From 3820ca8d2fd405f9dcf1b0b80de3b5fce98883b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=BB=AFu=20H=C3=A0?= Date: Mon, 18 Apr 2022 19:15:26 +0700 Subject: [PATCH] Create docker-build-publish.yml --- .github/workflows/docker-build-publish.yml | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/docker-build-publish.yml diff --git a/.github/workflows/docker-build-publish.yml b/.github/workflows/docker-build-publish.yml new file mode 100644 index 0000000..07529fc --- /dev/null +++ b/.github/workflows/docker-build-publish.yml @@ -0,0 +1,63 @@ +name: Build Docker Image and Publish + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + schedule: + - cron: '21 11 * * *' + push: + branches: [ master ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ master ] + +env: + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # set env short env + - name: short-sha + uses: benjlevesque/short-sha@v1.2 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into Dockerhub registry + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + push: true + tags: ${{ env.IMAGE_NAME }}:${{ env.SHA }},${{ env.IMAGE_NAME }}:latest + labels: ${{ steps.meta.outputs.labels }}