Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.

Commit 8c85390

Browse files
authored
initial migration worker (#301)
This PR brings the initial version of migration app and its new pipeline.
1 parent de7b9f5 commit 8c85390

File tree

8 files changed

+125
-1
lines changed

8 files changed

+125
-1
lines changed

AWS-CICD/Dockerfile-mig.image

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
2+
COPY mig/ mig/
3+
COPY amazon-cloudwatch-agent.deb /mig
4+
WORKDIR /mig
5+
6+
RUN dpkg -i -E ./amazon-cloudwatch-agent.deb
7+
COPY /AWS-CICD/amazon-cloudwatch-agent-mig.json /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
8+
COPY /AWS-CICD/commands-mig.sh .
9+
RUN chmod +x commands-mig.sh
10+
11+
ENTRYPOINT ["./commands-mig.sh"]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"logs": {
3+
"logs_collected": {
4+
"files": {
5+
"collect_list": [
6+
{
7+
"file_path": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log",
8+
"log_group_name": "sdra-mig",
9+
"log_stream_name": "amazon-cloudwatch-agent.log",
10+
"timezone": "Local"
11+
},
12+
{
13+
"file_path": "/var/log/**.log",
14+
"log_group_name": "sdra-mig",
15+
"log_stream_name": "var-logs",
16+
"timezone": "Local"
17+
},
18+
{
19+
"file_path": "/mig/console.log",
20+
"log_group_name": "sdra-mig",
21+
"log_stream_name": "console.log",
22+
"timezone": "Local"
23+
}
24+
]
25+
}
26+
},
27+
"log_stream_name": "sdra-mig-default-stream",
28+
"force_flush_interval" : 15
29+
}
30+
}

AWS-CICD/build-specs/buildspec-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ phases:
44
commands:
55
- cd AWS-CICD/Deploy
66
- npm install
7-
- node deploy-version.js $pipelineName $PipelineExecutionId $CODEBUILD_BUILD_NUMBER "sdra" $environmentName
7+
- node deploy-version.js $pipelineName $PipelineExecutionId $CODEBUILD_BUILD_NUMBER "$appName" $environmentName
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 0.2
2+
3+
phases:
4+
install:
5+
commands:
6+
- apt-get update
7+
- apt-get install -y nodejs
8+
- apt-get install -y npm
9+
build:
10+
commands:
11+
- cd WebApplication
12+
- dotnet publish -c Release -o ../mig
13+
artifacts:
14+
files:
15+
- 'mig/**/*'
16+
- 'AWS-CICD/commands-mig.sh'
17+
- 'AWS-CICD/Dockerfile-mig.image'
18+
- 'AWS-CICD/build-specs/buildspec-mig-image.yml'
19+
- 'AWS-CICD/Dockerrun.aws.json'
20+
- 'AWS-CICD/amazon-cloudwatch-agent-mig.json'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: 0.2
2+
phases:
3+
install:
4+
runtime-versions:
5+
docker: 18
6+
pre_build:
7+
commands:
8+
- echo Logging in to Amazon ECR...
9+
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
10+
build:
11+
commands:
12+
- echo Build started on `date`
13+
- IMAGE_TAG=${CommitId:0:7}
14+
- wget https://s3.us-west-2.amazonaws.com/amazoncloudwatch-agent-us-west-2/debian/amd64/latest/amazon-cloudwatch-agent.deb
15+
- echo Building Docker production image...
16+
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG -f ./AWS-CICD/Dockerfile-mig.image .
17+
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
18+
post_build:
19+
commands:
20+
- echo Build completed on `date`
21+
- echo Pushing the Docker image...
22+
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
23+
- sed -i 's/sdra:latest/'$IMAGE_REPO_NAME:$IMAGE_TAG'/g' ./AWS-CICD/Dockerrun.aws.json
24+
artifacts:
25+
files:
26+
- Dockerrun.aws.json
27+
base-directory: AWS-CICD

AWS-CICD/commands-mig.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh -e
2+
/opt/aws/amazon-cloudwatch-agent/bin/start-amazon-cloudwatch-agent &
3+
dotnet WebApplication.dll migration=true

WebApplication/Startup.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ public void ConfigureServices(IServiceCollection services)
105105
services.AddScoped<UserResolver>(); // TODO: use interface
106106
services.AddSingleton<LocalCache>();
107107
services.AddSingleton<Uploads>();
108+
109+
if(Configuration.GetValue<bool>("migration"))
110+
{
111+
services.AddHostedService<MigrationApp.Worker>();
112+
}
108113
}
109114

110115
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

WebApplication/Worker.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
using Microsoft.Extensions.Hosting;
4+
using Microsoft.Extensions.Logging;
5+
using WebApplication.Services;
6+
7+
namespace MigrationApp
8+
{
9+
public class Worker : BackgroundService
10+
{
11+
private readonly ILogger<Worker> _logger;
12+
private readonly IForgeOSS _forgeOSS;
13+
14+
public Worker(ILogger<Worker> logger, IForgeOSS forgeOSS)
15+
{
16+
_logger = logger;
17+
_forgeOSS = forgeOSS;
18+
}
19+
20+
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
21+
{
22+
while (!stoppingToken.IsCancellationRequested)
23+
{
24+
await Task.Delay(1000, stoppingToken);
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)