Skip to content

Publish Docker image #771

Publish Docker image

Publish Docker image #771

name: "Publish Docker image"
# 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:
schedule:
- cron: '33 00 * * *'
release:
types: [published]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
DOCKER_REGISTRY: tmknight88
# name of image
IMAGE: nordvpn
# github.repository as <account>/<repo>
IMAGE_NAME: tmknight/nordvpn
# Build args
BUILD_ARGS: |
"UBUNTU_VER=${{ vars.UBUNTU_VER }}"
"REPO_URL=${{ vars.REPO_URL }}"
jobs:
nordvpn-version:
uses: ./.github/workflows/get-version.yml
build:
needs: nordvpn-version
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@v4
# Setup QEMU for multi-arch
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: amd64,arm64
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
id: container-registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log into Docker Hub
id: docker-hub
if: github.event_name != 'workflow_dispatch'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Determine registries to publish
id: registry-select
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "IMAGES=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" >> $GITHUB_ENV
else
echo "IMAGES=${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE }}, ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" >> $GITHUB_ENV
fi
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGES }}
tags: |
type=ref,event=tag
type=raw,enable=${{ github.event_name == 'schedule' || (github.event_name == 'release' && github.event.action == 'published' && !github.event.release.prerelease) }},value=latest
type=ref,event=branch,enable=${{ github.event_name == 'workflow_dispatch' }}
# 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@v5
with:
context: .
platforms: linux/amd64,linux/arm64
file: ${{ env.IMAGE }}.dockerfile
build-args: |
${{ env.BUILD_ARGS }}
NORDVPN_VERSION=${{ vars.NORDVPN_VERSION == 'false' && needs.nordvpn-version.outputs.pkg-version || vars.NORDVPN_VERSION }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=The NordVPN client for Docker
cache-from: type=gha
cache-to: type=gha,mode=max