Skip to content

Bump docker/build-push-action from 2 to 6 #395

Bump docker/build-push-action from 2 to 6

Bump docker/build-push-action from 2 to 6 #395

Workflow file for this run

name: Build and Deploy
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
env:
CONTAINER_REGISTRY: ghcr.io
jobs:
build:
name: Build & test
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
outputs:
image_tag: ${{ steps.image.outputs.tag }}
services:
postgres:
image: postgres
env:
POSTGRES_DB: trn_generator
POSTGRES_PASSWORD: trn_generator
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
- name: Build
run: dotnet build --configuration Release
working-directory: TrnGeneratorApi
- name: Tests
uses: ./.github/workflows/actions/test
with:
test_project_path: TrnGeneratorApi/tests/TrnGeneratorApi.IntegrationTests
report_name: "Test results"
dotnet_test_args: '-e ConnectionStrings__DefaultConnection="Host=localhost;Username=postgres;Password=trn_generator;Database=trn_generator" -e ApiKeys__0="12345"'
- name: Publish
run: dotnet publish --configuration Release --no-build src/TrnGeneratorApi/TrnGeneratorApi.csproj
working-directory: TrnGeneratorApi
- name: Docker image tag
id: image
run: |
echo "tag=$CONTAINER_REGISTRY/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]'):$GITHUB_SHA" >> $GITHUB_OUTPUT
- name: Login to GitHub Cotainer Registry
uses: docker/login-action@v1
with:
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker build & push
uses: docker/build-push-action@v6
with:
context: TrnGeneratorApi/src/TrnGeneratorApi
push: true
tags: ${{ steps.image.outputs.tag }}
build-args: |
GIT_SHA=${{ github.sha }}
deploy_to_dev:
name: Deploy to dev environment
runs-on: ubuntu-latest
if: (github.event_name == 'pull_request' && github.event.pull_request.draft == false) || github.event_name == 'workflow_dispatch'
concurrency: deploy_dev
needs: [build]
environment:
name: dev
url: ${{ steps.deploy.outputs.environment_url }}
outputs:
environment_url: ${{ steps.deploy.outputs.environment_url }}
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/deploy-environment
id: deploy
with:
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
environment_name: dev
image_tag: ${{ needs.build.outputs.image_tag }}
deploy:
name: Deploy to ${{ matrix.environment }} environment
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
concurrency: deploy_${{ matrix.environment }}
needs: [build]
strategy:
max-parallel: 1
matrix:
environment: [test, preprod, production]
environment:
name: ${{ matrix.environment }}
url: ${{ steps.deploy.outputs.environment_url }}
outputs:
environment_url: ${{ steps.deploy.outputs.environment_url }}
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/deploy-environment
id: deploy
with:
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
environment_name: ${{ matrix.environment }}
image_tag: ${{ needs.build.outputs.image_tag }}