我想要以下工作流程:
YY.MM.DD
应该发生的是
YY.MM.DD
latest
和YY.MM.DD
latest
,当前sha和发布标签格式为YY.MM.DD
目前我有这个工作流程,它向 DockerHub 发布新版本和图像,但我缺少的是:
latest
YY.MM.DD
任何帮助将不胜感激!
# 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.
# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.
name: Publish Docker image
on:
release:
types: [published]
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up dynamic build ARGs
id: getargs
run: echo "version=$(cat ./stable/VERSION)" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
# list of Docker images to use as base name for tags
images: |
jokobsk/pi.alert
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
请检查:
https://blog.derlin.ch/github-actions-reusable-workflow-docker-images
作为奖励,我还希望能够推送到 Docker Hub,但仅限于特定情况(例如,从发布中,而不是从 PR 构建中)并且使用不同的标签集(没有 main-{sha}) . 这种条件性令人失望,因为默认情况下不支持它。玩了一会儿之后,我设计了一个 hack 来实现这个“如果”,而无需复制整个工作流程。 如果您有兴趣,请查看更新后的工作流程:https://github.com/derlin/rickroller/blob/e67546a90218c8300676c1270699cccdb5f7e053/.github/workflows/reusable_docker-build-and-push.yaml 让我知道如果您想发表评论,请发表评论!
希望有帮助。 菲利普·纳西门托