Skip to content

Commit

Permalink
Merge branch 'issue/83-make-rake-tasks-accept-variables-and-upgrade-j…
Browse files Browse the repository at this point in the history
…ekyll' into 'master'

upgrades jekyll, adds more dynamic rake tasks

Closes docker-library#83

See merge request static-websites/techrangers-website!75
  • Loading branch information
bagofarms committed Sep 21, 2018
2 parents cd700cc + 2955e12 commit 2896f1e
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 60 deletions.
3 changes: 2 additions & 1 deletion .bundle/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
BUNDLE_PATH: "vendor/bundle"
BUNDLE_PATH: vendor/bundle
BUNDLE_DISABLE_SHARED_GEMS: '1'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.DS_Store
*/.DS_Store
_site/
vendor
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source "https://rubygems.org"
#
# This will help ensure the proper Jekyll version is running.
# Happy Jekylling!
gem "jekyll", "~> 3.6.2"
gem "jekyll", "~> 3.8.3"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Expand Down
42 changes: 27 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,51 @@ GEM
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
colorator (1.1.0)
ffi (1.9.18)
concurrent-ruby (1.0.5)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
eventmachine (1.2.7)
ffi (1.9.25)
forwardable-extended (2.6.0)
jekyll (3.6.2)
http_parser.rb (0.6.0)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jekyll (3.8.3)
addressable (~> 2.4)
colorator (~> 1.0)
em-websocket (~> 0.5)
i18n (~> 0.7)
jekyll-sass-converter (~> 1.0)
jekyll-watch (~> 1.1)
jekyll-watch (~> 2.0)
kramdown (~> 1.14)
liquid (~> 4.0)
mercenary (~> 0.3.3)
pathutil (~> 0.9)
rouge (>= 1.7, < 3)
rouge (>= 1.7, < 4)
safe_yaml (~> 1.0)
jekyll-sass-converter (1.5.0)
jekyll-sass-converter (1.5.2)
sass (~> 3.4)
jekyll-watch (1.5.0)
listen (~> 3.0, < 3.1)
kramdown (1.15.0)
jekyll-watch (2.0.0)
listen (~> 3.0)
kramdown (1.17.0)
liquid (4.0.0)
listen (3.0.8)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
mercenary (0.3.6)
pathutil (0.16.0)
pathutil (0.16.1)
forwardable-extended (~> 2.6)
public_suffix (3.0.0)
public_suffix (3.0.3)
rake (12.2.1)
rb-fsevent (0.10.2)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rouge (2.2.1)
rouge (3.2.1)
ruby_dep (1.5.0)
safe_yaml (1.0.4)
sass (3.5.3)
sass (3.5.7)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand All @@ -46,7 +58,7 @@ PLATFORMS
ruby

DEPENDENCIES
jekyll (~> 3.6.2)
jekyll (~> 3.8.3)
rake
tzinfo-data

Expand Down
64 changes: 47 additions & 17 deletions RAKEFILE
Original file line number Diff line number Diff line change
@@ -1,29 +1,59 @@
cloudfront_distribution_id = 'E1XOBY74UMJI29'
desc 'build and watch for dev'
task :dev do
sh "bundle exec jekyll serve --livereload"
end

desc 'build and watch for dev inside docker'
task :dev_docker do
# docker requires you bind to 0.0.0.0
sh "bundle exec jekyll serve --livereload --host=0.0.0.0 --port=4000 --livereload-port=35729"
end

desc 'Build for deploy'
task :build_for_deploy do
# right now this just runs build
# but we could put some more post-processing scripts in here
sh "JEKYLL_ENV=production bundle exec jekyll build"
end


# sync files from _site up to s3
# deletes files that exist on the target and dont exist locally
# sets acl to public read for all files
# sets cache control max age to 24 hours
# requires
desc 'Publish website to S3'
task :deploy_production do
# sync files from _site up to s3
# deletes files that exist on the target and dont exist locally
# sets acl to public read for all files
# sets cache control max age to 24 hours
sh "aws s3 sync ./_site/ s3://ucfcdl-website-techrangers/ --acl public-read --delete --cache-control max-age=86400"
task :deploy_production, [:bucket] do |task, args|
if args[:bucket].nil?
raise "bucket argument required"
end

sh "aws s3 sync ./_site/ s3://#{args[:bucket]}/ --acl public-read --delete --cache-control max-age=86400"
puts "Site published"
end


# Now we need to invalidate the cloudfront cache for the site
# this takes time! don't run this over and over
# todo - build a list of the files that changed and only invalidate those
desc 'Clears cache from cloudfront'
task :invalidate_cdn_cache do
# Now we need to invalidate the cloudfront cache for the site
# this takes time! don't run this over and over
# todo - build a list of the files that changed and only invalidate those
sh "aws cloudfront create-invalidation --paths '/*' --distribution-id #{cloudfront_distribution_id}"
task :invalidate_cdn_cache, [:cloudfront_distribution_id] do |task, args|
if args[:cloudfront_distribution_id].nil?
raise "cloudfront_distribution_id argument required"
end
sh "aws cloudfront create-invalidation --paths '/*' --distribution-id #{args[:cloudfront_distribution_id]}"
puts "Cache invalidation requested"
end


# Now we need to invalidate the cloudfront cache for the site
# this takes time! don't run this over and over
# todo - build a list of the files that changed and only invalidate those
desc 'show cloudfront invalidations'
task :show_invalidations do
# Now we need to invalidate the cloudfront cache for the site
# this takes time! don't run this over and over
# todo - build a list of the files that changed and only invalidate those
sh "aws cloudfront list-invalidations --distribution-id #{cloudfront_distribution_id}"
task :show_invalidations, [:cloudfront_distribution_id] do |task, args|
if args[:cloudfront_distribution_id].nil?
raise "cloudfront_distribution_id argument required"
end

sh "aws cloudfront list-invalidations --distribution-id #{args[:cloudfront_distribution_id]}"
end
54 changes: 39 additions & 15 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,86 @@ Built with [Jekyll](https://jekyllrb.com/). Use the [Jekyll Quick Start Guide](

## Setting up your environment

If you are doing this for the first time run these commands:
If you are doing this for the first time run these commands.

Running Jekyll natively on your machine is preferred, so try that option first.

If your file permissions are being a pain, or you want to use the same environment that jenkins uses to deploy - we've included a dockerfile you can use to build a reliable Docker container that has ruby and all the gems you need.

### Using Docker

In the top directory of this project, run:

`docker build --rm -t ruby-tr-site-build-container .`

Here's a breakdown of that command:

* `--rm`: remove container intermediate containers created when building
* `-t ruby-tr-site-build-container`: tag the resulting image to make it esier to identify
* `-t ruby-tr-site-build-container`: tag the resulting image to make it easier to identify
* `.`: look in this directory for a dockerfile to use for building the image

### Just MacOS

Use homebrew to install ruby, though you may not need to depending on the version included in OSX.

`brew install ruby`

`gem install bundle`

... And finally in the root of this git project, run:

`bundle install`

## Run a local development server

Once you start the jekyll server, you can view the site at [http://localhost:4000](http://localhost:4000) or [http://127.0.0.1:4000](http://127.0.0.1:4000). It will rebuild every time you make a change.

Depending on your setup, the following instructions should get your dev server running.

### Docker

`docker run --rm -p 4000:4000 -v "$(pwd)":/website ruby-tr-site-build-container bundle exec jekyll serve --host=0.0.0.0`
`docker run --rm -p 4000:4000 -p 35729:35729 -v "$(pwd)":/website ruby-tr-site-build-container bundle exec rake dev_docker`

Here's a breakdown of that command:

* `docker`: well, we're using the docker engine to do stuff
* `run`: this will start a container and execute a command we provide
* `--rm`: remove container after running
* `-p 4000:4000`: connect this machine's port 4000 to the container's port 4000
* `-p 4000:4000`: connect this machine's port 4000 to the container's port 4000 (we'll use for the website)
* `-p 35729:35729`: port used for the livereload server
* `-v "$(pwd)":/website`: mount a volume on the container, left side being the current directory `($pwd)`, right side being the place it's mounted in the container `/website`
* `ruby-tr-site-build-container`: the docker image to use
* `bundle exec jekyll serve --host=0.0.0.0`: the command being run inside the container
* `--host=0.0.0.0`: causes jekyll to bind to 0.0.0.0 inside the container to make sure requests from our host are heard by jekyll
* `ruby-tr-site-build-container`: the docker image to execute our command in
* `bundle exec rake dev_docker`: the command being run inside the container (in this case our rake command)

### MacOS

`bundle exec jekyll serve`
Just `bundle exec rake dev`

## Build and Deploy

### Docker
### Rake tasks

`docker run --rm -v "$(pwd)":/website ruby-tr-site-build-container bundle exec jekyll build`
We've built a handful of rake tasks that are easy to use. Note that these are used on Jenkins to deploy the website, so adding post-processing to the build_for_deploy script is an option.

### MacOS
Run `rake -T` to list all available tasks

```bash
$ bundle exec rake -T

rake build_for_deploy # Build for deploy
rake deploy_production[bucket] # Publish website to S3
rake dev # build and watch for dev
rake invalidate_cdn_cache[cloudfront_distribution_id] # Clears cache from cloudfront
rake show_invalidations[cloudfront_distribution_id] # show cloudfront invalidations
```

`bundle exec jekyll build`
### Docker

## Bonus rake tasks
`docker run --rm -v "$(pwd)":/website ruby-tr-site-build-container bundle exec rake build_for_deploy`

`bundle exec rake deploy_production`
### MacOS

`bundle exec rake invalidate_cdn_cache`
`bundle exec rake build_for_deploy`

## Adding a Bio

Expand Down
21 changes: 10 additions & 11 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
title: Techrangers
email: [email protected]
description: >- # this means to ignore newlines until "baseurl:"
The Techrangers® is a team of students at the Center for Distributed Learning,
who provide course development for faculty and web/application development for
The Techrangers® is a team of students at the Center for Distributed Learning,
who provide course development for faculty and web/application development for
the University of Central Florida (UCF).
baseurl: "" # the subpath of your site, e.g. /blog
url: "http://techrangers.cdl.ucf.edu" # the base hostname & protocol for your site, e.g. http://example.com
url: "https://techrangers.cdl.ucf.edu" # the base hostname & protocol for your site, e.g. http://example.com
google_analytics: UA-36116523-10

# Build settings
Expand Down Expand Up @@ -52,11 +52,10 @@ future: true
# Exclude from processing.
# The following items will not be processed, by default. Create a custom list
# to override the default setting.
# exclude:
# - Gemfile
# - Gemfile.lock
# - node_modules
# - vendor/bundle/
# - vendor/cache/
# - vendor/gems/
# - vendor/ruby/
exclude:
- RAKEFILE
- Gemfile
- Gemfile.lock
- README.MD
- dockerfile
- vendor

0 comments on commit 2896f1e

Please sign in to comment.