From bb62a67cb209710120ea288b678b6d7099e380a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Tue, 8 Oct 2024 18:11:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8F=91=E5=B8=83=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=B7=A5=E4=BD=9C=E6=B5=81=E5=B9=B6=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E6=9E=84=E5=BB=BA=E5=B7=A5=E4=BD=9C=E6=B5=81=E4=B8=BA?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=A4=9C=E9=97=B4=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/release-tag.yaml | 77 +++++++++++++++++++ ...docker-image.yaml => release-nightly.yaml} | 30 ++------ 2 files changed, 82 insertions(+), 25 deletions(-) create mode 100644 .gitea/workflows/release-tag.yaml rename .github/workflows/{build-docker-image.yaml => release-nightly.yaml} (68%) diff --git a/.gitea/workflows/release-tag.yaml b/.gitea/workflows/release-tag.yaml new file mode 100644 index 0000000..201b541 --- /dev/null +++ b/.gitea/workflows/release-tag.yaml @@ -0,0 +1,77 @@ +name: Release Tag + +on: + push: + tags: + - "*" + +env: + DOCKER_IMAGE_NAME: murielmay67761/docker-example + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ env.DOCKERHUB_USERNAME }} + password: ${{ env.DOCKERHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + uses: actions/cache@v4 + with: + path: | + /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: | + docker.io/${{ env.DOCKER_IMAGE_NAME }} + tags: | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + type=semver,pattern={{major}} + type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }} + + # type=pep440,pattern={{raw}},enable=${{ startsWith(github.ref, 'refs/tags/') }} + + # type=schedule,pattern={{date 'YYYYMMDD-HHmmss' tz='UTC'}} + # type=ref,event=branch + # type=ref,event=pr + # type=semver,pattern={{version}} + # type=semver,pattern={{major}}.{{minor}}.{{patch}} + # type=sha + + - name: Print metadata + run: | + echo "tags: ${{ steps.meta.outputs.tags }}" + echo "labels: ${{ steps.meta.outputs.labels }}" + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + file: ./Dockerfile + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache \ No newline at end of file diff --git a/.github/workflows/build-docker-image.yaml b/.github/workflows/release-nightly.yaml similarity index 68% rename from .github/workflows/build-docker-image.yaml rename to .github/workflows/release-nightly.yaml index 85df94f..875d95e 100644 --- a/.github/workflows/build-docker-image.yaml +++ b/.github/workflows/release-nightly.yaml @@ -1,14 +1,13 @@ -name: Build Docker Image +name: Release Nightly on: - workflow_dispatch: push: + branches: [main] + tags: + - "*" env: - DOCKER_IMAGE_NAME: yanhao98/docker-example GHCR_IMAGE_NAME: ${{ github.repository }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }} GHCR_USERNAME: ${{ github.repository_owner }} @@ -19,13 +18,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # - name: Login to DockerHub - # uses: docker/login-action@v3 - # with: - # registry: docker.io - # username: ${{ env.DOCKER_USERNAME }} - # password: ${{ env.DOCKER_PASSWORD }} - - name: Login to GHCR uses: docker/login-action@v3 with: @@ -39,21 +31,11 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - # - name: Cache Docker layers - # uses: actions/cache@v4 - # with: - # path: | - # /tmp/.buildx-cache - # key: ${{ runner.os }}-buildx-${{ github.sha }} - # restore-keys: | - # ${{ runner.os }}-buildx- - - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: | - # docker.io/${{ env.DOCKER_IMAGE_NAME }} ghcr.io/${{ env.GHCR_IMAGE_NAME }} tags: | type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} @@ -84,6 +66,4 @@ jobs: labels: ${{ steps.meta.outputs.labels }} file: ./Dockerfile cache-from: type=gha - cache-to: type=gha,mode=max - # cache-from: type=local,src=/tmp/.buildx-cache - # cache-to: type=local,dest=/tmp/.buildx-cache + cache-to: type=gha,mode=max \ No newline at end of file