From 39d03b698d9a28b21dfa026b3b2bbb86936374cc Mon Sep 17 00:00:00 2001 From: Arseniy Savin Date: Sun, 13 Aug 2023 21:05:10 +0600 Subject: [PATCH] [+] Added backend Dockerfile build and push on registries action --- .github/workflows/backend-build.yaml | 62 ++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/backend-build.yaml diff --git a/.github/workflows/backend-build.yaml b/.github/workflows/backend-build.yaml new file mode 100644 index 00000000..f6c41dec --- /dev/null +++ b/.github/workflows/backend-build.yaml @@ -0,0 +1,62 @@ +name: Build and push backend + +on: + push: + branches: + - develop + - backend + paths: + - "effectiveOfficeBackend/**" + workflow_dispatch: + inputs: + hash: + description: "Commit sha256sum" + required: false + type: string + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ inputs.hash || env.GITHUB_REF }} + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # More info on https://cloud.yandex.ru/docs/container-registry/operations/authentication#sa-json + - name: Login to Yandex Container Registry + uses: docker/login-action@v2 + with: + registry: cr.yandex + username: json_key + password: ${{ secrets.YACLOUD_JSON_KEY }} + + # FIXME: deprecated set-output + - name: Extract current commit properties + id: commit_properties + run: | + echo "::set-output name=branch::$(echo ${GITHUB_REF#refs/heads/})" + echo "::set-output name=short_hash::$(git rev-parse --short HEAD)" + echo "::set-output name=full_hash::$(git rev-parse HEAD)" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push the Docker image + uses: docker/build-push-action@v4 + with: + cache-from: type=registry,ref=${{ vars.DOCKERHUB_BACKEND_IMAGE }} + cache-to: type=registry,ref=${{ vars.DOCKERHUB_BACKEND_IMAGE }} + context: "effectiveOfficeBackend" # FIXME: hardcoded context + push: true + tags: | + ${{ vars.DOCKERHUB_BACKEND_IMAGE }}:${{ steps.commit_properties.outputs.branch }} + ${{ vars.DOCKERHUB_BACKEND_IMAGE }}:${{ steps.commit_properties.outputs.short_hash }} + ${{ vars.DOCKERHUB_BACKEND_IMAGE }}:${{ steps.commit_properties.outputs.full_hash }} + ${{ vars.YACLOUD_BACKEND_IMAGE }}:${{ steps.commit_properties.outputs.branch }} -- GitLab