diff --git a/.github/workflows/merge-master.yaml b/.github/workflows/merge-master.yaml new file mode 100644 index 0000000..e4e1d26 --- /dev/null +++ b/.github/workflows/merge-master.yaml @@ -0,0 +1,41 @@ +name: Build and push Docker image + +on: + push: + branches: + - master + +jobs: + push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to Quay + uses: docker/login-action@v3 + with: + registry: quay.io + username: ${{ vars.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Set up Docker BuildX + uses: docker/setup-buildx-action@v3 + with: + version: v0.11.2 + + - name: Restore build cache + uses: actions/cache@v3 + with: + path: /tmp/.buildx-${{ github.ref_name }}-cache + key: ${{ runner.os }}-buildx-${{ github.ref_name }} + restore-keys: | + ${{ runner.os }}-buildx-${{ github.ref_name }} + + - name: Build and push + run: | + make push + env: + BRANCH_NAME: ${{ github.ref_name }} + RELEASE_ID: ${{ github.run_number }} + GIT_HASH: ${{ github.sha }} diff --git a/Makefile b/Makefile index 28cf1c9..0bf387f 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,18 @@ +DOCKER_REPOSITORY ?= quay.io/road +BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD) +GIT_HASH ?= $(shell git rev-parse HEAD) +RELEASE_ID ?= $(shell id -un)-local +DOCKER_LATEST_TAG ?= latest + build: - DOCKER_BUILDKIT=1 DOCKER_SCAN_SUGGEST=false docker build -t e-flux-tools-mongo-backup:latest -f Dockerfile --platform=linux/amd64 . - docker tag e-flux-tools-mongo-backup:latest europe-west3-docker.pkg.dev/eflux-staging/docker/e-flux-tools-mongo-backup:latest - docker tag e-flux-tools-mongo-backup:latest europe-west3-docker.pkg.dev/eflux-production/docker/e-flux-tools-mongo-backup:latest + docker buildx build \ + --cache-from type=local,src=/tmp/.buildx-$(BRANCH_NAME)-mongodb-backups-cache \ + --cache-to type=local,mode=max,dest=/tmp/.buildx-$(BRANCH_NAME)-mongodb-backups-cache \ + --provenance mode=min,inline-only=true \ + --tag $(DOCKER_REPOSITORY)/mongodb-backups:$(GIT_HASH) \ + --tag $(DOCKER_REPOSITORY)/mongodb-backups:$(DOCKER_LATEST_TAG) \ + --tag $(DOCKER_REPOSITORY)/mongodb-backups:release-$(RELEASE_ID) \ + --push \ + . push: build - docker push europe-west3-docker.pkg.dev/eflux-staging/docker/e-flux-tools-mongo-backup:latest - docker push europe-west3-docker.pkg.dev/eflux-production/docker/e-flux-tools-mongo-backup:latest