Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Storing files in an S3 bucket between GitHub Actions runs#
For my git-history live demos I needed to store quite large files (~200MB SQLite databases) in between GitHub Actions runs, to avoid having to recreate the entire file from scratch every time.
Creating the bucket and credentials#
I used my s3-credentials tool to create an S3 bucket with permanent, locked-down credentials.
1~ % s3-credentials create git-history-demos --public --create-bucket2Created bucket: git-history-demos3Attached bucket policy allowing public access4Created user: 's3.read-write.git-history-demos' with permissions boundary: 'arn:aws:iam::aws:policy/AmazonS3FullAccess'5Attached policy s3.read-write.git-history-demos to user s3.read-write.git-history-demos6Created access key for user: s3.read-write.git-history-demos7{8 "UserName": "s3.read-write.git-history-demos",9 "AccessKeyId": "AKIAWXFXAIOZOLWKY4FP",10 "Status": "Active",11 "SecretAccessKey": “…”,;12 "CreateDate": "2021-12-07 07:11:48+00:00"13}I saved the new access key and secret key to SECRETS in my repository called AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
Downloading the files as part of the Actions workflow#
Since I used --public to create the bucket, I could download files inside the action like this:
1curl -o ca-fires.db https://s3.amazonaws.com/git-history-demos/ca-fires.dbIf I had not used --public I could use s3-credentials get-object instead:
1s3-credentials get-object git-history-demos ca-fires.db -o ca-fires.dbI would need to expose the secrets as environment variables first, see below.
I actually wanted to attempt the download but keep running if the file was not there, because in this case my scripts will generate the file from scratch if it’s not already in the bucket. I used this pattern for that:
1 - name: Download ca-fires.db2 run: curl --fail -o ca-fires.db https://s3.amazonaws.com/git-history-demos/ca-fires.db3 continue-on-error: trueUploading the files to the bucket#
My step to upload the generated files to the bucket looks like this:
1 - name: Upload databases to S32 env:3 AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}4 AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}5 run: |-6 s3-credentials put-object git-history-demos pge-outages.db pge-outages.db7 s3-credentials put-object git-history-demos ca-fires.db ca-fires.db8 s3-credentials put-object git-history-demos sf-bay-511.db sf-bay-511.dbHere I’m passing through the repository secrets as environment variables that s3-credentials put-object can then use.
Full workflow is here: https://github.com/simonw/git-history/blob/main/.github/workflows/deploy-demos.yml