Skip to content

SPUC-build-test-push #6

SPUC-build-test-push

SPUC-build-test-push #6

name: SPUC-build-test-push
on:
workflow_dispatch:
inputs:
version:
description: 'Push with versioned tag?'
required: false
type: string
default: ''
push:
branches: [ "main" ]
paths:
- 'code/SPUC/Dockerfile'
- '.github/workflows/spuc-build-test-push.yaml'
jobs:
build-push:
runs-on: ubuntu-latest
env:
CONTAINER_NAME: spuc
CONTEXT: ./code/SPUC
DOCKERFILE: ./code/SPUC/Dockerfile
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to dockerhub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Pull latest image for caching
run: docker pull ${{ env.CONTAINER_NAME }}:latest || true
- name: Set tag
id: set-tag
run: |
if [ -z "${{ github.event.inputs.version }}" ]; then
echo "tag=${{ secrets.DOCKERHUB_USER }}/${{ env.CONTAINER_NAME }}:latest" >> $GITHUB_OUTPUT
else
echo "tag=${{ secrets.DOCKERHUB_USER }}/${{ env.CONTAINER_NAME }}:${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
fi
- name: Build and push to dockerhub
uses: docker/build-push-action@v5
with:
context: ${{ env.CONTEXT }}
file: ${{ env.DOCKERFILE }}
tags: ${{ steps.set-tag.outputs.tag }}
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USER }}/${{ env.CONTAINER_NAME }}:latest
cache-to: type=inline
load: true
push: true
- name: Push latest
if: ${{ github.event.inputs.version }}
run: |
docker tag ${{ secrets.DOCKERHUB_USER }}/${{ env.CONTAINER_NAME }}:${{ github.event.inputs.version }} ${{ secrets.DOCKERHUB_USER }}/${{ env.CONTAINER_NAME }}:latest
docker push ${{ secrets.DOCKERHUB_USER }}/${{ env.CONTAINER_NAME }}:latest