Skip to content

Docker Publish

Docker Publish #113

# for NordVPN
name: Docker Publish
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
workflow_dispatch:
release:
types: [published]
schedule:
- cron: '19 05 * * *'
# push:
# paths-ignore:
# - '.github/**'
# branches: [ "main" ]
# Publish semver tags as releases.
# tags: [ 'v*.*.*' ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: docker.io
IMAGE: privoxy
IMAGE_NAME: tmknight88/privoxy
BUILD_ARGS: |
"ALPINE_VER=${{ vars.ALPINE_VER }}"
"PRIVOXY_VER=3.0.34"
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
# 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: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ 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=tag
type=raw,enable=${{ github.event_name == 'schedule' }},value=latest
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- if: github.event_name == 'schedule'
name: Build and push Docker image on schedule
id: build-and-push-schedule
uses: docker/build-push-action@v4
with:
context: .
file: ${{ env.IMAGE }}.dockerfile
build-args: ${{ env.BUILD_ARGS }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: |
${{ steps.meta.outputs.labels }}
org.opencontainers.image.version=latest
cache-from: type=gha
cache-to: type=gha,mode=max
- if: github.event_name != 'schedule'
name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: .
file: ${{ 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