Skip to content

Commit a3c0421

Browse files
merge 1.2.1 into 1.2.2
2 parents 4e1aee9 + c9dba8f commit a3c0421

18 files changed

+819
-510
lines changed

Dockerfile.dbupdate

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
2+
WORKDIR /app
3+
4+
# copy dependencies
5+
COPY ./Streetcode/DbUpdate/DbUpdate.csproj ./DbUpdate/
6+
COPY ./Streetcode/DbUpdate/*.cs ./DbUpdate/
7+
COPY ./Streetcode/DbUpdate/appsettings.json ./DbUpdate/
8+
COPY ./Streetcode/DbUpdate/appsettings.Local.json ./DbUpdate/
9+
COPY ./Streetcode ./Streetcode/
10+
COPY ./Streetcode/Streetcode.DAL/Persistence/ScriptsMigration ./Streetcode.DAL/Persistence/ScriptsMigration/
11+
12+
RUN dotnet restore ./DbUpdate/DbUpdate.csproj
13+
14+
15+
# build
16+
RUN dotnet build ./DbUpdate/DbUpdate.csproj -c Release -o /app/build
17+
18+
# publishishing application
19+
FROM build AS publish
20+
RUN dotnet publish ./DbUpdate/DbUpdate.csproj -c Release -o /app/publish
21+
22+
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS runtime
23+
WORKDIR /app
24+
COPY --from=publish /app/publish .
25+
26+
CMD ["dotnet", "DbUpdate.dll"]

Jenkinsfile

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
def CODE_VERSION = ''
22
def IS_IMAGE_BUILDED = false
3+
def IS_DBUPDATE_IMAGE_BUILDED = false
34
def IS_IMAGE_PUSH = false
5+
def IS_DBUPDATE_IMAGE_PUSH = false
46
def isSuccess
57
def preDeployFrontStage
68
def preDeployBackStage
@@ -138,46 +140,53 @@ pipeline {
138140
}
139141
}
140142
}
141-
stage('Build image') {
143+
stage('Build images') {
142144
when {
143145
branch pattern: "release/[0-9].[0-9].[0-9]", comparator: "REGEXP"
144146

145147
}
146148
steps {
147149
script {
148150
withCredentials([usernamePassword(credentialsId: 'docker-login-streetcode', passwordVariable: 'password', usernameVariable: 'username')]){
149-
sh "docker build -t ${username}/streetcode:latest ."
151+
// Build the backend image
152+
sh "docker build -f Dockerfile -t ${username}/streetcode:${env.CODE_VERSION} ."
150153
IS_IMAGE_BUILDED = true
154+
155+
// Build the dbupdate image
156+
sh "docker build -f Dockerfile.dbupdate -t ${username}/dbupdate:${env.CODE_VERSION} ."
157+
IS_DBUPDATE_IMAGE_BUILDED = true
151158
}
152159
}
153160
}
154161
}
155-
stage('Push image') {
162+
stage('Push images') {
156163
when {
157-
expression { IS_IMAGE_BUILDED == true }
164+
expression { IS_IMAGE_BUILDED == true && IS_DBUPDATE_IMAGE_BUILDED == true }
158165
}
159166
steps {
160167
script {
161168
withCredentials([usernamePassword(credentialsId: 'docker-login-streetcode', passwordVariable: 'password', usernameVariable: 'username')]){
162169
sh 'echo "${password}" | docker login -u "${username}" --password-stdin'
163-
sh "docker push ${username}/streetcode:latest"
164-
sh "docker tag ${username}/streetcode:latest ${username}/streetcode:${env.CODE_VERSION}"
170+
165171
sh "docker push ${username}/streetcode:${env.CODE_VERSION}"
166172
IS_IMAGE_PUSH = true
167-
173+
174+
sh "docker push ${username}/dbupdate:${env.CODE_VERSION}"
175+
IS_DBUPDATE_IMAGE_PUSH = true
176+
168177
}
169178
}
170179
}
171180
}
172181
stage('Deploy Stage'){
173182
when {
174-
expression { IS_IMAGE_PUSH == true }
183+
expression { IS_IMAGE_PUSH == true && IS_DBUPDATE_IMAGE_PUSH == true }
175184
}
176185
steps {
177186
input message: 'Do you want to approve Staging deployment?', ok: 'Yes', submitter: 'admin_1, ira_zavushchak , dev'
178187
script {
179188
checkout scmGit(
180-
branches: [[name: 'main']],
189+
branches: [[name: 'feature/add-init-container']],
181190
userRemoteConfigs: [[credentialsId: 'StreetcodeGithubCreds', url: '[email protected]:ita-social-projects/Streetcode-DevOps.git']])
182191

183192
preDeployBackStage = sh(script: 'docker container inspect $(docker container ls -aq) --format "{{.Config.Image}}" | grep "streetcodeua/streetcode:" | perl -pe \'($_)=/([0-9]+([.][0-9]+)+)/\'', returnStdout: true).trim()
@@ -195,7 +204,7 @@ pipeline {
195204
sh 'docker system prune --force --filter "until=72h"'
196205
sh """ export DOCKER_TAG_BACKEND=${env.CODE_VERSION}
197206
export DOCKER_TAG_FRONTEND=${preDeployFrontStage}
198-
docker stop backend frontend nginx loki certbot
207+
docker stop backend frontend nginx loki certbot dbupdate
199208
docker container prune -f
200209
docker volume prune -f
201210
docker network prune -f
@@ -207,7 +216,7 @@ pipeline {
207216
}
208217
stage('WHAT IS THE NEXT STEP') {
209218
when {
210-
expression { IS_IMAGE_PUSH == true }
219+
expression { IS_IMAGE_PUSH == true && IS_DBUPDATE_IMAGE_PUSH == true }
211220
}
212221
steps {
213222
script {
@@ -228,7 +237,7 @@ pipeline {
228237
sh """
229238
export DOCKER_TAG_BACKEND=${preDeployBackStage}
230239
export DOCKER_TAG_FRONTEND=${preDeployFrontStage}
231-
docker stop backend frontend nginx loki certbot
240+
docker stop backend frontend nginx loki certbot dbupdate
232241
docker container prune -f
233242
docker volume prune -f
234243
docker network prune -f
@@ -245,7 +254,9 @@ pipeline {
245254
}
246255
}
247256
}
257+
248258
/*
259+
249260
stage('Deploy prod') {
250261
agent {
251262
label 'production'
@@ -286,7 +297,9 @@ pipeline {
286297
}
287298
}
288299
}
300+
289301
*/
302+
290303
stage('Sync after release') {
291304
when {
292305
expression { isSuccess == '1' }
@@ -340,7 +353,9 @@ pipeline {
340353
}
341354
}
342355
}
356+
343357
*/
358+
344359
}
345360
post {
346361
always {
@@ -349,3 +364,4 @@ post {
349364
}
350365
}
351366
}
367+

Streetcode/DbUpdate/DbUpdate.csproj

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
<PackageReference Include="DbUp" Version="5.0.8" />
1212
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0" />
1313
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
1415
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
16+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
1519
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
1620
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
1721
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
@@ -24,8 +28,24 @@
2428
</ItemGroup>
2529

2630
<ItemGroup>
27-
<ProjectReference Include="..\Streetcode.WebApi\Streetcode.WebApi.csproj" />
31+
<None Remove="appsettings.Local.json" />
32+
<Content Include="appsettings.Local.json">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</Content>
35+
<!-- <None Remove="appsettings.IntegrationTests.json" /> -->
36+
<Content Include="appsettings.IntegrationTests.json">
37+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
38+
</Content>
2839
</ItemGroup>
40+
41+
<ItemGroup>
42+
<!-- Include the files you want to copy from the other project -->
43+
<FilesToCopy Include="..\Streetcode.DAL\Persistence\ScriptsMigration\*.*" />
44+
</ItemGroup>
45+
46+
<Target Name="CopyFiles" AfterTargets="Build">
47+
<Copy SourceFiles="@(FilesToCopy)" DestinationFolder="$(OutputPath)\ScriptsMigration\" />
48+
</Target>
2949

3050
<PropertyGroup>
3151
<SonarQubeExclude>true</SonarQubeExclude>

Streetcode/DbUpdate/Program.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using DbUp;
1+
using System.Reflection;
2+
using DbUp;
23
using Microsoft.Extensions.Configuration;
34

45
public class Program
@@ -8,22 +9,20 @@ static int Main(string[] args)
89
string rootDirectory = GetRootFolderPath();
910
string pathToSqlScripts = Path.Combine(
1011
rootDirectory,
11-
"Streetcode",
12-
"Streetcode.DAL",
13-
"Persistence",
1412
"ScriptsMigration");
1513

1614
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Local";
1715

1816
var configuration = new ConfigurationBuilder()
19-
.SetBasePath(Path.Combine(rootDirectory, "Streetcode", "Streetcode.WebApi"))
20-
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
17+
.SetBasePath(rootDirectory)
18+
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
2119
.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
2220
.AddEnvironmentVariables("STREETCODE_")
2321
.Build();
2422

2523
var connectionString = configuration.GetConnectionString("DefaultConnection");
2624

25+
Console.WriteLine($"Connection string: {connectionString}");
2726
var upgrader =
2827
DeployChanges.To
2928
.SqlDatabase(connectionString)
@@ -50,16 +49,16 @@ static int Main(string[] args)
5049
return 0;
5150
}
5251

53-
private static string GetRootFolderPath()
54-
{
55-
// By root folder we mean folder, that contains .gitignore file.
56-
string currentDirectoryPath = Directory.GetCurrentDirectory();
57-
var directory = new DirectoryInfo(currentDirectoryPath);
58-
while (directory is not null && !directory.GetFiles(".gitignore").Any())
59-
{
60-
directory = directory.Parent;
61-
}
62-
63-
return directory?.FullName ?? throw new NullReferenceException("Cannot find root folder");
52+
private static string GetRootFolderPath()
53+
{
54+
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
55+
if (codeBase == null)
56+
{
57+
throw new NullReferenceException("Cannot find root folder");
58+
}
59+
60+
UriBuilder uri = new UriBuilder(codeBase);
61+
string path = Uri.UnescapeDataString(uri.Path);
62+
return Path.GetDirectoryName(path) !;
6463
}
6564
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ConnectionStrings": {
3+
"DefaultConnection": "Server=localhost,1455;Database=Streetcode_IntegrationTests_Db;User Id=sa;Password=sdlLKMCD234!@#lkcmds;MultipleActiveResultSets=True;TrustServerCertificate=true"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ConnectionStrings": {
3+
"DefaultConnection": "Server=localhost, 1433;Database=test-db;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true;TrustServerCertificate=true"
4+
}
5+
}

Streetcode/Streetcode.DAL/Persistence/ScriptsMigration/Script_20230703154732_UpdatePartnerModel.sql

Lines changed: 0 additions & 31 deletions
This file was deleted.

Streetcode/Streetcode.DAL/Persistence/ScriptsMigration/Script_20230804120930_Change_StreetcodeCategoryContent_Text_to_10000_simb.sql

Lines changed: 0 additions & 19 deletions
This file was deleted.

Streetcode/Streetcode.DAL/Persistence/ScriptsMigration/Script_20230905201616_Jobs.sql

Lines changed: 0 additions & 44 deletions
This file was deleted.

Streetcode/Streetcode.DAL/Persistence/ScriptsMigration/Script_20231130202258_DatestringLength.sql

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)