Refactor AWS command

This commit is contained in:
Joachim 2021-06-08 18:19:52 +02:00
parent 311042a59b
commit 280be59c46

32
bw-dev
View file

@ -38,26 +38,15 @@ function makeitblack {
docker-compose run --rm web black celerywyrm bookwyrm
}
function copytos3 {
function awscommand {
# expose env vars
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
export AWS_DEFAULT_REGION=${AWS_S3_REGION_NAME}
docker run --rm -it -v bookwyrm_media_volume:/images\
# first arg is mountpoint, second is the whole aws command
docker run --rm -it -v $1\
-e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION\
amazon/aws-cli s3 cp /images s3://${AWS_STORAGE_BUCKET_NAME}/images\
--recursive --endpoint-url ${AWS_S3_ENDPOINT_URL} --acl public-read
}
function setcorstos3 {
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
export AWS_DEFAULT_REGION=${AWS_S3_REGION_NAME}
docker run --rm -it -v $(pwd):/bw\
-e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION -e AWS_ACCESS_KEY_ID\
amazon/aws-cli s3api put-bucket-cors\
--bucket ${AWS_STORAGE_BUCKET_NAME}\
--endpoint-url ${AWS_S3_ENDPOINT_URL}\
--cors-configuration file:///bw/$@
amazon/aws-cli $2
}
CMD=$1
@ -130,10 +119,17 @@ case "$CMD" in
runweb python manage.py populate_streams
;;
copy_media_to_s3)
copytos3
awscommand "bookwyrm_media_volume:/images"\
"s3 cp /images s3://${AWS_STORAGE_BUCKET_NAME}/images\
--endpoint-url ${AWS_S3_ENDPOINT_URL}\
--recursive --acl public-read"
;;
set_cors_to_s3)
setcorstos3 $@
awscommand "$(pwd):/bw"\
"s3api put-bucket-cors\
--bucket ${AWS_STORAGE_BUCKET_NAME}\
--endpoint-url ${AWS_S3_ENDPOINT_URL}\
--cors-configuration file:///bw/$@"
;;
*)
echo "Unrecognised command. Try: build, clean, up, initdb, resetdb, makemigrations, migrate, bash, shell, dbshell, restart_celery, test, pytest, test_report, black, populate_feeds, copy_media_to_s3, set_cors_to_s3"