Skip to content

Commit

Permalink
feat(dockerfile): auto migrate and adminer added (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliyaghini authored Aug 18, 2024
1 parent 05a7be3 commit 52c6041
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COPY . .

RUN dotnet publish ./AnalysisData/AnalysisData/AnalysisData.csproj -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS runtime
WORKDIR /app
COPY --from=build /app/out ./

Expand All @@ -16,6 +16,11 @@ ENV ASPNETCORE_ENVIRONMENT=Development
ENV ASPNETCORE_URLS=http://*:80
EXPOSE 80

COPY . ./app

#RUN dotnet tool install --global dotnet-ef
#RUN export PATH="${PATH}:/root/.dotnet/tools"
#RUN dotnet ef database update --project AnalysisData/AnalysisData/AnalysisData.csproj

# Start the application
ENTRYPOINT ["dotnet", "AnalysisData.dll"]
19 changes: 19 additions & 0 deletions Dockerfile2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0

RUN dotnet tool install --global dotnet-ef --version 8.0
ENV PATH="${PATH}:/root/.dotnet/tools"

WORKDIR /build

# Copy solution file
#COPY ./AnalysisData/AnalysisData.sln ./

# Copy src .csproj files
#COPY ./AnalysisData/AnalysisData/AnalysisData.csproj ./src/AnalysisData/

# Copy everything and build
COPY . .

WORKDIR /build

CMD ["dotnet", "ef", "--project", "AnalysisData/AnalysisData/AnalysisData.csproj", "database", "update"]
21 changes: 13 additions & 8 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ services:
volumes:
- pgdata:/var/lib/postgresql/data


migrate:
image: mcr.microsoft.com/dotnet/sdk:8.0 #mcr.microsoft.com/dotnet/runtime:8.0-windowsservercore-ltsc2022
#image: migrateimage
image: yaghooli/migrateimage:latest
depends_on:
- postgres
working_dir: /app
volumes:
- .:/app
environment:
ConnectionStrings__DefaultConnection: Host=postgres;Database=mohaymen;Username=postgres;Password=1234;
command: >
bash -c "dotnet tool install --global dotnet-ef &&
export PATH=\"$PATH:/root/.dotnet/tools\" &&
dotnet ef database update --project AnalysisData/AnalysisData/AnalysisData.csproj"

admin:
image: adminer
restart: always
depends_on:
- postgres
ports:
- 8089:8080

web:
image: yaghooli/dotnetdev:latest
#build: .
depends_on:
migrate:
condition: service_completed_successfully
Expand All @@ -37,3 +41,4 @@ services:

volumes:
pgdata:

0 comments on commit 52c6041

Please sign in to comment.