Created
January 3, 2025 12:41
-
-
Save yin1999/95cd4e6a4a2a1ebd4f29650138506b1a to your computer and use it in GitHub Desktop.
This file contains hidden or 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: DockerBuilder | |
on: | |
release: | |
types: [published] | |
schedule: | |
- cron: "0 4 1 * *" | |
jobs: | |
publish_to_docker_hub: | |
name: Publish to Docker Hub | |
runs-on: ubuntu-latest | |
steps: | |
- name: get latest tag while released | |
if: startsWith(github.ref, 'refs/tags/') | |
run: | | |
echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> ${GITHUB_ENV} | |
- name: get latest tag while scheduled | |
if: startsWith(github.ref, 'refs/tags/') == false | |
run: | | |
echo "VERSION=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | grep -oEm 1 '"tag_name": "v[0-9]{1,}.[0-9]{1,}(.[0-9]{1,})?"' | cut -d':' -f2 | sed 's/ //g;s/"//g')" >> ${GITHUB_ENV} | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ env.VERSION }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Docker Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push to Docker Hub | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
push: true | |
# 指定多个CPU架构 | |
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: | | |
user-name/image-name:${{ env.VERSION }} | |
user-name/image-name:latest | |
ghcr.io/${{ github.repository_owner }}/image-name:${{ env.VERSION }} | |
ghcr.io/${{ github.repository_owner }}/image-name:latest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment