Skip to content

Commit e8b707b

Browse files
committed
Merge branch 'aws'
2 parents 779f023 + 589aa91 commit e8b707b

8 files changed

Lines changed: 61 additions & 12 deletions

File tree

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ services:
55

66
language: generic
77

8+
before_install:
9+
- pip install --user awscli
10+
- export PATH=$PATH:$HOME/.local/bin
11+
812
script:
913
# - if [ "$TRAVIS_TAG" != "" ]; then
1014
# docker run -it --rm -v $TRAVIS_BUILD_DIR:/sources microsoft/dotnet:1.1.0-sdk-msbuild bash /sources/scripts/PublishDebug.sh;

Dockerfile.debug

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
FROM microsoft/dotnet:1.1.0-runtime
22

3+
# Install the AWS CLI
4+
RUN apt-get update && \
5+
apt-get -y install python curl unzip && cd /tmp && \
6+
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" \
7+
-o "awscli-bundle.zip" && \
8+
unzip awscli-bundle.zip && \
9+
./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws && \
10+
rm awscli-bundle.zip && rm -rf awscli-bundle
11+
312
# Copy our code to the "/app" folder in our container
413
WORKDIR /app
514
COPY ./published/debug .
@@ -9,7 +18,11 @@ ENV ASPNETCORE_URLS http://+:5000
918
EXPOSE 5000
1019

1120
ENV ASPNETCORE_ENVIRONMENT Development
12-
ENV db-connection-string ConnectionString_dockerContainer
21+
ENV CONNECTIONSTRINGNAME ConnectionString_Postgres
22+
23+
COPY ./Scripts/secrets-entrypoint.sh /secrets-entrypoint.sh
24+
ENTRYPOINT ["/secrets-entrypoint.sh"]
1325

1426
# Run the dotnet application against a DLL from within the container
15-
ENTRYPOINT ["dotnet", "SimpleToDoService.dll"]
27+
#ENTRYPOINT ["dotnet", "SimpleToDoService.dll"]
28+
CMD [dotnet, "SimpleToDoService.dll"]

RequestTests.paw

7.8 KB
Binary file not shown.

Scripts/BuildImage.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
#!/bin/sh
2-
set -ev
2+
set -e
33

44
if [ "${TRAVIS_TAG}" != "" ]; then
5+
56
docker run -it -d --name builder microsoft/dotnet:1.1.0-sdk-msbuild tail -f /dev/null
6-
echo "try ls"
7-
docker exec builder bash -c 'ls'
87
docker cp src/SimpleToDoService builder:app
98
docker exec builder bash -c 'cd /app; dotnet restore; dotnet publish -o "../published/debug"'
109
docker cp builder:published published
10+
11+
#push to AWS
12+
aws ecr get-login --region eu-central-1 > login
13+
eval "$(cat login)"
14+
export REPO=${DOCKER_AWS_REPONAME}
15+
export TAG=empty-${TRAVIS_TAG}
16+
docker build -f Dockerfile.debug -t $REPO:$TAG .
17+
docker tag $REPO:$TAG $REPO:latest
18+
docker push $REPO > PushLog.log
19+
echo "AWS push log ===="
20+
cat PushLog.log
21+
echo "======"
22+
23+
#push to docker-hub
1124
docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
1225
export REPO=reloni/todo-service
13-
export TAG=Debug-${TRAVIS_TAG}
1426
docker build -f Dockerfile.debug -t $REPO:$TAG .
1527
docker tag $REPO:$TAG $REPO:latest
16-
docker push $REPO
28+
docker push $REPO > PushLog.log
29+
echo "Docker hub push log ===="
30+
cat PushLog.log
31+
echo "======"
1732
fi
1833

1934
exit 0;

Scripts/RunContainer.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docker run -d --name task-manager-service -p 5000:5000 -e POSTGRES_PASSWORD=test -e POSTGRES_USER=taskmanager -e POSTGRES_DB=tasksdb -e POSTGRES_HOST=localhost -e POSTGRES_PORT=5432 reloni/todo-service:latest
2+
3+
4+
docker run -d --name task-manager-service -p 5000:5000 -e POSTGRES_PASSWORD=test -e POSTGRES_USER=taskmanager -e POSTGRES_DB=tasksdb -e POSTGRES_HOST=localhost -e POSTGRES_PORT=5432 test-todo

Scripts/secrets-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
if [ "$LOAD_S3_SECRETS" = "YES" ]; then
4+
# Load the S3 secrets file contents into the environment variables
5+
eval $(aws s3 --region ${SECRETS_BUCKET_REGION} cp s3://${SECRETS_BUCKET_NAME}/${SECRETS_FILE_NAME} - | sed 's/^/export /')
6+
fi
7+
8+
dotnet SimpleToDoService.dll

src/SimpleToDoService/AppSettings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
"Microsoft": "Information"
88
}
99
},
10-
"DbContextSettings" :{
10+
"DbContextSettings" :{
1111
"ConnectionString_localhost" : "User ID=postgres;Password=pass;Host=localhost;Port=5432;Database=postgres;Pooling=true;",
12-
"ConnectionString_dockerContainer" : "User ID=postgres;Password=pass;Host=db;Port=5432;Database=postgres;Pooling=true;"
12+
"ConnectionString_dockerContainer" : "User ID=postgres;Password=pass;Host=db;Port=5432;Database=postgres;Pooling=true;",
13+
"ConnectionString_Postgres" : "User ID={USER_ID};Password={PASSWORD};Host={HOST};Port={PORT};Database={DB};Pooling=true;"
1314
}
1415
}

src/SimpleToDoService/Startup.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ public void ConfigureServices(IServiceCollection services)
3939

4040

4141

42-
var connectionString = Configuration[string.Format("DbContextSettings:{0}",
43-
Environment.GetEnvironmentVariable("db-connection-string"))];
42+
var connectionString = Configuration["DbContextSettings:ConnectionString_Postgres"];
43+
connectionString = connectionString.Replace("{USER_ID}", Environment.GetEnvironmentVariable("POSTGRES_USER"))
44+
.Replace("{PASSWORD}", Environment.GetEnvironmentVariable("POSTGRES_PASSWORD"))
45+
.Replace("{DB}", Environment.GetEnvironmentVariable("POSTGRES_DB"))
46+
.Replace("{HOST}", Environment.GetEnvironmentVariable("POSTGRES_HOST"))
47+
.Replace("{PORT}", Environment.GetEnvironmentVariable("POSTGRES_PORT"));
4448

4549
services.AddDbContext<ToDoDbContext>(opts => opts.UseNpgsql(connectionString));
4650
services.AddScoped<IToDoDbContext, ToDoDbContext>();
@@ -59,4 +63,4 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
5963
app.UseMvc();
6064
}
6165
}
62-
}
66+
}

0 commit comments

Comments
 (0)