Skip to content

Build and Push Docker Image #3

Build and Push Docker Image

Build and Push Docker Image #3

# for Privoxy
name: Build and Push Docker Image
on:
workflow_dispatch:
inputs:
registry:
description: "One of ghcr.io or docker.io"
required: true
type: string
default: ghcr.io
username:
description: "One of tmknight or tmnknight88"
required: true
type: string
default: tmknight
distro:
description: "One of alpine or ubuntu"
required: true
type: string
default: alpine
release:
description: "One of stable or edge"
required: true
type: string
default: stable
latest:
description: "Set 'latest' tag"
required: false
type: boolean
default: false
workflow_call:
inputs:
registry:
description: "One of ghcr.io or docker.io"
required: true
type: string
username:
description: "One of tmknight or tmnknight88"
required: true
type: string
distro:
description: "One of alpine or ubuntu"
required: true
type: string
release:
description: "One of stable or edge"
required: true
type: string
latest:
description: "Set 'latest' tag"
required: false
type: boolean
default: false
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ${{ github.event.inputs.registry }}
# name of image
IMAGE: privoxy
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.event.inputs.username }}/privoxy
# Build args
CONTEXT: .
DISTRO: ${{ github.event.inputs.distro }}
RELEASE: ${{ github.event.inputs.release }}
BUILD_ARGS: |
if: ${{ github.event.inputs.distro == 'alpine' }} "ALPINE_VER=${{ vars.ALPINE_VER }}"
if: ${{ github.event.inputs.distro == 'ubuntu' }} "UBUNTU_VER=${{ vars.UBUNTU_VER }}"
if: ${{ github.event.inputs.release == 'stable' }} "PRIVOXY_VER=3.0.34"
if: ${{ github.event.inputs.release == 'edge' }} "PRIVOXY_VER=3.0.35"
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Setup QEMU for multi-arch
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: amd64,arm64
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: |
if: ${{ env.REGISTRY == 'ghcr.io' }} ${{ github.actor }}
if: ${{ env.REGISTRY == 'docker.io' }} ${{ secrets.DOCKERHUB_USERNAME }}
password: |
if: ${{ env.REGISTRY == 'ghcr.io' }} ${{ secrets.GITHUB_TOKEN }}
if: ${{ env.REGISTRY == 'docker.io' }} ${{ secrets.DOCKERHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch,enable=${{ github.event_name != 'schedule' }}
type=ref,event=tag
type=schedule,pattern=nightly
type=raw,enable=${{ (env.DISTRO == 'alpine' && env.RELEASE == 'stable') || github.event.inputs.latest }},value=latest
type=raw,enable=true,value=${{ env.DISTRO }}-${{ env.RELEASE }}
type=raw,enable=${{ env.RELEASE == 'stable' }},value=${{ env.DISTRO }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: ${{ env.CONTEXT }}
platforms: linux/amd64,linux/arm64
file: docker/${{ env.DISTRO }}/${{ env.RELEASE }}/${{ env.IMAGE }}.dockerfile
build-args: ${{ env.BUILD_ARGS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max