build: 移除DockerHub相关配置,添加GitHub容器注册表支持 #47
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: build docker image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| release: | |
| types: [created, published] # 表示在创建新的 Release 时触发 | |
| # Allows you to run this workflow manually from the Actions tab | |
| # 可以手动触发 | |
| workflow_dispatch: | |
| inputs: | |
| logLevel: | |
| description: "Log level" | |
| required: true | |
| default: "warning" | |
| tags: | |
| description: "Test scenario tags" | |
| env: | |
| DOCKERHUB_USERNAME: eryajf | |
| ALIHUB_URL: registry.cn-hangzhou.aliyuncs.com | |
| ALIHUB_USERNAME: eryajf | |
| ALIHUB_IMAGE_REPONAME: eryajf | |
| IMAGE_REPONAME: eryajfctl | |
| jobs: | |
| buildImage: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Inject slug/short variables | |
| uses: rlespinasse/github-slug-action@v4 | |
| - name: Get current date | |
| id: date | |
| run: echo "today=$(date +'%Y%m%d-%H%M')" >> $GITHUB_OUTPUT | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ env.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # - name: Login to the Ali Registry | |
| # uses: docker/login-action@v3 | |
| # with: | |
| # registry: ${{ env.ALIHUB_URL }} | |
| # username: ${{ env.ALIHUB_USERNAME }} | |
| # password: ${{ secrets.ALIHUB_TOKEN }} | |
| # - name: 设置go环境 | |
| # uses: actions/setup-go@v5 | |
| # with: | |
| # go-version-file: "go.mod" | |
| # cache-dependency-path: "go.sum" | |
| # - name: 安装 UPX | |
| # uses: crazy-max/ghaction-upx@v3 | |
| # with: | |
| # install-only: true | |
| # - run: go install github.com/authelia/gox@latest # setup gox | |
| # - run: make gox-linux | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: ${{ github.event_name != 'pull_request' }} | |
| cache-from: type=registry,ref=${{ env.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPONAME }}:buildcache | |
| cache-to: type=registry,ref=${{ env.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPONAME }}:buildcache,mode=max | |
| platforms: linux/amd64,linux/arm64 | |
| tags: | | |
| ${{ env.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPONAME }}:latest | |
| ${{ env.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPONAME }}:${{ env.GITHUB_REF_NAME }} | |
| ${{ env.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPONAME }}:${{ steps.date.outputs.today }} | |
| ghcr.io/${{ github.actor }}/${{ github.repository }} | |
| ghcr.io/${{ github.actor }}/${{ github.repository }}:${{ env.GITHUB_REF_NAME }} | |
| ghcr.io/${{ github.actor }}/${{ github.repository }}:${{ steps.date.outputs.today }} |