Skip to content

Rebuild master docker image #145

Rebuild master docker image

Rebuild master docker image #145

name: Rebuild master docker image
on:
workflow_dispatch:
schedule:
- cron: '0 12 * * 0'
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: set-up-environment
uses: DFE-Digital/github-actions/set-up-environment@master
- uses: Azure/login@v2
with:
creds: ${{ secrets.GSE_REPO_AZ_CREDENTIALS }}
- name: Fetch synk token from key vault
uses: azure/CLI@v2
id: fetch-keyvault-secret
with:
inlineScript: |
SNYK_TOKEN=$(az keyvault secret show --name "SNYK-TOKEN" --vault-name "${{ secrets.INF_KEY_VAULT}}" --query "value" -o tsv)
echo "::add-mask::$SNYK_TOKEN"
echo "SNYK-TOKEN=$SNYK_TOKEN" >> $GITHUB_OUTPUT
SLACK_WEBHOOK=$(az keyvault secret show --name "SLACK-WEBHOOK" --vault-name "${{ secrets.INF_KEY_VAULT}}" --query "value" -o tsv)
echo "::add-mask::$SLACK_WEBHOOK"
echo "SLACK-WEBHOOK=$SLACK_WEBHOOK" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@master
- name: Get Short SHA
id: sha
run: echo "short=$(echo $GITHUB_SHA | cut -c -7)" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Repository
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build docker image
uses: docker/build-push-action@v6
with:
tags: ${{ env.DOCKER_REPOSITORY }}:master
load: true
push: false
build-args: SHA=${{ steps.sha.outputs.short }}
- name: Run Snyk to check Docker image for vulnerabilities
uses: snyk/actions/docker@master
env:
SNYK_TOKEN: ${{ steps.fetch-keyvault-secret.outputs.SNYK-TOKEN }}
with:
image: ${{ env.DOCKER_REPOSITORY }}:master
args: --severity-threshold=high --file=Dockerfile --exclude-app-vulns
- name: Push image to registry
if: success()
run: docker image push --all-tags ${{ env.DOCKER_REPOSITORY }}
- name: Slack Notification
if: failure() && github.ref == 'refs/heads/master'
uses: rtCamp/action-slack-notify@master
env:
SLACK_COLOR: ${{env.SLACK_ERROR}}
SLACK_MESSAGE: 'There has been a failure building the application'
SLACK_TITLE: 'Failure Building Application'
SLACK_WEBHOOK: ${{ steps.fetch-keyvault-secret.outputs.SLACK-WEBHOOK }}