Skip to content

Build and push docker image #8

Build and push docker image

Build and push docker image #8

name: Build and push docker image
on:
workflow_dispatch:
workflow_call:
push:
branches:
- master
jobs:
build_and_push_docker_image:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/[email protected]
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Determine tag
id: determine_tag
run: |
base_image="ghcr.io/dfe-digital/buying-for-schools-v2"
branch="${{ github.ref_name }}"
commit="$(echo $GITHUB_SHA | head -c7)"
if [ "$branch" == "master" ]; then
echo tags=${base_image}:${commit},${base_image}:latest >> $GITHUB_OUTPUT
else
echo tags=${base_image}:${commit},${base_image}:${branch} >> $GITHUB_OUTPUT
fi
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.determine_tag.outputs.tags }}