S3 deploy: Clean up old files via `--delete`
The following discussion from !9 (merged) should be addressed:
-
@seanarnold started a discussion: (+2 comments) Do we want to add the
--delete
param here, in case we need to clean up old files?--delete (boolean) Files that exist in the destination but not in the source are deleted during sync.
https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html
As for now, we could exclude list.json
and incident/*
:
Before
$ aws s3 sync --dryrun --delete 'dist' s3://$S3_BUCKET_NAME
(dryrun) delete: s3://pleitzen-status-page-mvc-testing/incident/1.json
(dryrun) delete: s3://pleitzen-status-page-mvc-testing/incident/2.json
(dryrun) delete: s3://pleitzen-status-page-mvc-testing/incident/3.json
(dryrun) upload: dist/js/app.9b995020.js to s3://pleitzen-status-page-mvc-testing/js/app.9b995020.js
(dryrun) upload: dist/js/app.9b995020.js.map to s3://pleitzen-status-page-mvc-testing/js/app.9b995020.js.map
(dryrun) delete: s3://pleitzen-status-page-mvc-testing/js/app.f9b33dc7.js
(dryrun) delete: s3://pleitzen-status-page-mvc-testing/js/app.f9b33dc7.js.map
(dryrun) delete: s3://pleitzen-status-page-mvc-testing/list.json
After
$ aws s3 sync --dryrun --delete --exclude "list.json" --exclude "incident/*" 'dist' s3://$S3_BUCKET_NAME
(dryrun) upload: dist/js/app.9b995020.js to s3://pleitzen-status-page-mvc-testing/js/app.9b995020.js
(dryrun) upload: dist/js/app.9b995020.js.map to s3://pleitzen-status-page-mvc-testing/js/app.9b995020.js.map
(dryrun) delete: s3://pleitzen-status-page-mvc-testing/js/app.f9b33dc7.js
(dryrun) delete: s3://pleitzen-status-page-mvc-testing/js/app.f9b33dc7.js.map
Once the directory structure is finalized we can exclude all possible files uploaded by backend
Edited by Peter Leitzen