-
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 54dbef9
Showing
8 changed files
with
444 additions
and
302 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,60 @@ | ||
name: Publish Docker image prod | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main # Trigger on PR to main branch | ||
# You can still keep `workflow_dispatch` here for manual triggers later, if you need | ||
# workflow_dispatch: | ||
|
||
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 | ||
- name: Build and push Docker images | ||
id: push | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
file: Dockerfile.prod # Specify the production Dockerfile | ||
push: true | ||
tags: | | ||
ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.tags }} # Version tags (e.g., v1.0.0) | ||
ghcr.io/${{ github.repository }}:prod # Prod tag | ||
labels: | | ||
version=${{ steps.meta.outputs.tags }} | ||
environment=production # Add production-related 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,60 @@ | ||
# This workflow will build a Docker image and push it to GitHub Container Registry | ||
|
||
name: Publish Docker image | ||
name: Publish Docker image prod | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
tags: | ||
- "v*" | ||
pull_request: | ||
branches: | ||
- main # Trigger on PR to main branch | ||
# You can still keep `workflow_dispatch` here for manual triggers later, if you need | ||
# workflow_dispatch: | ||
|
||
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 | ||
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: 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: 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 | ||
- 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 | ||
- name: Build and push Docker images | ||
id: push | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: linux/amd64,linux/arm64 | ||
- name: Build and push Docker images | ||
id: push | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
file: Dockerfile.prod # Specify the production Dockerfile | ||
push: true | ||
tags: | | ||
ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.tags }} # Version tags (e.g., v1.0.0) | ||
ghcr.io/${{ github.repository }}:prod # Prod tag | ||
labels: | | ||
version=${{ steps.meta.outputs.tags }} | ||
environment=production # Add production-related labels | ||
platforms: linux/amd64,linux/arm64 |
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.