From 7f7dc07f4caf6348c82404b22e5906543fd24cf8 Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Sat, 23 Nov 2024 01:17:24 +0400 Subject: [PATCH] Create publish-docker-image --- .github/workflows/publish-docker-image | 86 ++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/publish-docker-image diff --git a/.github/workflows/publish-docker-image b/.github/workflows/publish-docker-image new file mode 100644 index 0000000..92b43b8 --- /dev/null +++ b/.github/workflows/publish-docker-image @@ -0,0 +1,86 @@ +name: publish-docker-image + +on: + push: + tags: + # Match stable and pre versions, such as 'v1.0.0', 'v0.23.0-a', 'v0.23.0-a.2', 'v0.23.0-b', 'v0.23.0-b.3' + - "v*.*.*" + - "v*.*.*-a" + - "v*.*.*-a.*" + - "v*.*.*-b" + - "v*.*.*-b.*" + +jobs: + build-and-push-stable-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Extract build args + # Extract version number and check if it's an pre version + run: | + if [[ "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "PRE_RELEASE=false" >> $GITHUB_ENV + else + echo "PRE_RELEASE=true" >> $GITHUB_ENV + fi + echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: aykhans + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + with: + install: true + version: v0.9.1 + + # Metadata for stable versions + - name: Docker meta for stable + id: meta-stable + if: env.PRE_RELEASE == 'false' + uses: docker/metadata-action@v5 + with: + images: | + aykhans/dodo + tags: | + type=semver,pattern={{version}},value=${{ env.VERSION }} + type=raw,value=stable + flavor: | + latest=true + labels: | + org.opencontainers.image.version=${{ env.VERSION }} + + # Metadata for pre versions + - name: Docker meta for pre + id: meta-pre + if: env.PRE_RELEASE == 'true' + uses: docker/metadata-action@v5 + with: + images: | + aykhans/dodo + tags: | + type=raw,value=${{ env.VERSION }} + labels: | + org.opencontainers.image.version=${{ env.VERSION }} + + - name: Build and Push + id: docker_build + uses: docker/build-push-action@v6 + with: + context: ./ + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta-stable.outputs.tags || steps.meta-pre.outputs.tags }} + labels: ${{ steps.meta-stable.outputs.labels || steps.meta-pre.outputs.labels }}