Skip to content

Commit

Permalink
Add environment variable support for Docker builds and update connect…
Browse files Browse the repository at this point in the history
…ion strings
  • Loading branch information
sentemon committed Nov 16, 2024
1 parent b707781 commit 4d77244
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/post.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ jobs:
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
IMAGE_VERSION=${GITHUB_REF#refs/tags/}
fi
docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/post-service:${IMAGE_VERSION} -f ./backend/src/PostService/Dockerfile ./backend/src
docker build \
--build-arg ASPNETCORE_ENVIRONMENT=${{ secrets.ASPNETCORE_ENVIRONMENT }} \
--build-arg DB_CONNECTION_STRING=${{ secrets.DB_CONNECTION_STRING }} \
-t ${{ secrets.DOCKER_HUB_USERNAME }}/post-service:${IMAGE_VERSION} -f ./backend/src/PostService/Dockerfile ./backend/src
- name: Push Docker image to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -71,4 +74,7 @@ jobs:
uses: actions/checkout@v4

- name: Build Docker Compose
run: docker compose build --no-cache
run: docker compose build --no-cache
env:
ASPNETCORE_ENVIRONMENT: ${{ secrets.ASPNETCORE_ENVIRONMENT }}
DB_CONNECTION_STRING: ${{ secrets.DB_CONNECTION_STRING }}
6 changes: 6 additions & 0 deletions backend/src/PostService/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080

ARG ASPNETCORE_ENVIRONMENT
ARG DB_CONNECTION_STRING

ENV ASPNETCORE_ENVIRONMENT=${ASPNETCORE_ENVIRONMENT}
ENV ConnectionStrings__DefaultConnection=${DB_CONNECTION_STRING}

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

WORKDIR /src
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
}
},
"ConnectionStrings": {
"DefaultConnection": "Host=postgres-posts;Port=5432;Username=postgres;Password=mysecretpasswordfordevelopment;Database=postgres"
"DefaultConnection": "Host=localhost;Port=5432;Username=postgres;Password=mysecretpasswordfordevelopment;Database=postgres"
}
}
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ services:
ports:
- "8080:8080"
environment:
ASPNETCORE_ENVIRONMENT: Development
ConnectionStrings__DefaultConnection: Host=postgres-posts;Port=5432;Username=postgres;Password=mysecretpasswordfordevelopment;Database=postgres
ASPNETCORE_ENVIRONMENT: ${ASPNETCORE_ENVIRONMENT}
ConnectionStrings__DefaultConnection: ${DB_CONNECTION_STRING}
depends_on:
- postgres-posts
networks:
Expand Down

0 comments on commit 4d77244

Please sign in to comment.