From fe6e492c479ea47c9c6255aec56a63bd97451008 Mon Sep 17 00:00:00 2001 From: Nico Tena Date: Sat, 19 Jul 2025 01:45:57 +0200 Subject: [PATCH 1/3] feat: #12: Add container support --- src/SpotifyDaily.Worker/.dockerignore | 30 +++++++++++++++++++ src/SpotifyDaily.Worker/Dockerfile | 29 ++++++++++++++++++ .../Properties/launchSettings.json | 9 ++++++ .../SpotifyDaily.Worker.csproj | 3 ++ 4 files changed, 71 insertions(+) create mode 100644 src/SpotifyDaily.Worker/.dockerignore create mode 100644 src/SpotifyDaily.Worker/Dockerfile diff --git a/src/SpotifyDaily.Worker/.dockerignore b/src/SpotifyDaily.Worker/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/src/SpotifyDaily.Worker/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/src/SpotifyDaily.Worker/Dockerfile b/src/SpotifyDaily.Worker/Dockerfile new file mode 100644 index 0000000..71aee8b --- /dev/null +++ b/src/SpotifyDaily.Worker/Dockerfile @@ -0,0 +1,29 @@ +# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +# This stage is used when running from VS in fast mode (Default for Debug configuration) +FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base +WORKDIR /app +EXPOSE 8080 + +# This stage is used to build the service project +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["SpotifyDaily.Worker.csproj", "."] +RUN dotnet restore "./SpotifyDaily.Worker.csproj" +COPY . . +WORKDIR "/src/." +RUN dotnet build "./SpotifyDaily.Worker.csproj" -c $BUILD_CONFIGURATION -o /app/build + +# This stage is used to publish the service project to be copied to the final stage +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./SpotifyDaily.Worker.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +RUN chown -R root:root /app +USER root +ENTRYPOINT ["dotnet", "SpotifyDaily.Worker.dll"] \ No newline at end of file diff --git a/src/SpotifyDaily.Worker/Properties/launchSettings.json b/src/SpotifyDaily.Worker/Properties/launchSettings.json index bb6f52b..8f69f5c 100644 --- a/src/SpotifyDaily.Worker/Properties/launchSettings.json +++ b/src/SpotifyDaily.Worker/Properties/launchSettings.json @@ -6,6 +6,15 @@ "DOTNET_ENVIRONMENT": "Development" }, "dotnetRunMessages": true + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", + "environmentVariables": { + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": false } }, "$schema": "http://json.schemastore.org/launchsettings.json" diff --git a/src/SpotifyDaily.Worker/SpotifyDaily.Worker.csproj b/src/SpotifyDaily.Worker/SpotifyDaily.Worker.csproj index 799e30c..64beb9e 100644 --- a/src/SpotifyDaily.Worker/SpotifyDaily.Worker.csproj +++ b/src/SpotifyDaily.Worker/SpotifyDaily.Worker.csproj @@ -5,10 +5,13 @@ enable enable dotnet-SpotifyDaily.Worker-4c7fb886-ddd0-4116-bf4f-aac245a7d38d + Linux + . + From de1fff3cffde596c87973594b829a2d8d626bf37 Mon Sep 17 00:00:00 2001 From: Nico Tena Date: Tue, 22 Jul 2025 09:26:02 +0200 Subject: [PATCH 2/3] Create dotnet.yml --- .github/workflows/dotnet.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/dotnet.yml diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000..5c9df6a --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,31 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + working-directory: src + - name: Build + run: dotnet build --no-restore + working-directory: src + - name: Test + run: dotnet test --no-build --verbosity normal + working-directory: src From 3962f5927c0d207397df05a9fb1a983c488d03f0 Mon Sep 17 00:00:00 2001 From: Nico Tena Date: Tue, 22 Jul 2025 13:18:30 +0200 Subject: [PATCH 3/3] feat: Add docker support --- .github/workflows/docker.yml | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..8229c36 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,48 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - master + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=sha,prefix={{branch}}- + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ./src/SpotifyDaily.Worker + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file