Skip to content

Commit

Permalink
feat(grunt): basic s3_website support
Browse files Browse the repository at this point in the history
  • Loading branch information
sparanoid committed Dec 30, 2016
1 parent 89f36b3 commit 06df93c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
17 changes: 12 additions & 5 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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 [
Expand Down
10 changes: 9 additions & 1 deletion _deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
30 changes: 30 additions & 0 deletions s3_website.example.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 06df93c

Please sign in to comment.