Docker Image Deployment #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Image Deployment | |
on: | |
push: | |
branches: ["main"] | |
tags: ["*.*.*"] | |
workflow_dispatch: | |
pull_request: | |
env: | |
IMAGE_NAME: debian-torproxy | |
DOCKER_REPOSITORY: j3lte/debian-torproxy | |
jobs: | |
build: | |
name: Build | |
if: github.repository == 'j3lte/debian-torproxy' | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
env: | |
# Define tags to use for Docker images based on Git tags/branches (for docker/metadata-action) | |
# For a new commit on default branch (master), use the literal tag 'latest' on Docker image. | |
# For a new commit on other branches, use the branch name as the tag for Docker image. | |
# For a new tag, copy that tag name as the tag for Docker image. | |
IMAGE_TAGS: | | |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} | |
type=ref,event=branch,enable=${{ !endsWith(github.ref, github.event.repository.default_branch) }} | |
type=ref,event=tag | |
# Define default tag "flavor" for docker/metadata-action per | |
# https://github.com/docker/metadata-action#flavor-input | |
# We turn off 'latest' tag by default. | |
TAGS_FLAVOR: | | |
latest=false | |
steps: | |
- name: Checkout codebase | |
uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/[email protected] | |
with: | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/[email protected] | |
- name: Login to Docker Hub | |
if: github.event_name != 'pull_request' | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to Container registry | |
if: github.event_name != 'pull_request' | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Sync metadata (tags, labels) from GitHub to Docker for 'debian-torproxy' image | |
id: meta_build | |
uses: docker/metadata-action@v3 | |
with: | |
images: | | |
${{ env.DOCKER_REPOSITORY }} | |
ghcr.io/${{ github.repository }} | |
tags: ${{ env.IMAGE_TAGS }} | |
flavor: ${{ env.TAGS_FLAVOR }} | |
- name: Build and push 'debian-torproxy' image | |
id: docker_build | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta_build.outputs.tags }} | |
labels: ${{ steps.meta_build.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Docker Hub Description | |
if: github.event_name != 'pull_request' | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
short-description: ${{ github.event.repository.description }} | |
repository: ${{ env.DOCKER_REPOSITORY }} |