From 791bc30300765c8f39156dc2eb23dfa7f2c5f269 Mon Sep 17 00:00:00 2001 From: Dmitry Khokhlov Date: Mon, 7 Jul 2025 13:12:53 +0300 Subject: [PATCH 1/4] Update deploy.yml --- .github/workflows/deploy.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7bb9340..a545cba 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Build, Push, and Deploy (5 Separate Jobs) +name: Build, Push, and Deploy on: pull_request: @@ -23,6 +23,7 @@ jobs: tags: diametrfq/website:latest cache-from: type=gha cache-to: type=gha,mode=max + cache-scope: frontend-build-cache - name: Save image to tar run: docker save diametrfq/website:latest -o /tmp/frontend.tar - name: Upload image artifact @@ -46,8 +47,10 @@ jobs: push: false load: true tags: diametrfq/website-backend:latest + # ПРАВИЛЬНОЕ кэширование: только GHA и с уникальным именем cache-from: type=gha cache-to: type=gha,mode=max + cache-scope: backend-build-cache # <--- КЛЮЧЕВОЕ ИСПРАВЛЕНИЕ - name: Save image to tar run: docker save diametrfq/website-backend:latest -o /tmp/backend.tar - name: Upload image artifact From 7d90f40db2b9cdfe8699a167f2150de92be09a34 Mon Sep 17 00:00:00 2001 From: Dmitry Khokhlov Date: Sat, 12 Jul 2025 01:02:46 +0300 Subject: [PATCH 2/4] Update deploy.yml --- .github/workflows/deploy.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a545cba..e2e3cb4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,9 +21,8 @@ jobs: push: false load: true tags: diametrfq/website:latest - cache-from: type=gha - cache-to: type=gha,mode=max - cache-scope: frontend-build-cache + cache-from: type=gha,scope=frontend-build + cache-to: type=gha,mode=max,scope=frontend-build - name: Save image to tar run: docker save diametrfq/website:latest -o /tmp/frontend.tar - name: Upload image artifact @@ -47,10 +46,8 @@ jobs: push: false load: true tags: diametrfq/website-backend:latest - # ПРАВИЛЬНОЕ кэширование: только GHA и с уникальным именем - cache-from: type=gha - cache-to: type=gha,mode=max - cache-scope: backend-build-cache # <--- КЛЮЧЕВОЕ ИСПРАВЛЕНИЕ + cache-from: type=gha,scope=backend-build + cache-to: type=gha,mode=max,scope=backend-build - name: Save image to tar run: docker save diametrfq/website-backend:latest -o /tmp/backend.tar - name: Upload image artifact From d3a416a506027c0354f09fd5a4e17dbbdda248cf Mon Sep 17 00:00:00 2001 From: Dmitry Khokhlov Date: Sat, 12 Jul 2025 01:29:50 +0300 Subject: [PATCH 3/4] Update deploy.yml --- .github/workflows/deploy.yml | 40 ++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e2e3cb4..c765f4b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,6 +5,11 @@ on: branches: - main +env: + DOCKER_BUILD_RECORD_RETENTION_DAYS: 1 + BUILDX_CACHE_MAX_SIZE: 5GB + ACTIONS_CACHE_KEY_PREFIX: v1 + jobs: build_frontend_image: name: 1. Build Frontend Image @@ -21,8 +26,12 @@ jobs: push: false load: true tags: diametrfq/website:latest - cache-from: type=gha,scope=frontend-build - cache-to: type=gha,mode=max,scope=frontend-build + cache-from: | + type=gha,scope=frontend-build-${{ hashFiles('frontend/**') }} + type=gha,scope=frontend-build + cache-to: | + type=gha,mode=max,scope=frontend-build-${{ hashFiles('frontend/**') }} + type=gha,mode=min,scope=frontend-build - name: Save image to tar run: docker save diametrfq/website:latest -o /tmp/frontend.tar - name: Upload image artifact @@ -46,14 +55,18 @@ jobs: push: false load: true tags: diametrfq/website-backend:latest - cache-from: type=gha,scope=backend-build - cache-to: type=gha,mode=max,scope=backend-build + cache-from: | + type=gha,scope=backend-build-${{ hashFiles('backend/**') }} + type=gha,scope=backend-build + cache-to: | + type=gha,mode=max,scope=backend-build-${{ hashFiles('backend/**') }} + type=gha,mode=min,scope=backend-build - name: Save image to tar run: docker save diametrfq/website-backend:latest -o /tmp/backend.tar - name: Upload image artifact uses: actions/upload-artifact@v4 with: - name: backend-image + name: backend-image-${{ github.run_number }} path: /tmp/backend.tar push_frontend_image: @@ -69,7 +82,7 @@ jobs: - name: Download frontend image artifact uses: actions/download-artifact@v4 with: - name: frontend-image + name: frontend-image-${{ github.run_number }} path: /tmp - name: Load and Push Frontend Image run: | @@ -134,3 +147,18 @@ jobs: echo "Cleaning up old images..." docker system prune -af + + cleanup_artifacts: + name: 6. Cleanup Artifacts + runs-on: ubuntu-latest + needs: [deploy_to_server] + if: always() + steps: + - name: Delete build artifacts from current run + uses: geekyeggo/delete-artifact@v5 + with: + name: | + frontend-image-${{ github.run_number }} + backend-image-${{ github.run_number }} + useGlob: false + failOnError: false From 1314c6aae47cca47553974d05d334111508127f3 Mon Sep 17 00:00:00 2001 From: Dmitry Khokhlov Date: Sat, 12 Jul 2025 01:32:07 +0300 Subject: [PATCH 4/4] Update deploy.yml --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c765f4b..5d404e9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -37,7 +37,7 @@ jobs: - name: Upload image artifact uses: actions/upload-artifact@v4 with: - name: frontend-image + name: frontend-image-${{ github.run_number }} path: /tmp/frontend.tar build_backend_image: @@ -102,7 +102,7 @@ jobs: - name: Download backend image artifact uses: actions/download-artifact@v4 with: - name: backend-image + name: backend-image-${{ github.run_number }} path: /tmp - name: Load and Push Backend Image run: |