Skip to content

Commit dbc4ca5

Browse files
authored
Put everything needed for deploys in deploy bundles (#153)
The aim of this commit is to allow Travis to create deploy bundles for both the client and the server on tags so that everything we need for a deployment is contained in the deploy bundles. There are two separate bundles: one for the server, which includes the trypurescript binary as well as nginx configuration and the systemd service file, and one for the client, which just includes the HTML, CSS, and JS files we serve from try.purescript.org. The server bundle already exists; I have only modified it to additionally include nginx and systemd configuration. The reason for this is that I would prefer to have as much as reasonably possible of the production config in the repository, so that we can move towards more automated deployments, and also to help avoid a situation where only one person understands enough about the server setup to be able to administer it. For the client bundle, I've moved stuff we want to be publicly visible into a separate public/ directory, mostly because I don't want to include things like the output/ and node_modules/ directories in the client bundle (so that it doesn't become too large). I've also removed the client/CNAME and client/LICENSE files. The CNAME file is no longer needed: it was only used for GH pages, which I'd like to try moving away from. The license for the client code is covered by the LICENSE file at the repo root - LICENSE and client/LICENSE are the same, except that the client/LICENSE file has the copyright years listed as 2013-16, so it is redundant.
1 parent 4a9c84d commit dbc4ca5

24 files changed

+124
-20
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ cabal.sandbox.config
1313
*.chi
1414
*.chs.h
1515
*.lksh*
16+
bundle/

.travis.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ notifications:
3030
email: true
3131

3232
before_deploy:
33-
- mkdir bundle
34-
- cp `stack path --dist-dir`/build/trypurescript/trypurescript bundle/
35-
- cp LICENSE bundle/
36-
- tar czf trypurescript.tar.gz -C bundle/ .
33+
./ci/before_deploy.sh
3734

3835
deploy:
3936
provider: releases
4037
api_key: $RELEASE_KEY
41-
file: trypurescript.tar.gz
38+
file: trypurescript-$COMPONENT.tar.gz
4239
skip_cleanup: true
4340
on:
4441
tags: true

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ npm install
5050
npm run build
5151
npm run bundle
5252

53+
cd public
5354
httpserver 8080 #eg with: alias httpserver='python -m SimpleHTTPServer'
5455
open http://localhost:8080
5556
```

ci/before_deploy.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /usr/bin/env bash
2+
3+
set -ex
4+
5+
case $COMPONENT in
6+
server)
7+
mkdir bundle
8+
cp $(stack path --dist-dir)/build/trypurescript/trypurescript bundle/
9+
cp LICENSE bundle/
10+
cp -r deploy/ bundle/
11+
cp -r staging/ bundle/
12+
tar czf trypurescript-server.tar.gz -C bundle/ .
13+
;;
14+
client)
15+
mkdir bundle
16+
cp LICENSE bundle/
17+
cp -r client/public/ bundle/
18+
tar czf trypurescript-client.tar.gz -C bundle/ .
19+
;;
20+
*)
21+
echo >&2 "Unrecognised component: $COMPONENT"
22+
exit 1
23+
;;
24+
esac

client/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
/.purs*
77
/.psa*
88
/.stack*
9-
/js/index.js
9+
/public/js/index.js
1010
.spago/

client/CNAME

-1
This file was deleted.

client/LICENSE

-12
This file was deleted.

client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"scripts": {
44
"clean": "rimraf output",
55
"build": "spago build --purs-args '--censor-lib --strict'",
6-
"bundle": "spago bundle-app --to js/index.js"
6+
"bundle": "spago bundle-app --to public/js/index.js"
77
},
88
"devDependencies": {
99
"purescript": "^0.13.6",
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

deploy/nginx.conf

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
server {
3+
listen 80 default_server;
4+
listen [::]:80 default_server;
5+
6+
return 301 https://$host$request_uri;
7+
}
8+
9+
server {
10+
server_name try.purescript.org;
11+
12+
listen 443 ssl http2;
13+
listen [::]:443 ssl http2;
14+
15+
# SSL configuration
16+
# based on https://ssl-config.mozilla.org/
17+
ssl_certificate /etc/letsencrypt/live/try.purescript.org/fullchain.pem;
18+
ssl_trusted_certificate /etc/letsencrypt/live/try.purescript.org/fullchain.pem;
19+
ssl_certificate_key /etc/letsencrypt/live/try.purescript.org/privkey.pem;
20+
ssl_session_timeout 1d;
21+
ssl_session_cache shared:ssl:10m;
22+
ssl_session_tickets off;
23+
ssl_stapling on;
24+
ssl_stapling_verify on;
25+
ssl_dhparam /etc/nginx/ssl_dhparam;
26+
ssl_protocols TLSv1.2 TLSv1.3;
27+
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
28+
ssl_prefer_server_ciphers off;
29+
30+
# HSTS
31+
# Maybe enable this later
32+
# Low max-age to start with, just in case
33+
# add_header Strict-Transport-Security "max-age=60" always;
34+
35+
#
36+
# try.purescript.org specific things
37+
#
38+
39+
location / {
40+
root /var/www/trypurescript/public;
41+
}
42+
43+
}
44+
45+
server {
46+
server_name compile.purescript.org;
47+
48+
listen 443 ssl http2;
49+
listen [::]:443 ssl http2;
50+
51+
# SSL configuration
52+
# based on https://ssl-config.mozilla.org/
53+
ssl_certificate /etc/letsencrypt/live/try.purescript.org/fullchain.pem;
54+
ssl_trusted_certificate /etc/letsencrypt/live/try.purescript.org/fullchain.pem;
55+
ssl_certificate_key /etc/letsencrypt/live/try.purescript.org/privkey.pem;
56+
ssl_session_timeout 1d;
57+
ssl_session_cache shared:ssl:10m;
58+
ssl_session_tickets off;
59+
ssl_stapling on;
60+
ssl_stapling_verify on;
61+
ssl_dhparam /etc/nginx/ssl_dhparam;
62+
ssl_protocols TLSv1.2 TLSv1.3;
63+
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
64+
ssl_prefer_server_ciphers off;
65+
66+
# HSTS
67+
# Maybe enable this later
68+
# Low max-age to start with, just in case
69+
# add_header Strict-Transport-Security "max-age=60" always;
70+
71+
#
72+
# compile.purescript.org specific things
73+
#
74+
75+
location / {
76+
proxy_pass http://127.0.0.1:8081;
77+
}
78+
}

deploy/start

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /usr/bin/env/bash
2+
3+
exec trypurescript +RTS -N1 -A128m -M750M -RTS 8081 $(spago sources)

deploy/trypurescript.service

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=Web service for Try PureScript
3+
4+
[Service]
5+
Type=simple
6+
User=www-data
7+
ExecStart=/var/www/trypurescript/deploy/start
8+
WorkingDirectory=/var/www/trypurescript/staging
9+
Restart=always
10+
RestartSec=5s
11+
12+
[Install]
13+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)