-
Notifications
You must be signed in to change notification settings - Fork 12
Add Docker caching in deployments #4831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
39b90c1
deploy: cache pnpm fetch layer in service Dockerfiles
backspace b7aecb1
ci: inline docker build with ECR registry cache instead of GHA
backspace 7b27c88
ci: bump amazon-ecr-login to v2.1.5 (node24)
backspace 1fb55e9
Merge remote-tracking branch 'origin/main' into deployment-speedup-cs…
backspace 12ca827
Merge remote-tracking branch 'origin/main' into deployment-speedup-cs…
backspace ae708a3
Merge remote-tracking branch 'origin/main' into deployment-speedup-cs…
backspace 3fcf018
Merge remote-tracking branch 'origin/main' into deployment-speedup-cs…
backspace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| name: Docker build and push to ECR (with ECR registry cache) | ||
| description: | | ||
| Build a Docker image and push to AWS ECR, using an ECR-stored layer cache | ||
| rather than the GHA cache backend. This is a temporary inline replacement | ||
| for `cardstack/gh-actions/.github/workflows/docker-ecr.yml` while we | ||
| iterate on which cache backend works best for boxel's large pnpm-fetch | ||
| layers (the GHA backend transfers them too slowly to be a net win). | ||
|
|
||
| Cache lives at `<ecr-repo>:buildcache` in the same ECR repository as the | ||
| image tags. ECR pulls inside the same AWS region are typically much faster | ||
| than the GHA cache service. | ||
|
|
||
| inputs: | ||
| repository: | ||
| required: true | ||
| description: ECR repository name (without registry prefix) | ||
| environment: | ||
| required: true | ||
| description: Deployment environment (staging or production) | ||
| dockerfile: | ||
| required: false | ||
| default: "Dockerfile" | ||
| description: Path to the Dockerfile | ||
| context: | ||
| required: false | ||
| default: "." | ||
| description: Docker build context | ||
| build-args: | ||
| required: false | ||
| default: "" | ||
| description: Build args passed to docker/build-push-action | ||
| platforms: | ||
| required: false | ||
| default: "linux/amd64" | ||
| description: Target platform | ||
|
|
||
| outputs: | ||
| image: | ||
| description: Final image tag (sha-tagged) suitable for ECS task-def update | ||
| value: ${{ steps.tags.outputs.tag_sha }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 | ||
|
|
||
| - name: Set up AWS role for environment | ||
| shell: bash | ||
| env: | ||
| INPUT_ENVIRONMENT: ${{ inputs.environment }} | ||
| run: | | ||
| if [ "$INPUT_ENVIRONMENT" = "production" ]; then | ||
| echo "AWS_ROLE_ARN=arn:aws:iam::120317779495:role/github" >> "$GITHUB_ENV" | ||
| elif [ "$INPUT_ENVIRONMENT" = "staging" ]; then | ||
| echo "AWS_ROLE_ARN=arn:aws:iam::680542703984:role/github" >> "$GITHUB_ENV" | ||
| else | ||
| echo "unrecognized environment: $INPUT_ENVIRONMENT" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6.1.1 | ||
| with: | ||
| role-to-assume: ${{ env.AWS_ROLE_ARN }} | ||
| aws-region: us-east-1 | ||
|
|
||
| - id: login-ecr | ||
| uses: aws-actions/amazon-ecr-login@fa648b43de3d4d023bcb3f89ed6940096949c419 # v2.1.5 | ||
|
|
||
| - id: tags | ||
| shell: bash | ||
| env: | ||
| REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
| REPOSITORY: ${{ inputs.repository }} | ||
| ENVIRONMENT: ${{ inputs.environment }} | ||
| run: | | ||
| TAG_PREFIX="$REGISTRY/$REPOSITORY" | ||
| { | ||
| echo "tag_sha=${TAG_PREFIX}:${GITHUB_SHA::7}" | ||
| echo "tag_env=${TAG_PREFIX}:${ENVIRONMENT}" | ||
| echo "tag_latest=${TAG_PREFIX}:latest" | ||
| echo "tag_buildcache=${TAG_PREFIX}:buildcache" | ||
| } >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Build and push | ||
| uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0 | ||
| with: | ||
| context: ${{ inputs.context }} | ||
| file: ${{ inputs.dockerfile }} | ||
| push: true | ||
| # `image-manifest=true,oci-mediatypes=true` is required for the | ||
| # registry cache to round-trip through ECR — ECR rejects the | ||
| # default cache manifest format buildx uses for other registries. | ||
| cache-from: type=registry,ref=${{ steps.tags.outputs.tag_buildcache }} | ||
| cache-to: type=registry,ref=${{ steps.tags.outputs.tag_buildcache }},mode=max,image-manifest=true,oci-mediatypes=true | ||
| platforms: ${{ inputs.platforms }} | ||
| build-args: ${{ inputs.build-args }} | ||
| tags: | | ||
| ${{ steps.tags.outputs.tag_latest }} | ||
| ${{ steps.tags.outputs.tag_sha }} | ||
| ${{ steps.tags.outputs.tag_env }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an existing issue, but CS-11154 tracks it.