Skip to content

Commit

Permalink
add cache-to and cache-from options for docker buildx build
Browse files Browse the repository at this point in the history
  • Loading branch information
AzamatKomaev committed Oct 17, 2024
1 parent 55cb200 commit 46cbae4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/build-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PORT: ${{ secrets.SSH_PORT }}

S3_ENDPOINT_URL: ${{ secrets.S3_ENDPOINT_URL }}
S3_REGION: ${{ secrets.S3_REGION }}
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}


jobs:
build:
Expand All @@ -38,13 +44,17 @@ jobs:
run: |
docker buildx build --platform linux/amd64,linux/arm64 --push ./backend \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_backend:latest \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_backend:$IMAGE_TAG
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_backend:$IMAGE_TAG \
--cache-to type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_backend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY \
--cache-from type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_backend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY
- name: Build & Publish frontend to Github Container registry
run: |
docker buildx build --platform linux/amd64,linux/arm64 --push ./frontend \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_frontend:latest \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_frontend:$IMAGE_TAG
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_frontend:$IMAGE_TAG \
--cache-to type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_frontend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY \
--cache-from type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_frontend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY
deploy:
runs-on: ubuntu-latest
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ env:
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
IMAGE_TAG: ${{ github.sha }}

S3_ENDPOINT_URL: ${{ secrets.S3_ENDPOINT_URL }}
S3_REGION: ${{ secrets.S3_REGION }}
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -33,11 +39,13 @@ jobs:
- name: Build & Publish backend to Github Container registry
run: |
docker buildx build --platform linux/amd64,linux/arm64 --push ./backend \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_backend:latest \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_backend:$IMAGE_TAG
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_backend:$IMAGE_TAG \
--cache-to type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_backend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY \
--cache-from type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_backend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY
- name: Build & Publish frontend to Github Container registry
run: |
docker buildx build --platform linux/amd64,linux/arm64 --push ./frontend \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_frontend:latest \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_frontend:$IMAGE_TAG
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_frontend:$IMAGE_TAG \
--cache-to type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_frontend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY \
--cache-from type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_frontend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY

0 comments on commit 46cbae4

Please sign in to comment.