Skip to content

Build and Push Docker Images #8

Build and Push Docker Images

Build and Push Docker Images #8

Workflow file for this run

name: Build and Push Docker Images
on:
push:
branches:
- main
workflow_dispatch:
inputs:
image:
type: choice
description: Image to build and push
options:
- simple
- flask
- legacy
jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
image:
- simple
- flask
- legacy
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check if image should be updated
id: check
run: |
if [ "${{ github.event.inputs.image }}" == "${{ matrix.image }}" ]; then
echo "update=true" >> $GITHUB_STATE
echo "Manually triggered build and push for ${{ matrix.image }}."
elif git diff --quiet HEAD~1 -- "${{ matrix.image }}"; then
echo "update=false" >> $GITHUB_STATE
echo "No changes detected in ${{ matrix.image }}, skipping."
else
echo "update=true" >> $GITHUB_STATE
echo "Changes detected in ${{ matrix.image }}, building and pushing."
fi
- name: Set up Docker Buildx
if: steps.check.outputs.update == 'true'
uses: docker/setup-buildx-action@v2
- name: Log in to DockerHub
if: steps.check.outputs.update == 'true'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
if: steps.check.outputs.update == 'true'
uses: docker/build-push-action@v5
with:
context: ${{ matrix.image }}
push: true
tags: pwncollege/challenge-${{ matrix.image }}:latest