From 8c45639461cc988959c73838df1102d495facd56 Mon Sep 17 00:00:00 2001 From: kjubybot Date: Tue, 25 Feb 2025 17:52:57 +0100 Subject: [PATCH 1/2] use docker cache for ci; split builds --- .github/workflows/master.yml | 79 ++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 8 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 3a8e83324..e93b0425e 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -113,24 +113,87 @@ 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: codebattle + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - 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: + file: services/app/Dockerfile.codebattle + build-args: | + GIT_HASH=${{ github.sha }} + push: false + 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 + with: + fetch-depth: 1 + - 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: + file: services/app/Dockerfile.runner + push: false + 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 From cab5c6cdf9505bbaec096edab1716563ef943a5e Mon Sep 17 00:00:00 2001 From: kjubybot Date: Wed, 26 Feb 2025 20:57:59 +0100 Subject: [PATCH 2/2] add pushing docker images --- .github/workflows/master.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index caa3c411f..4f1d37681 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -128,7 +128,7 @@ jobs: - runtime-image include: - target: runtime-image - tag: codebattle + tag: latest steps: - uses: actions/checkout@v4 @@ -149,7 +149,7 @@ jobs: file: services/app/Dockerfile.codebattle build-args: | GIT_HASH=${{ github.sha }} - push: false + 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 @@ -187,7 +187,7 @@ jobs: with: context: services/app file: services/app/Dockerfile.runner - push: false + 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