Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance CI/CD workflows and Dockerfile with version management and us… #320

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,21 @@ jobs:
ConnectionStrings__RedisConnection: "localhost:6379"
run: dotnet test src/WHMapper.Tests -c Release

- name: Cache SonarCloud data
if: ${{ env.BASE_REPO == env.PR_HEAD_REPO }}
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-sonar-

- name: Install SonarCloud scanners
if: ${{ env.BASE_REPO == env.PR_HEAD_REPO }}
run: |
dotnet tool install --global dotnet-sonarscanner
dotnet tool install --global dotnet-coverage

- name: SonarCloud Build and Analyze 🚀 🧪
if: ${{ env.BASE_REPO == env.PR_HEAD_REPO }}
env:
Expand Down Expand Up @@ -267,7 +277,8 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && startsWith(github.ref, 'refs/tags/') }}
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') }}
flavor: |
latest=false

Expand Down Expand Up @@ -323,7 +334,8 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && startsWith(github.ref, 'refs/tags/') }}
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') }}
flavor: |
latest=false

Expand Down Expand Up @@ -384,7 +396,8 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && startsWith(github.ref, 'refs/tags/') }}
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') }}
flavor: |
latest=false

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ jobs:
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true

build-args: |
VERSION=${{ env.VERSION }}

- name: Export digest
run: |
mkdir -p /tmp/digests
Expand All @@ -137,15 +139,13 @@ jobs:
needs: [prepare_release_docker_image_docker_io]
runs-on: ubuntu-latest
steps:
-
name: Download digests
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
-
name: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Docker meta
Expand Down
12 changes: 10 additions & 2 deletions src/WHMapper/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
# Use the official ASP.NET runtime as a parent image
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base

WORKDIR /app
EXPOSE 80
EXPOSE 443

# Create a non-root user and group
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

# Use the official .NET SDK as a parent image for building the application
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
WORKDIR /src
COPY ["WHMapper.csproj", "."]
RUN dotnet restore "WHMapper.csproj"
COPY . .
RUN dotnet build "WHMapper.csproj" -c Release -o /app/build

# Publish the application
FROM build AS publish
RUN dotnet publish "WHMapper.csproj" -c Release -o /app/publish
ARG VERSION=0.0.0
RUN dotnet publish "WHMapper.csproj" -c Release -o /app/publish /p:Version="$VERSION"

# Final stage: use the runtime image to run the application
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
Expand Down
Loading