Skip to content

Commit ba6507a

Browse files
committed
refactor: improve readability of aws creds
1 parent f33c8c7 commit ba6507a

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

.github/actions/docker/action.yaml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ runs:
8888
endpoint: ${{ inputs.cache_endpoint }}
8989
prefix: "cache-layers/${{ inputs.platform }}/"
9090
cache_to_name: ${{ inputs.cache_to_name }}
91+
s3_access_key_id: ${{ inputs.cache_access_key_id }}
92+
s3_secret_access_key: ${{ inputs.cache_secret_access_key }}
9193

9294
- name: Set HOME variable to github context
9395
shell: bash
@@ -153,8 +155,9 @@ runs:
153155
}
154156
skip-extraction: ${{ steps.yarn-cache.outputs.cache-hit }}
155157

156-
- name: Setup sccache vars
158+
- name: Configure sccache settings
157159
uses: ./.github/actions/sccache
160+
id: sccache
158161
with:
159162
bucket: ${{ inputs.cache_bucket }}
160163
region: ${{ inputs.cache_region }}
@@ -167,6 +170,7 @@ runs:
167170
- name: Build and push Docker image ${{ inputs.image }}
168171
id: docker_build
169172
uses: docker/build-push-action@v6
173+
env: ${{ steps.layer_cache_settings.outputs.env_vars }}
170174
with:
171175
context: .
172176
builder: ${{ steps.buildx.outputs.name }}
@@ -177,14 +181,7 @@ runs:
177181
platforms: ${{ inputs.platform }}
178182
secret-files: |
179183
AWS=${{ env.HOME }}/.aws/credentials
180-
build-args: |
181-
CARGO_BUILD_PROFILE=${{ inputs.cargo_profile }}
182-
SCCACHE_BUCKET=${{ inputs.cache_bucket }}
183-
SCCACHE_REGION=${{ inputs.cache_region }}
184-
SCCACHE_ENDPOINT=${{ inputs.cache_endpoint }}
185-
SCCACHE_S3_KEY_PREFIX=${{ env.SCCACHE_S3_KEY_PREFIX }}
186-
SCCACHE_VERSION=${{ env.SCCACHE_VERSION }}
187-
AWS_PROFILE=sccache
184+
build-args: ${{ steps.sccache.outputs.env_vars }}
188185
cache-from: ${{ steps.layer_cache_settings.outputs.cache_from }}
189186
cache-to: ${{ steps.layer_cache_settings.outputs.cache_to }}
190187
outputs: type=image,name=${{ inputs.image_org }}/${{ inputs.image_name }},push-by-digest=${{ inputs.push_tags != 'true' }},name-canonical=true,push=true

.github/actions/s3-layer-cache-settings/action.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ inputs:
2525
prefix:
2626
description: S3 key prefix
2727
default: "cache-layers/"
28+
s3_access_key_id:
29+
description: Access key ID for S3 cache
30+
required: true
31+
s3_secret_access_key:
32+
description: Secret access key for S3 cache
33+
required: true
2834
mode:
2935
description: Cache mode
3036
default: max
@@ -39,10 +45,22 @@ outputs:
3945
cache_from:
4046
description: "String with s3-based cache configuration for docker buildx cache-from option"
4147
value: ${{ steps.script.outputs.cache_from }}
48+
env_vars:
49+
description: "Environment variables to set before running docker buildx"
50+
value: |
51+
AWS_PROFILE=docker-layers
52+
AWS_SHARED_CREDENTIALS_FILE=${HOME}/.aws/credentials
4253
4354
runs:
4455
using: composite
4556
steps:
57+
- name: Configure AWS credentials for s3 layers
58+
uses: ./.github/actions/aws_credentials
59+
with:
60+
access_key_id: ${{ inputs.access_key_id }}
61+
secret_access_key: ${{ inputs.secret_access_key }}
62+
profile: "docker-layers"
63+
4664
- uses: actions/github-script@v6
4765
id: script
4866
with:

.github/actions/sccache/action.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ inputs:
2828
description: "sccache version"
2929
default: "0.8.2"
3030
required: false
31+
outputs:
32+
env_vars:
33+
description: "Environment variables to set"
34+
value: |
35+
AWS_PROFILE=sccache
36+
CARGO_INCREMENTAL=0
37+
RUSTC_WRAPPER=sccache
38+
SCCACHE_BUCKET=${{ inputs.bucket }}
39+
SCCACHE_REGION=${{ inputs.region }}
40+
SCCACHE_ENDPOINT=${{ inputs.endpoint }}
41+
SCCACHE_S3_KEY_PREFIX=sccache/${{ inputs.platform }}/
42+
SCCACHE_VERSION=${{ inputs.version }}
43+
CC="sccache cc"
44+
CXX="sccache c++"
3145
3246
# TODO: Cache deps here to save 1 minute
3347
runs:
@@ -57,3 +71,5 @@ runs:
5771
echo "SCCACHE_S3_KEY_PREFIX=sccache/${{ inputs.platform }}/" >> $GITHUB_ENV
5872
# "SCCACHE_VERSION" is used inside Docker to install the same version of sccache
5973
echo "SCCACHE_VERSION=${{ inputs.version }}" >> $GITHUB_ENV
74+
echo "CC=\"sccache cc\"" >> $GITHUB_ENV
75+
echo "CXX=\"sccache c++\"" >> $GITHUB_ENV

0 commit comments

Comments
 (0)