I had some fun over the last week setting up a docker image for an S3-copy utility, and integrating it into the gulp build for https://apps.frickjack.com. I pushed the image for the s3cp app up to hub.docker.com. I use s3cp to sync a local build of https://apps.frickjack.com up to an S3 bucket. I could probably coerce the AWS CLI (aws s3 sync) into doing the same job, but I wrote this app a while ago, and it includes functionality to automatically gzip-compress each asset before upload, and setup various HTTP headers on the asset (content-encoding, cache-control, content-type, and etag). For example - inspect the headers (using a browser's developer tools) on an arbitrary apps.frickjack.com asset like https://apps.frickjack.com/resources/css/littleware/styleGuide/guide.css.
A few s3cp details - it's a simple scala application with two command line flags (-config aws-key aws-secret, -copy source destination). The '-config' command saves the AWS credential under ~/.littleware/aws/. The code could use a little love - it is hard-coded to use the AWS Virginia region, it could use a '-force' option with '-copy', and its error messages are annoying - but it works for what I need. The source is on github (git clone ...; cd littleware/webapp/littleApps/s3Copy; gradle build; gradle copyToLib; cli/s3cp.sh --help).
I pushed a binary build of s3cp to dockerhub. I run it like this. First, I register my AWS credentials with the app. We only need to configure s3cp once, but we'll want to mount a docker volume to save the configuration to (I need to wire up a more secure way to save and pass the AWS secrets):
docker volume create littleware docker run -it -v littleware:/root/.littleware \ -v /home/reuben:/mnt/reuben \ --name s3cp --rm frickjack/s3cp:1.0.0 \ -config aws-key aws-secret
After the configuration is done I use s3cp with '-copy' commands like this:
docker run -it -v littleware:/root/.littleware \ -v /home/reuben:/mnt/reuben \ --name s3cp --rm frickjack/s3cp:1.0.0 \ -copy /mnt/reuben/Code/littleware-html5Client/build/ s3://apps.frickjack.com/
I added a gulp task to the apps.frickjack.com code to simplify the S3 deploy - from gulpfile.js:
gulp.task( 'deploy', [ 'compileclean' ], function(cb) { const pwdPath = process.cwd(); const imageName = "frickjack/s3cp:1.0.0"; const commandStr = "yes | docker run --rm --name s3gulp -v littleware:/root/.littleware -v '" + pwdPath + ":/mnt/workspace' " + imageName + " -copy /mnt/workspace/build/ s3://apps.frickjack.com/"; console.log( "Running: " + commandStr ); exec( commandStr, function (err, stdout, stderr) { console.log(stdout); console.log(stderr); if ( err ) { //reject( err ); } else { cb(); } } ); });