Skip to content

preview.20

preview.20 #374

name: GithubActionsWIP
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
env:
appNameDS: 'icebg.web.ds.wip'
appNameUI: 'icebg.web.ui.wip'
containerRegistry: 'cricebg.azurecr.io'
images-to-keep: '10'
jobs:
############################################################################################################
# These jobs are used to gate actions. By creating these jobs we don't need to proliferate the repo checks
############################################################################################################
build-allowed:
name: Build allowed
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
steps:
- name: Nothing to see here
run: echo ""
deployment-allowed:
name: Deployment allowed
needs: [build-allowed]
runs-on: ubuntu-latest
if: github.repository == 'MarkStega/ICEBG'
steps:
- name: Nothing to see here
run: echo ""
deployment-not-allowed:
name: Deployment not allowed
needs: [build-allowed]
runs-on: ubuntu-latest
if: github.repository != 'MarkStega/ICEBG'
steps:
- name: Nothing to see here
run: echo ""
############################################################################################################
# Set unified version for the two deployed applications
############################################################################################################
set-unified-version:
name: Create the date based UnifiedVersion
needs: [deployment-allowed]
runs-on: ubuntu-latest
outputs:
unifiedVersion: ${{ steps.setUnifiedVersion.outputs.LocalUnifiedVersion }}
steps:
- id: setUnifiedVersion
run: echo "LocalUnifiedVersion=$(date +'%Y-%m-%d--%H-%M-%S')--WIP" >> $GITHUB_OUTPUT
shell: bash
############################################################################################################
# Build and deploy blazor DS image
############################################################################################################
build-deploy-ds:
name: Build and deploy ICEBG DS
needs: [set-unified-version]
runs-on: ubuntu-latest
steps:
- name: Retrieve the global UnifiedVersion
run: echo "unifiedVersion=${{needs.set-unified-version.outputs.unifiedVersion}}" >> $GITHUB_ENV
shell: bash
- name: Checkout repository under $GITHUB_WORKSPACE so the job can access it 🛎️
uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'
- name: Docker login
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Publish tagged DS image
run: >
dotnet publish ICEBG.Web.DataServices/ICEBG.Web.DataServices.csproj
--arch x64
--os linux
--configuration Azure
--no-self-contained
-p:ContainerImageTag=${{ env.unifiedVersion }}
-p:ContainerRegistry=${{env.containerRegistry}}
-p:ContainerRepository=${{env.appNameDS}}
-p:PublishProfile=DefaultContainer
-p:Version=${{ env.unifiedVersion }}
- name: Display package output for brotli & gzip compressed files
run: find ${{ github.workspace }} -type f \( -iname "*.br" -o -iname "*.gz" \) | sort
############################################################################################################
# Build and deploy blazor UI image
############################################################################################################
build-deploy-ui:
name: Build and deploy ICEBG UI
needs: [set-unified-version]
runs-on: ubuntu-latest
steps:
- name: Retrieve the global UnifiedVersion
run: echo "unifiedVersion=${{needs.set-unified-version.outputs.unifiedVersion}}" >> $GITHUB_ENV
shell: bash
- name: Checkout repository under $GITHUB_WORKSPACE so the job can access it 🛎️
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'
- name: 'Docker login'
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Publish tagged UI image
run: >
dotnet publish ICEBG.Web.UserInterface/ICEBG.Web.UserInterface.csproj
--arch x64
--os linux
--configuration Azure
--no-self-contained
-p:ContainerImageTag=${{ env.unifiedVersion }}
-p:ContainerRegistry=${{env.containerRegistry}}
-p:ContainerRepository=${{env.appNameUI}}
-p:PublishProfile=DefaultContainer
-p:Version=${{ env.unifiedVersion }}
- name: Display package output for brotli & gzip compressed files
run: find ${{ github.workspace }} -type f \( -iname "*.br" -o -iname "*.gz" \) | sort
############################################################################################################
# Build blazor DS image
############################################################################################################
build-ds:
name: Build ICEBG DS
needs: [deployment-not-allowed, build-allowed]
runs-on: ubuntu-latest
steps:
- name: Set unifiedVersion as env variable
run: echo "unifiedVersion=$(date +'%Y-%m-%d--%H-%M-%S')--WIP" >> $GITHUB_ENV
shell: bash
- name: Checkout repository under $GITHUB_WORKSPACE so the job can access it 🛎️
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'
- name: Build DS image
run: >
dotnet build ICEBG.Web.DataServices/ICEBG.Web.DataServices.csproj
--arch x64
--os linux
--configuration Azure
-p:Version=${{ env.unifiedVersion }}
############################################################################################################
# Build blazor UI image
############################################################################################################
build-ui:
name: Build ICEBG UI
needs: [deployment-not-allowed, build-allowed]
runs-on: ubuntu-latest
steps:
- name: Set unifiedVersion as env variable
run: echo "unifiedVersion=$(date +'%Y-%m-%d--%H-%M-%S')--WIP" >> $GITHUB_ENV
shell: bash
- name: Checkout repository under $GITHUB_WORKSPACE so the job can access it 🛎️
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'
- name: Build UI image
run: >
dotnet build ICEBG.Web.UserInterface/ICEBG.Web.UserInterface.csproj
--arch x64
--os linux
--configuration Azure
-p:Version=${{ env.unifiedVersion }}
#############################################################################################################
## Clean up after building docker containers
#############################################################################################################
cleanup-docker-containers:
name: Clean up after building docker containers
needs: [build-deploy-ds,build-deploy-ui]
runs-on: ubuntu-latest
steps:
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure CLI script to purge old DS & UI WIP container images
uses: azure/CLI@v1
with:
inlineScript: >
az acr run
--cmd "acr purge --ago 0d --keep ${{ env.images-to-keep }} --filter '${{ env.appNameDS }}:.*' --filter '${{ env.appNameUI }}:.*'"
--registry ${{ secrets.REGISTRY_LOGIN_SERVER }}
/dev/null