Skip to content

Commit

Permalink
🐎 ci(docker): Update Docker-Publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
KarhouTam committed Feb 26, 2024
1 parent 78e01e8 commit f0a242e
Showing 1 changed file with 30 additions and 93 deletions.
123 changes: 30 additions & 93 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
name: Docker

# 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.
name: Docker-Publish

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]


env:
# Use docker.io for Docker Hub if empty
GHCR_REGISTRY: ghcr.io
GITHUB_REGISTRY: ghcr.io
ALIYUN_REGISTRY: registry.cn-hangzhou.aliyuncs.com
DOCKERHUB_REGISTRY: docker.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

IMAGE_TAG: master

jobs:
build:
Expand All @@ -27,107 +18,53 @@ jobs:
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: Set Lowercase Variables
run: |
echo "IMAGE_LOWERCASE_OWNER=$(echo ${{ github.actor }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "IMAGE_LOWERCASE_NAME=$(echo ${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v3

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
uses: actions/checkout@v4
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
uses: docker/setup-buildx-action@v3
# https://github.com/docker/login-action
- name: Log into registry ${{ env.GHCR_REGISTRY }}
- name: Log into ghcr.io
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta-ghcr
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}

# 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-to-GitHub-container-registry
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-ghcr.outputs.tags }}
labels: ${{ steps.meta-ghcr.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.ALIYUN_REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.ALIYUN_REGISTRY }}
username: ${{ secrets.ALIYUN_USERNAME }}
password: ${{ secrets.ALIYUN_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta-aliyun
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.ALIYUN_REGISTRY }}/${{ env.IMAGE_NAME }}

# 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-to-Aliyun-container-registry
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-aliyun.outputs.tags }}
labels: ${{ steps.meta-aliyun.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.DOCKERHUB_REGISTRY }}
- name: Log into Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKERHUB_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-dockerhub
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
- name: Log into Aliyun
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
images: ${{ env.DOCKERHUB_REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
registry: ${{ env.ALIYUN_REGISTRY }}
username: ${{ secrets.ALIYUN_USERNAME }}
password: ${{ secrets.ALIYUN_TOKEN }}
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push-to-Dockerhub-container-registry
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
uses: docker/build-push-action@v5
with:
context: .
file: .environment/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-Dockerhub.outputs.tags }}
labels: ${{ steps.meta-Dockerhub.outputs.labels }}
build-args: |
REPO_PATH=.
REPO_NAME=${{ github.event.repository.name }}
tags: |
${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_LOWERCASE_OWNER }}/${{ env.IMAGE_LOWERCASE_NAME }}:${{ env.IMAGE_TAG }}
${{ env.ALIYUN_REGISTRY }}/${{ env.IMAGE_LOWERCASE_OWNER }}/${{ env.IMAGE_LOWERCASE_NAME }}:${{ env.IMAGE_TAG }}
${{ env.DOCKERHUB_REGISTRY }}/${{ env.IMAGE_LOWERCASE_OWNER }}/${{ env.IMAGE_LOWERCASE_NAME }}:${{ env.IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit f0a242e

Please sign in to comment.