-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With prod dockerfile and workflow to generate the image
- Loading branch information
1 parent
965f658
commit 59bb113
Showing
8 changed files
with
390 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
Oops, something went wrong.