Skip to content

Commit

Permalink
Create job to push to dockerhub
Browse files Browse the repository at this point in the history
  • Loading branch information
SSchulze1989 committed Feb 3, 2025
1 parent 5ae24ae commit 429586a
Showing 1 changed file with 66 additions and 30 deletions.
96 changes: 66 additions & 30 deletions .github/workflows/dotnet_tag_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,77 @@ name: .NET
on:
push:
tags:
- "*"
- "*.*.*"

jobs:
publish:
# publish:
# name: Publish packages to NuGet
# env:
# BUILD_CONFIG: Release
# NUGET_AUTH_TOKEN: ${{secrets.NUGET_TOKEN}}
# TEST_USER: root
# TEST_PASSWORD: TestPass123
# TEST_DATABASE: TestDatabase
# DB_TEST_PROJECT: test/DbIntegrationTests

# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v3
# - name: Setup .NET 8
# uses: actions/setup-dotnet@v3
# with:
# dotnet-version: 8.0.x
# source-url: https://api.nuget.org/v3/index.json
# - name: Setup MySQL
# uses: mirromutth/[email protected]
# with:
# # Required if "mysql user" is empty, default is empty. The root superuser password
# mysql root password: $TEST_PASSWORD
# # MYSQL_DATABASE - name for the default database that is created
# mysql database: $TEST_DATABASE
# - name: Set secrets
# run: dotnet user-secrets set "ConnectionStrings:ModelDb" "server=localhost;database=$TEST_DATABASE;user=$TEST_USER;password=$TEST_PASSWORD" --project $DB_TEST_PROJECT
# - name: Restore dependencies
# run: dotnet restore
# - name: Build
# run: dotnet build -c $BUILD_CONFIG --no-restore
# - name: Test
# run: dotnet test -c $BUILD_CONFIG --no-build --verbosity normal
# - name: Publish
# run: dotnet nuget push **\*.nupkg --skip-duplicate -k ${NUGET_AUTH_TOKEN}

push-to-dockerhub:
name: Push image to dockerhub
env:
BUILD_CONFIG: Release
NUGET_AUTH_TOKEN: ${{secrets.NUGET_TOKEN}}
TEST_USER: root
TEST_PASSWORD: TestPass123
TEST_DATABASE: TestDatabase
DB_TEST_PROJECT: test/DbIntegrationTests
USERNAME: ${{secrets.DOCKER_USER}}
PASSWORD: ${{secrets.DOCKER_TOKEN}}

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
dotnet-version: 8.0.x
source-url: https://api.nuget.org/v3/index.json
- name: Setup MySQL
uses: mirromutth/[email protected]
with:
# Required if "mysql user" is empty, default is empty. The root superuser password
mysql root password: $TEST_PASSWORD
# MYSQL_DATABASE - name for the default database that is created
mysql database: $TEST_DATABASE
- name: Set secrets
run: dotnet user-secrets set "ConnectionStrings:ModelDb" "server=localhost;database=$TEST_DATABASE;user=$TEST_USER;password=$TEST_PASSWORD" --project $DB_TEST_PROJECT
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build -c $BUILD_CONFIG --no-restore
- name: Test
run: dotnet test -c $BUILD_CONFIG --no-build --verbosity normal
- name: Publish
run: dotnet nuget push **\*.nupkg --skip-duplicate -k ${NUGET_AUTH_TOKEN}
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

0 comments on commit 429586a

Please sign in to comment.