Skip to content

Build Container

Build Container #26

Workflow file for this run

name: Build Container
on:
push:
branches:
- main
- 'feature/**'
paths:
- 'src/**'
- '.github/workflows/build.yml'
workflow_dispatch:
jobs:
build-and-push-application:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['8.0.x']
steps:
- uses: actions/checkout@v1
with:
fetch-depth: '0'
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: 5.x
- id: determine_version
name: Determine Version
uses: gittools/actions/gitversion/[email protected]
with:
additionalArguments: /overrideconfig mode=Mainline
- id: EnvOverlay
name: Set Release Number
run: |
$branchName = (((${env:GITHUB_REF} -replace "refs/heads/", "") -replace "feature/", "") -replace "bugfix/", "") -replace " ", ""
Write-Host "The Branch Name is: $branchName"
$environmentName = "test"
Write-Host "The environment name is now $environmentName"
if ($branchName -ne "main")
{
Write-Host "The branch is not the main branch, using the feature branch settings instead."
$environmentName = "dev"
}
Write-Host "Setting the Output Variable KUSTOMIZE_ENVIRONMENT to $environmentName"
Write-Output "KUSTOMIZE_ENVIRONMENT=$environmentName" >> $Env:GITHUB_OUTPUT
shell: pwsh
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_PAT_USERNAME }}
password: ${{ secrets.DOCKERHUB_PAT }}
- name: install buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
- name: build and push website container
working-directory: src
run: |
docker buildx build --push --platform linux/amd64,linux/arm64 -f "./RandomQuotes.Web/Dockerfile" --build-arg APP_VERSION=${{ steps.determine_version.outputs.semVer }} --tag bobjwalker99/randomquotes-k8s:${{ steps.determine_version.outputs.semVer }} --tag bobjwalker99/randomquotes-k8s:latest .
- name: update dev kustomize
uses: mikefarah/yq@master
with:
cmd: yq -i '.images.[0].newTag = "${{ steps.determine_version.outputs.semVer }}"' 'k8s/overlays/${{ steps.EnvOverlay.outputs.KUSTOMIZE_ENVIRONMENT }}/kustomization.yaml'
- name: commit the kustomize change
uses: devops-infra/action-commit-push@master
with:
github_token: "${{ secrets.GITHUB_TOKEN }}"
commit_message: "Updating the ${{ steps.EnvOverlay.outputs.KUSTOMIZE_ENVIRONMENT }} Kustomize overlay to ${{ steps.determine_version.outputs.semVer }}"
runs-on: ubuntu-latest
steps:
- name: update tag
uses: richardsimko/update-tag@v1
with:
tag_name: ${{ steps.determine_version.outputs.semVer }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}