diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 02a35b4..a31f8ce 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -51,6 +51,8 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + with: + buildkitd-flags: --debug - name: Login to Container Registry uses: docker/login-action@v3 @@ -59,6 +61,15 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + # Restore cache + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Generate Docker metadata id: meta uses: docker/metadata-action@v5 @@ -81,8 +92,21 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} platforms: linux/amd64 - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: | + type=local,src=/tmp/.buildx-cache + type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache + cache-to: | + type=local,dest=/tmp/.buildx-cache-new,mode=max + type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max + outputs: | + type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Временный фикс для кэша + - name: Move cache + if: always() + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache - name: Check image if: success() diff --git a/Dockerfile b/Dockerfile index 3cdcaf2..3de87a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,6 +28,7 @@ WORKDIR /app COPY --from=planner /app/recipe.json recipe.json # Собираем только зависимости RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git \ cargo chef cook --release --recipe-path recipe.json # Третий этап - Финальная сборка @@ -38,9 +39,10 @@ COPY --from=cacher /app/target target COPY --from=cacher /usr/local/cargo/registry /usr/local/cargo/registry # Копируем исходный код COPY . . -# Собираем только наш код +# Собираем наш код RUN --mount=type=cache,target=/usr/local/cargo/registry \ - cargo build --release --offline + --mount=type=cache,target=/usr/local/cargo/git \ + cargo build --release # Финальный образ FROM alpine:latest