From b469e535fb75319248334a0449915fd765a10b8b Mon Sep 17 00:00:00 2001 From: Chris Ayers Date: Wed, 14 Feb 2024 06:35:11 +0000 Subject: [PATCH] add dotnet publish workflow --- .github/workflows/dotnet-docker.yml | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/dotnet-docker.yml diff --git a/.github/workflows/dotnet-docker.yml b/.github/workflows/dotnet-docker.yml new file mode 100644 index 0000000..1b47934 --- /dev/null +++ b/.github/workflows/dotnet-docker.yml @@ -0,0 +1,49 @@ +name: Build and deploy ASP.Net Core app to an Azure Web App + +env: + DOTNET_VERSION: '8' # set this to the .NET Core version to use + +on: + push: + branches: [ "main" ] + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + env: + IMAGE_NAME: 'sampleapi' + TAG: ${{ github.sha }} + + steps: + - uses: actions/checkout@v3 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v2 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Set up dependency caching for faster builds + uses: actions/cache@v3 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget- + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ vars.DOCKER_LOGIN_SERVER }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ vars.DOCKER_LOGIN_SERVER }} + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Build with dotnet + run: dotnet publish -c Release -t:PublishContainer -p ContainerRepository=${{ vars.DOCKER_LOGIN_SERVER }}/${{ env.IMAGE_NAME }} -p ContainerRegistry=${{ vars.DOCKER_LOGIN_SERVER }} + working-directory: src/SampleApi \ No newline at end of file