Skip to content

Commit

Permalink
With prod dockerfile and workflow to generate the image
Browse files Browse the repository at this point in the history
  • Loading branch information
MertzAndreas committed Dec 9, 2024
1 parent 965f658 commit 59bb113
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 255 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/build-and-push-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# This workflow will build a Docker image and push it to GitHub Container Registry

name: Publish Docker image prod

on:
workflow_dispatch:
pull_request:
branches:
- main

jobs:
push_to_registries:
name: Push Docker image to ghcr.io
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
id-token: write

steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/[email protected]
with:
install: true
driver-opts: network=host
platforms: linux/amd64,linux/arm64

- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=raw,value=latest
type=raw,value=prod
- name: Build and push Docker images
id: push
uses: docker/[email protected]
with:
context: .
file: Dockerfile.prod
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
2 changes: 0 additions & 2 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This workflow will build a Docker image and push it to GitHub Container Registry

name: Publish Docker image

on:
Expand All @@ -9,7 +8,6 @@ on:
push:
tags:
- "v*"

jobs:
push_to_registries:
name: Push Docker image to ghcr.io
Expand Down
75 changes: 38 additions & 37 deletions .idea/.idea.weekplanner-api/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Stage 1: Build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG TARGETARCH
WORKDIR /app
ENV ASPNETCORE_ENVIRONMENT=Production

# Copy only the required project files
COPY GirafAPI/*.csproj ./GirafAPI/
COPY GirafAPI/Data/Migrations/*.cs ./GirafAPI/Data/Migrations/
RUN dotnet restore ./GirafAPI/GirafAPI.csproj

# Build and publish the application
COPY . .
RUN dotnet build ./GirafAPI/GirafAPI.csproj -c Release -o /app/build -a $TARGETARCH
RUN dotnet publish ./GirafAPI/GirafAPI.csproj -c Release -o /app/publish -a $TARGETARCH --no-restore

# Stage 2: Runtime
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app

# Copy the published app from the build stage
COPY --from=build /app/publish .

# Expose the application port
EXPOSE 5171
ENV ASPNETCORE_URLS=http://+:5171

# Set the entry point
ENTRYPOINT ["dotnet", "/app/GirafAPI.dll"]
Loading

0 comments on commit 59bb113

Please sign in to comment.