Skip to content

Build Container

Build Container #75

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
- name: update tag
uses: richardsimko/update-tag@v1
with:
tag_name: ${{ env.GitVersion_SemVer }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.ref == 'refs/heads/main'
- 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=${{ env.GitVersion_SemVer }} --tag ${{ secrets.DOCKERHUB_REPO }}:${{ env.GitVersion_SemVer }} --tag ${{ secrets.DOCKERHUB_REPO }}:latest .
- name: update kustomize overlay
uses: mikefarah/yq@master
with:
cmd: yq -i '.images.[0].newTag = "${{ env.GitVersion_SemVer }}"' 'k8s/overlays/${{ github.ref == 'refs/heads/main' && 'test' || 'dev' }}/kustomization.yaml'
- id: commit_kustomize_change
name: commit kustomize change
run : |
git config --global user.name '${{ github.actor }}'
git config --global user.email '${{ github.actor }}@users.noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git checkout "${GITHUB_REF:11}"
git stage 'k8s/overlays/${{ github.ref == 'refs/heads/main' && 'test' || 'dev' }}/kustomization.yaml'
git commit -am "[promotion:demo] Updating ${{ github.ref == 'refs/heads/main' && 'test' || 'dev' }} to ${{ env.GitVersion_SemVer }}"
git push --set-upstream origin ${GITHUB_REF:11}
echo "The current branch is ${{ github.ref }}"
if [[ "${{ github.ref }}" != "refs/head/main" ]]; then
echo "The current branch is not the main branch, updating the dev-argo tag"
git tag 'dev-argo' --force
git push origin 'dev-argo' --force
else
echo "The curent branch is the main branch, leaving the dev-argo tag alone"
fi