From a2538f0529619710642110d92e8fca4665bca20c Mon Sep 17 00:00:00 2001 From: Brian Collet <50160870+BrianCollet@users.noreply.github.com> Date: Fri, 13 Jun 2025 08:02:34 -0700 Subject: [PATCH 1/7] Added Github action --- .github/workflows/deploy-image.yml | 59 ++++++++++++++++++++++++++++++ Api/Api.csproj | 1 + 2 files changed, 60 insertions(+) create mode 100644 .github/workflows/deploy-image.yml diff --git a/.github/workflows/deploy-image.yml b/.github/workflows/deploy-image.yml new file mode 100644 index 0000000..c801654 --- /dev/null +++ b/.github/workflows/deploy-image.yml @@ -0,0 +1,59 @@ +# +name: Create and publish a Docker image + +# Configures this workflow to run every time a change is pushed to the branch called `release`. +on: + push: + branches: ["release"] + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds). + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v2 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true diff --git a/Api/Api.csproj b/Api/Api.csproj index b38a69a..f84856f 100644 --- a/Api/Api.csproj +++ b/Api/Api.csproj @@ -4,6 +4,7 @@ net9.0 enable enable + umami-cloud-api-wrapper From 46acb17e0c0dc845e38ef9c0e098d37e25e5934f Mon Sep 17 00:00:00 2001 From: Brian Collet <50160870+BrianCollet@users.noreply.github.com> Date: Fri, 13 Jun 2025 09:24:50 -0700 Subject: [PATCH 2/7] Updated the Github action for .NET --- .github/workflows/deploy-image.yml | 53 +++++++++--------------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/.github/workflows/deploy-image.yml b/.github/workflows/deploy-image.yml index c801654..38baadf 100644 --- a/.github/workflows/deploy-image.yml +++ b/.github/workflows/deploy-image.yml @@ -1,59 +1,36 @@ # -name: Create and publish a Docker image +name: Publish to GitHub Container Registry -# Configures this workflow to run every time a change is pushed to the branch called `release`. on: push: branches: ["release"] -# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} + DOTNET_VERSION: "9.x" -# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. jobs: - build-and-push-image: + publish: runs-on: ubuntu-latest - # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. permissions: contents: read packages: write - attestations: write - id-token: write - # + steps: - - name: Checkout repository - uses: actions/checkout@v4 - # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. - - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. - # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository. - # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. - - name: Build and push Docker image - id: push - uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds). - - name: Generate artifact attestation - uses: actions/attest-build-provenance@v2 - with: - subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} - subject-digest: ${{ steps.push.outputs.digest }} - push-to-registry: true + - name: Publish and push the container image + run: | + dotnet publish --os linux --arch x64 /p:PublishProfile=github From b2fb121332796d74bcab8c7ee7006bda63e37856 Mon Sep 17 00:00:00 2001 From: Brian Collet <50160870+BrianCollet@users.noreply.github.com> Date: Fri, 13 Jun 2025 09:28:11 -0700 Subject: [PATCH 3/7] Updated the Github action to use PublishContainer instead of PublishProfile --- .github/workflows/deploy-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-image.yml b/.github/workflows/deploy-image.yml index 38baadf..9df6af3 100644 --- a/.github/workflows/deploy-image.yml +++ b/.github/workflows/deploy-image.yml @@ -33,4 +33,4 @@ jobs: - name: Publish and push the container image run: | - dotnet publish --os linux --arch x64 /p:PublishProfile=github + dotnet publish --os linux --arch x64 /t:PublishContainer -p ContainerRegistry=${{ env.REGISTRY }} From 9d23bac5420e274e929130881cf9efff0328e4b3 Mon Sep 17 00:00:00 2001 From: Brian Collet <50160870+BrianCollet@users.noreply.github.com> Date: Fri, 13 Jun 2025 09:32:56 -0700 Subject: [PATCH 4/7] Updated ContainerRepository to GitHub format --- Api/Api.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Api/Api.csproj b/Api/Api.csproj index f84856f..9556f5c 100644 --- a/Api/Api.csproj +++ b/Api/Api.csproj @@ -4,7 +4,8 @@ net9.0 enable enable - umami-cloud-api-wrapper + 1.0.0 + BrianCollet/umami-cloud-api-wrapper From 49c4b73905b25e362ce324a199d3dc66d71d507c Mon Sep 17 00:00:00 2001 From: Brian Collet <50160870+BrianCollet@users.noreply.github.com> Date: Fri, 13 Jun 2025 09:40:18 -0700 Subject: [PATCH 5/7] Reverted to HTTP instead of HTTPS --- Api/appsettings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Api/appsettings.json b/Api/appsettings.json index 1623d40..2632f7b 100644 --- a/Api/appsettings.json +++ b/Api/appsettings.json @@ -1,8 +1,8 @@ { "Kestrel": { "Endpoints": { - "Https": { - "Url": "https://localhost:5001" + "Http": { + "Url": "http://localhost:5001" } } }, From a91f276f5a9ce1a888228629ce7fc7842652a445 Mon Sep 17 00:00:00 2001 From: Brian Collet <50160870+BrianCollet@users.noreply.github.com> Date: Fri, 13 Jun 2025 11:11:54 -0700 Subject: [PATCH 6/7] Removed Kestrel config to allow specifying port through env variable --- Api/appsettings.json | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Api/appsettings.json b/Api/appsettings.json index 2632f7b..10f68b8 100644 --- a/Api/appsettings.json +++ b/Api/appsettings.json @@ -1,11 +1,4 @@ { - "Kestrel": { - "Endpoints": { - "Http": { - "Url": "http://localhost:5001" - } - } - }, "Logging": { "LogLevel": { "Default": "Information", From aeb437d55cc17d8667123b50578fd102826babe3 Mon Sep 17 00:00:00 2001 From: Brian Collet <50160870+BrianCollet@users.noreply.github.com> Date: Fri, 13 Jun 2025 11:52:12 -0700 Subject: [PATCH 7/7] Removed HTTPS redirection middleware --- Api/Program.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Api/Program.cs b/Api/Program.cs index 1157b9d..71f7505 100644 --- a/Api/Program.cs +++ b/Api/Program.cs @@ -17,12 +17,6 @@ options.MaxAge = TimeSpan.FromDays(60); }); -builder.Services.AddHttpsRedirection(options => -{ - options.RedirectStatusCode = Status307TemporaryRedirect; - options.HttpsPort = 5001; -}); - var app = builder.Build(); // Configure the HTTP request pipeline. @@ -35,8 +29,6 @@ }); } -app.UseHttpsRedirection(); - app.UseAuthorization(); app.MapControllers();