name: Build Docker Images

on:
  schedule:
    - cron: '0 0 * * *'
  workflow_dispatch:

jobs:
  dockerhub:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: user
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/s390x
          push: true
          tags: user/app:latest
  • Access Token可以通过Docker HubAccount Settings->Personal access tokens->Cenerate new token创建,然后通过GitHub仓库的Settings->Actions secrets and variables->New repository secret创建DOCKERHUB_TOKEN
  • tags: user/app:latest中的userapp需要修改为实际的用户名镜像名