11---
22name : " Build and push docker image"
3- description : " Build and push docker image by digest with Rust caching"
3+ description : |
4+ Build and push docker image by digest with extensive caching.
5+
6+ This action builds and pushes a Docker image to Docker Hub.
7+ It uses caching for Rust dependencies and Docker layers.
8+ It also provides sccache settings to the docker builder for caching Rust compilation.
9+
10+ Layers cache and sccache will use the same credentials and S3 bucket, but different prefixes.
411inputs :
512 image_name :
613 description : Name of image in Docker Hub, like `drive`
@@ -25,21 +32,24 @@ inputs:
2532 cargo_profile :
2633 description : Cargo build profile, i.e release or dev
2734 default : dev
28- bucket :
29- description : S3 bucket to use for caching, must match runner define in `runs-on`
30- default : multi-runner-cache-x1xibo9c
31- region :
35+ cache_bucket :
36+ description : S3 bucket to use for caching (both sccache and layer cache)
37+ required : true
38+ cache_region :
3239 description : S3 bucket region
3340 required : true
34- aws_access_key_id :
35- description : AWS access key ID
41+ cache_endpoint :
42+ description : S3 endpoint to use for caching
43+ required : true
44+ cache_access_key_id :
45+ description : Access key ID for s3 cache
3646 required : true
37- aws_secret_access_key :
38- description : AWS secret access key
47+ cache_secret_access_key :
48+ description : Secret access key for s3 cache
3949 required : true
4050 cache_to_name :
41- description : ' Save cache to name manifest (should be used only on default branch)'
42- default : ' false'
51+ description : " Save cache to name manifest (should be used only on default branch)"
52+ default : " false"
4353outputs :
4454 digest :
4555 value : ${{ steps.docker_build.outputs.digest }}
8090 id : layer_cache_settings
8191 with :
8292 name : ${{ inputs.image_name }}
83- region : ${{ inputs.region }}
84- bucket : ${{ inputs.bucket }}
93+ region : ${{ inputs.cache_region }}
94+ bucket : ${{ inputs.cache_bucket }}
95+ endpoint : ${{ inputs.cache_endpoint }}
96+ prefix : " cache-layers/${{ inputs.platform }}/"
8597 cache_to_name : ${{ inputs.cache_to_name }}
98+ s3_access_key_id : ${{ inputs.cache_access_key_id }}
99+ s3_secret_access_key : ${{ inputs.cache_secret_access_key }}
86100
87101 - name : Set HOME variable to github context
88102 shell : bash
@@ -133,7 +147,7 @@ runs:
133147 id : arch
134148 uses : actions/github-script@v6
135149 with :
136- result-encoding : ' string'
150+ result-encoding : " string"
137151 script : return '${{ inputs.platform }}'.replace('linux/', '');
138152
139153 - name : Inject cargo cache into docker
@@ -148,9 +162,24 @@ runs:
148162 }
149163 skip-extraction : ${{ steps.yarn-cache.outputs.cache-hit }}
150164
165+ - name : Configure sccache settings
166+ uses : ./.github/actions/sccache
167+ id : sccache
168+ with :
169+ bucket : ${{ inputs.cache_bucket }}
170+ region : ${{ inputs.cache_region }}
171+ endpoint : ${{ inputs.cache_endpoint }}
172+ access_key_id : ${{ inputs.cache_access_key_id }}
173+ secret_access_key : ${{ inputs.cache_secret_access_key }}
174+ platform : ${{ inputs.platform }}
175+ install : false
176+
151177 - name : Build and push Docker image ${{ inputs.image }}
152178 id : docker_build
153179 uses : docker/build-push-action@v6
180+ env :
181+ # AWS profile to be used by layer cache; sccache settings are passed via build-args
182+ AWS_PROFILE : ${{ steps.layer_cache_settings.outputs.aws_profile }}
154183 with :
155184 context : .
156185 builder : ${{ steps.buildx.outputs.name }}
@@ -159,14 +188,9 @@ runs:
159188 push : ${{ inputs.push_tags }}
160189 tags : ${{ inputs.push_tags == 'true' && steps.docker_meta.outputs.tags || '' }}
161190 platforms : ${{ inputs.platform }}
162- build-args : |
163- CARGO_BUILD_PROFILE=${{ inputs.cargo_profile }}
164- RUSTC_WRAPPER=sccache
165- SCCACHE_BUCKET=${{ inputs.bucket }}
166- SCCACHE_REGION=${{ inputs.region }}
167- SCCACHE_S3_KEY_PREFIX=${{ runner.os }}/sccache
168- AWS_ACCESS_KEY_ID=${{ inputs.aws_access_key_id }}
169- AWS_SECRET_ACCESS_KEY=${{ inputs.aws_secret_access_key }}
191+ secret-files : |
192+ AWS=${{ env.HOME }}/.aws/credentials
193+ build-args : ${{ steps.sccache.outputs.env_vars }}
170194 cache-from : ${{ steps.layer_cache_settings.outputs.cache_from }}
171195 cache-to : ${{ steps.layer_cache_settings.outputs.cache_to }}
172196 outputs : type=image,name=${{ inputs.image_org }}/${{ inputs.image_name }},push-by-digest=${{ inputs.push_tags != 'true' }},name-canonical=true,push=true
0 commit comments