Skip to content

Commit

Permalink
try setting registry cache
Browse files Browse the repository at this point in the history
  • Loading branch information
lobeto99 committed Sep 30, 2024
1 parent 301e2f9 commit 403aa82
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions .github/workflows/template-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,44 @@ jobs:
id: branch
run: echo "branch=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT

- name: Build, tag, and push image to Amazon ECR
id: build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Check if Build Cache exists
id: build-cache
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: hb-${{ inputs.service }}
IMAGE_TAG: ${{ steps.sha.outputs.sha_short }}
run: |
echo "building and pushing to: $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
docker buildx build --ssh default=${{ env.SSH_AUTH_SOCK }} -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg githubUsername=hbh-github --build-arg githubToken=${{ secrets.GH_TOKEN }} .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker pull $ECR_REGISTRY/$ECR_REPOSITORY:buildcache
if [ $? -eq 0 ]; then
echo "Cache found"
else
echo "Cache not found, building and pushing now"
docker buildx build --ssh default=${{ env.SSH_AUTH_SOCK }} -t $ECR_REGISTRY/$ECR_REPOSITORY:buildcache --build-arg githubUsername=hbh-github --build-arg githubToken=${{ secrets.GH_TOKEN }} .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:buildcache
fi
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/hb-${{ inputs.service }}:${{ steps.sha.outputs.sha_short }}
ssh: [default=${{ env.SSH_AUTH_SOCK }}]
build-args: [githubUsername=hbh-github, githubToken=${{ secrets.GH_TOKEN }}]
cache-from: type=registry,ref=${{ steps.login-ecr.outputs.registry }}/hb-${{ inputs.service }}:buildcache
cache-to: type=registry,ref=${{ steps.login-ecr.outputs.registry }}/hb-${{ inputs.service }}:buildcache,mode=max

# - name: Build, tag, and push image to Amazon ECR
# id: build
# env:
# ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
# ECR_REPOSITORY: hb-${{ inputs.service }}
# IMAGE_TAG: ${{ steps.sha.outputs.sha_short }}
# run: |
# echo "building and pushing to: $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
# docker buildx build --ssh default=${{ env.SSH_AUTH_SOCK }} -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg githubUsername=hbh-github --build-arg githubToken=${{ secrets.GH_TOKEN }} .
# docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

- name: Check if branch is up to date
id: checkCurrent
Expand Down

0 comments on commit 403aa82

Please sign in to comment.