Skip to content

Commit 62ebb98

Browse files
committed
first
1 parent 4419699 commit 62ebb98

File tree

10 files changed

+765
-1
lines changed

10 files changed

+765
-1
lines changed

Jekyll-S3.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/sh
2+
3+
# Original script: https://gist.github.com/imkarthikk/2fe9053f0aef275f5527
4+
# Run it from the root of your Jekyll site like bash Jekyll-S3.sh
5+
6+
# This script uses the AWS command line interface (CLI) tool to upload content
7+
# to S3. The okta-awscli tool can be set up to get temporary credentials for
8+
# use by the AWS CLI.
9+
#
10+
# For details about using okta-awscli with the AWS CLI, see also:
11+
# https://confluence.nmdp.org/display/BIO/AWS+CLI+access+with+Okta+%28with+MFA%29+-+BIO+and+GDR
12+
#
13+
# E.g.
14+
# brew install okta-awscli
15+
# brew install awscli
16+
# (define [bio] and [gdr] profiles in ~/.okta-aws)
17+
# okta-awscli --okta-profile bio --profile bio
18+
# aws --profile bio <awscli command>
19+
20+
##
21+
# Configuration options
22+
##
23+
STAGING_BUCKET='s3://plstring-org-staging'
24+
LIVE_BUCKET='s3://plstring.org'
25+
SITE_DIR='_site/'
26+
AWS_S3_CMD='aws --profile bio s3'
27+
28+
##
29+
# Usage
30+
##
31+
usage() {
32+
cat << _EOF_
33+
Usage: ${0} [staging | live]
34+
35+
staging Deploy to the staging bucket
36+
live Deploy to the live (www) bucket
37+
_EOF_
38+
}
39+
40+
##
41+
# Color stuff
42+
##
43+
NORMAL=$(tput sgr0)
44+
RED=$(tput setaf 1)
45+
GREEN=$(tput setaf 2; tput bold)
46+
YELLOW=$(tput setaf 3)
47+
48+
function red() {
49+
echo "$RED$*$NORMAL"
50+
}
51+
52+
function green() {
53+
echo "$GREEN$*$NORMAL"
54+
}
55+
56+
function yellow() {
57+
echo "$YELLOW$*$NORMAL"
58+
}
59+
60+
##
61+
# Actual script
62+
##
63+
64+
# Expecting at least 1 parameter
65+
if [[ "$#" -ne "1" ]]; then
66+
echo "Expected 1 argument, got $#" >&2
67+
usage
68+
exit 2
69+
fi
70+
71+
if [[ "$1" = "live" ]]; then
72+
BUCKET=$LIVE_BUCKET
73+
green 'Deploying to live bucket'
74+
else
75+
BUCKET=$STAGING_BUCKET
76+
green 'Deploying to staging bucket'
77+
fi
78+
79+
80+
yellow '--> Running Jekyll'
81+
bundle exec jekyll build \
82+
|| { red '--> Jekyll build failed' ; exit 3 ; }
83+
84+
85+
yellow '--> Gzipping all html, css and js files'
86+
find $SITE_DIR \( -iname '*.html' -o -iname '*.css' -o -iname '*.js' \) -exec gzip -9 -n {} \; -exec mv {}.gz {} \; \
87+
|| { red '--> Gzipping failed' ; exit 3 ; }
88+
89+
# Sync css files (Cache: 4 hours)
90+
yellow '--> Uploading css files'
91+
${AWS_S3_CMD} sync --exclude '*.*' --include '*.css' --content-type 'text/css' --cache-control 'max-age=14400' --content-encoding 'gzip' $SITE_DIR $BUCKET \
92+
|| { red '--> css upload failed' ; exit 4 ; }
93+
94+
# Sync js files (Cache: 4 hours)
95+
yellow '--> Uploading js files'
96+
${AWS_S3_CMD} sync --exclude '*.*' --include '*.js' --content-type 'application/javascript' --cache-control 'max-age=14400' --content-encoding 'gzip' $SITE_DIR $BUCKET \
97+
|| { red '--> js upload failed' ; exit 4 ; }
98+
99+
# Sync media files (Cache: 4 hours)
100+
yellow '--> Uploading images (jpg, png, ico)'
101+
${AWS_S3_CMD} sync --exclude '*.*' --include '*.jpg' --content-type 'image/jpeg' --cache-control 'max-age=14400' $SITE_DIR $BUCKET \
102+
|| { red '--> jpg upload failed' ; exit 4 ; }
103+
${AWS_S3_CMD} sync --exclude '*.*' --include '*.png' --content-type 'image/png' --cache-control 'max-age=14400' $SITE_DIR $BUCKET \
104+
|| { red '--> png upload failed' ; exit 4 ; }
105+
${AWS_S3_CMD} sync --exclude '*.*' --include '*.ico' --content-type 'image/x-icon' --cache-control 'max-age=14400' $SITE_DIR $BUCKET \
106+
|| { red '--> ico upload failed' ; exit 4 ; }
107+
108+
# Sync html files (Cache: 2 hours)
109+
yellow '--> Uploading html files'
110+
${AWS_S3_CMD} sync --exclude '*.*' --include '*.html' --content-type 'text/html' --cache-control 'max-age=7200, must-revalidate' --content-encoding 'gzip' $SITE_DIR $BUCKET \
111+
|| { red '--> html upload failed' ; exit 4 ; }
112+
113+
114+
# Sync everything else
115+
yellow '--> Syncing everything else'
116+
${AWS_S3_CMD} sync --delete $SITE_DIR $BUCKET \
117+
|| { red '--> Sync failed' ; exit 4 ; }
118+
119+
green "Done deploying to $1 bucket"

README.md

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,118 @@
11
# plstring-code-jekyll
2-
website plstring.org
2+
3+
Source code for the GL String Code web site, built using the popular
4+
Jekyll static site generator.
5+
6+
See also: https://jekyllrb.com/docs/
7+
8+
Much of the site's static content is written in kramdown, a variant of
9+
Markdown.
10+
11+
See also: https://kramdown.gettalong.org/
12+
13+
## Setup
14+
15+
If needed (e.g. under MacOS, using Homebrew) install Ruby.
16+
17+
```
18+
$ brew install ruby
19+
...
20+
$ export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
21+
$ which ruby
22+
$ ruby -v
23+
```
24+
25+
Install Jekyll and Bundler gems (e.g. under MacOS).
26+
27+
```
28+
$ gem --help
29+
...
30+
$ gem help install
31+
...
32+
$ gem install --bindir /opt/homebrew/opt/ruby/bin bundler jekyll
33+
```
34+
35+
## Build and view site
36+
37+
Build the site and start a local server to host it.
38+
39+
```
40+
$ cd jekyll-site
41+
$ bundle exec jekyll serve
42+
```
43+
44+
Browse http://localhost:4000/ to view the locally hosted site.
45+
46+
Note: To select a different Jekyll version, before doing the above
47+
edit the jekyll version in Gemfile and run `bundle install`, e.g.
48+
49+
```
50+
$ rm Gemfile.lock
51+
$ vi Gemfile
52+
$ bundle install
53+
```
54+
55+
## Deploy to Amazon S3
56+
57+
The `Jekyll-S3.sh` script can be used to deploy the site to an Amazon S3
58+
bucket. To use it, first install `okta-awscli` and the AWS command line
59+
interface (AWS CLI, a.k.a. `awscli`). E.g. (MacOS):
60+
61+
```
62+
$ brew install okta-awscli
63+
...
64+
$ brew install awscli
65+
...
66+
```
67+
68+
The `okta-awscli` tool uses the AWS Security Token Service (AWS STS) to
69+
create and provide trusted users with temporary security credentials.
70+
Documentation on how to configure `okta-awscli` for use with the NMDP's
71+
BIO and GDR AWS segments is available on Confluence, here:
72+
73+
[AWS CLI access with Okta (with MFA) - BIO and GDR](https://confluence.nmdp.org/display/BIO/AWS+CLI+access+with+Okta+%28with+MFA%29+-+BIO+and+GDR)
74+
75+
To acquire a temporary security credential using `okta-awscli`, enter
76+
a command such as the following.
77+
78+
```
79+
$ okta-awscli --okta-profile bio --profile bio
80+
Enter password:
81+
```
82+
83+
The temporary security credential enables use of both the AWS CLI and the
84+
`Jekyll-S3.sh` script. AWS CLI usage example:
85+
86+
```
87+
$ aws --profile bio s3 ls s3://plstring-org-staging
88+
...
89+
```
90+
91+
### Deploy to staging bucket
92+
93+
```
94+
$ cd jekyll-site
95+
$ ../Jekyll-S3.sh staging
96+
...
97+
```
98+
99+
To view the staging site, browse
100+
http://plstring-org-staging.s3-website-us-east-1.amazonaws.com/.
101+
102+
### Deploy to live (www) bucket
103+
104+
```
105+
$ cd jekyll-site
106+
$ ../Jekyll-S3.sh live
107+
...
108+
```
109+
110+
To view the live site, browse https://plstring.org/
111+
or http://plstring.org.s3-website-us-east-1.amazonaws.com/.
112+
113+
The HTTPS site may not update immediately, because it is cached by CloudFront.
114+
To force the CloudFront cache to update immediately (i.e. invalidate the cache),
115+
see the following.
116+
117+
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html
118+

jekyll-site/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
_site
2+
.sass-cache
3+
.jekyll-cache
4+
.jekyll-metadata
5+
vendor

jekyll-site/404.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
permalink: /404.html
3+
layout: page
4+
---
5+
6+
<style type="text/css" media="screen">
7+
.container {
8+
margin: 10px auto;
9+
max-width: 600px;
10+
text-align: center;
11+
}
12+
h1 {
13+
margin: 30px 0;
14+
font-size: 4em;
15+
line-height: 1;
16+
letter-spacing: -1px;
17+
}
18+
</style>
19+
20+
<div class="container">
21+
<h1>404</h1>
22+
23+
<p><strong>Page not found :(</strong></p>
24+
<p>The requested page could not be found.</p>
25+
</div>

jekyll-site/Gemfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
source "https://rubygems.org"
2+
# Hello! This is where you manage which Jekyll version is used to run.
3+
# When you want to use a different version, change it below, save the
4+
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
5+
#
6+
# bundle exec jekyll serve
7+
#
8+
# This will help ensure the proper Jekyll version is running.
9+
# Happy Jekylling!
10+
gem "jekyll", "~> 4.4.1"
11+
# This is the default theme for new Jekyll sites. You may change this to anything you like.
12+
gem "minima", "~> 2.5"
13+
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
14+
# uncomment the line below. To upgrade, run `bundle update github-pages`.
15+
# gem "github-pages", group: :jekyll_plugins
16+
# If you have any plugins, put them here!
17+
group :jekyll_plugins do
18+
gem "jekyll-feed", "~> 0.12"
19+
end
20+
21+
# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
22+
# and associated library.
23+
platforms :mingw, :x64_mingw, :mswin, :jruby do
24+
gem "tzinfo", ">= 1", "< 3"
25+
gem "tzinfo-data"
26+
end
27+
28+
# Performance-booster for watching directories on Windows
29+
gem "wdm", "~> 0.1", :platforms => [:mingw, :x64_mingw, :mswin]
30+
31+
# Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem
32+
# do not have a Java counterpart.
33+
gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby]

0 commit comments

Comments
 (0)