From 06df93cabcf8c62a3c56414c356870fab2ca29f0 Mon Sep 17 00:00:00 2001 From: Tunghsiao Liu Date: Fri, 30 Dec 2016 20:13:17 +0800 Subject: [PATCH] feat(grunt): basic `s3_website` support --- Gruntfile.coffee | 17 ++++++++++++----- _deploy.yml | 10 +++++++++- s3_website.example.yml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 s3_website.example.yml diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 519076a51..dbfea4730 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -12,8 +12,7 @@ module.exports = (grunt) -> # Track tasks load time require("time-grunt") grunt - # Get deploy target, run `$ grunt rsync --env=server01` to deploy to your - # `server01`, server info stored in `_deploy.yml`. + # Get deploy target, see `_deploy.yml` for more info deploy_env = grunt.option("env") or "default" # Project configurations @@ -322,17 +321,21 @@ module.exports = (grunt) -> options: stdout: true - # Direct rsync compiled static files to remote server + # Sync compiled static files via `rsync` amsf__deploy__rsync: command: "rsync -avz -e 'ssh -p <%= config.deploy.rsync.#{deploy_env}.port %>' --delete --progress <%= config.deploy.rsync.#{deploy_env}.params %> <%= config.dist %>/ <%= config.deploy.rsync.#{deploy_env}.user %>@<%= config.deploy.rsync.#{deploy_env}.host %>:<%= config.deploy.rsync.#{deploy_env}.dest %> > deploy-rsync-#{deploy_env}.log" + # Sync compiled static files via `s3_website` + amsf__deploy__s3: + command: "s3_website push --site=<%= config.dist %>/ > deploy-s3-#{deploy_env}.log" + # Copy compiled static files to local directory for further post-process amsf__deploy__sparanoid__copy_to_local: - command: "rsync -avz --delete --progress <%= config.deploy.rsync.#{deploy_env}.params %> <%= jekyll.dist.options.dest %>/ <%= config.deploy.s3_website.#{deploy_env}.dest %>/site/<%= config.base %> > deploy-s3_website-#{deploy_env}.log" + command: "rsync -avz --delete --progress <%= config.deploy.rsync.#{deploy_env}.params %> <%= jekyll.dist.options.dest %>/ <%= config.deploy.sparanoid.#{deploy_env}.dest %>/site/<%= config.base %> > deploy-sparanoid-#{deploy_env}.log" # Auto commit untracked files sync'ed from sync_local amsf__deploy__sparanoid__auto_commit: - command: "bash <%= config.deploy.s3_website.#{deploy_env}.dest %>/auto-commit '<%= config.pkg.name %>'" + command: "bash <%= config.deploy.sparanoid.#{deploy_env}.dest %>/auto-commit '<%= config.pkg.name %>'" amsf__core__update_deps: command: [ @@ -707,6 +710,10 @@ module.exports = (grunt) -> "shell:amsf__deploy__rsync" ] + grunt.registerTask "deploy-s3", "Deploy to AWS S3", [ + "shell:amsf__deploy__s3" + ] + grunt.registerTask "deploy-sparanoid", "Deploy to remote server (for sparanoid.com)", -> if grunt.option("no-commit") grunt.task.run [ diff --git a/_deploy.yml b/_deploy.yml index 0fe1e77bd..d02724641 100644 --- a/_deploy.yml +++ b/_deploy.yml @@ -9,6 +9,14 @@ # $ grunt && grunt deploy:rsync # $ grunt && grunt deploy:rsync --env=prod # $ grunt && grunt deploy:s3_website +# +# You can also create your own deployment method, `default` environment is +# required if no `--env` parameter passed: +# ftp: +# default: +# user: ftp_user +# port: 123 +# blah: blah rsync: default: user: rsync @@ -29,6 +37,6 @@ rsync: # I use `--rsync-path` here to run `rsync` with sudo permission. params: --rsync-path="sudo rsync" --exclude=lab -s3_website: +sparanoid: default: dest: ~/Git/sparanoid.com-prod diff --git a/s3_website.example.yml b/s3_website.example.yml new file mode 100644 index 000000000..8e9b41c22 --- /dev/null +++ b/s3_website.example.yml @@ -0,0 +1,30 @@ +# This is an example config for `s3_website` +# Rename this file to `s3_website.yml` and edit it +# See https://github.com/laurilehmijoki/s3_website for more info +s3_id: <%= ENV['S3_ID'] %> +s3_secret: <%= ENV['S3_SECRET'] %> +s3_bucket: sparanoid.com +site: . +cache_control: + "*.json": no-cache, no-store +max_age: + "*.xml": 15 + "*.css": 2592000 + "*.js": 2592000 + "*": 86400 +exclude_from_upload: + - (?:\.(?:DS_Store|bak|config|sql|fla|psd|ai|sketch|ini|log|sh|inc|swp|dist))$ +index_document: index.html +error_document: error/index.html # should match your error page permalink +concurrency_level: 10 +treat_zero_length_objects_as_redirects: true + +# CloudFront settings +cloudfront_distribution_id: <%= ENV['CF_DIST_ID'] %> +cloudfront_invalidate_root: true +cloudfront_wildcard_invalidation: true +cloudfront_distribution_config: + aliases: + quantity: 1 + items: + - sparanoid.com