From fc0cdbaa992aa7b6c6098ef349499d1b83cf2568 Mon Sep 17 00:00:00 2001 From: kjubybot Date: Thu, 27 Feb 2025 03:08:35 +0400 Subject: [PATCH] CI caching (#2103) * use docker cache for ci; split builds --- .github/workflows/master.yml | 77 ++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 3a8e83324..4f1d37681 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -113,24 +113,85 @@ jobs: file: ./services/app/assp/codebattle/cover/excoveralls.json fail_ci_if_error: false + codebattle-docker-matrix: + if: github.repository == 'hexlet-codebattle/codebattle' + runs-on: ubuntu-latest + timeout-minutes: 30 # Add timeout to prevent hanging builds + needs: build + + strategy: + matrix: + target: + - assets-image + - compile-image + - nginx-assets + - runtime-image + include: + - target: runtime-image + tag: latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build codebattle ${{ matrix.target }} + uses: docker/build-push-action@v6 + with: + context: services/app + file: services/app/Dockerfile.codebattle + build-args: | + GIT_HASH=${{ github.sha }} + push: ${{ github.ref_name == 'master' }} + target: ${{ matrix.target }} + tags: codebattle/codebattle:${{ matrix.tag != '' && matrix.tag|| matrix.target }} + cache-to: type=registry,ref=codebattle/codebattle:${{ matrix.target }}-buildcache + cache-from: type=registry,ref=codebattle/codebattle:${{ matrix.target }}-buildcache,image-manifest=true + + runner-docker-matrix: + if: github.repository == 'hexlet-codebattle/codebattle' + runs-on: ubuntu-latest + timeout-minutes: 30 # Add timeout to prevent hanging builds + needs: build + + strategy: + matrix: + target: + - compile-image + - runtime-image + include: + - target: runtime-image + tag: latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build and push codebattle image - run: | - make GIT_HASH=${{ github.sha }} docker-build-codebattle - make docker-push-codebattle + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push runner image - run: | - make docker-build-runner - make docker-push-runner + - name: Build runner ${{ matrix.target }} + uses: docker/build-push-action@v6 + with: + context: services/app + file: services/app/Dockerfile.runner + push: ${{ github.ref_name == 'master' }} + target: ${{ matrix.target }} + tags: codebattle/runner:${{ matrix.tag != '' && matrix.tag|| matrix.target }} + cache-to: type=registry,ref=codebattle/runner:${{ matrix.target }}-buildcache + cache-from: type=registry,ref=codebattle/runner:${{ matrix.target }}-buildcache,image-manifest=true # stop integratoin tests on CI becaues of https://github.com/hexlet-codebattle/codebattle/runs/580337561?check_suite_focus=true # - name: Pull dockers