From dbc4ca5272673dd5474db66641578eec462318a4 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Fri, 1 May 2020 00:13:47 +0100 Subject: [PATCH] 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. --- .gitignore | 1 + .travis.yml | 7 +- README.md | 1 + ci/before_deploy.sh | 24 ++++++ client/.gitignore | 2 +- client/CNAME | 1 - client/LICENSE | 12 --- client/package.json | 2 +- client/{ => public}/css/flare.css | 0 client/{ => public}/css/index.css | 0 client/{ => public}/css/mathbox.css | 0 client/{ => public}/css/slides.css | 0 client/{ => public}/css/style.css | 0 client/{ => public}/frame.html | 0 client/{ => public}/img/favicon-white.svg | 0 client/{ => public}/img/favicon_clear-16.png | Bin client/{ => public}/img/favicon_clear-256.png | Bin client/{ => public}/img/favicon_clear-32.png | Bin client/{ => public}/img/loading.gif | Bin client/{ => public}/index.html | 0 client/{ => public}/js/frame.js | 0 deploy/nginx.conf | 78 ++++++++++++++++++ deploy/start | 3 + deploy/trypurescript.service | 13 +++ 24 files changed, 124 insertions(+), 20 deletions(-) create mode 100644 ci/before_deploy.sh delete mode 100644 client/CNAME delete mode 100644 client/LICENSE rename client/{ => public}/css/flare.css (100%) rename client/{ => public}/css/index.css (100%) rename client/{ => public}/css/mathbox.css (100%) rename client/{ => public}/css/slides.css (100%) rename client/{ => public}/css/style.css (100%) rename client/{ => public}/frame.html (100%) rename client/{ => public}/img/favicon-white.svg (100%) rename client/{ => public}/img/favicon_clear-16.png (100%) rename client/{ => public}/img/favicon_clear-256.png (100%) rename client/{ => public}/img/favicon_clear-32.png (100%) rename client/{ => public}/img/loading.gif (100%) rename client/{ => public}/index.html (100%) rename client/{ => public}/js/frame.js (100%) create mode 100644 deploy/nginx.conf create mode 100644 deploy/start create mode 100644 deploy/trypurescript.service diff --git a/.gitignore b/.gitignore index 884a06b7..289498d4 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ cabal.sandbox.config *.chi *.chs.h *.lksh* +bundle/ diff --git a/.travis.yml b/.travis.yml index f6039a30..a309ea98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,15 +30,12 @@ notifications: email: true before_deploy: - - mkdir bundle - - cp `stack path --dist-dir`/build/trypurescript/trypurescript bundle/ - - cp LICENSE bundle/ - - tar czf trypurescript.tar.gz -C bundle/ . + ./ci/before_deploy.sh deploy: provider: releases api_key: $RELEASE_KEY - file: trypurescript.tar.gz + file: trypurescript-$COMPONENT.tar.gz skip_cleanup: true on: tags: true diff --git a/README.md b/README.md index 2077296f..6bd843ef 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ npm install npm run build npm run bundle +cd public httpserver 8080 #eg with: alias httpserver='python -m SimpleHTTPServer' open http://localhost:8080 ``` diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh new file mode 100644 index 00000000..52cfbf97 --- /dev/null +++ b/ci/before_deploy.sh @@ -0,0 +1,24 @@ +#! /usr/bin/env bash + +set -ex + +case $COMPONENT in + server) + mkdir bundle + cp $(stack path --dist-dir)/build/trypurescript/trypurescript bundle/ + cp LICENSE bundle/ + cp -r deploy/ bundle/ + cp -r staging/ bundle/ + tar czf trypurescript-server.tar.gz -C bundle/ . + ;; + client) + mkdir bundle + cp LICENSE bundle/ + cp -r client/public/ bundle/ + tar czf trypurescript-client.tar.gz -C bundle/ . + ;; + *) + echo >&2 "Unrecognised component: $COMPONENT" + exit 1 + ;; +esac diff --git a/client/.gitignore b/client/.gitignore index 370786a3..d4779c13 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -6,5 +6,5 @@ /.purs* /.psa* /.stack* -/js/index.js +/public/js/index.js .spago/ diff --git a/client/CNAME b/client/CNAME deleted file mode 100644 index d238d507..00000000 --- a/client/CNAME +++ /dev/null @@ -1 +0,0 @@ -try.purescript.org diff --git a/client/LICENSE b/client/LICENSE deleted file mode 100644 index 91038416..00000000 --- a/client/LICENSE +++ /dev/null @@ -1,12 +0,0 @@ -Copyright (c) 2013-16 PureScript -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/client/package.json b/client/package.json index f8708fed..bdcbe669 100644 --- a/client/package.json +++ b/client/package.json @@ -3,7 +3,7 @@ "scripts": { "clean": "rimraf output", "build": "spago build --purs-args '--censor-lib --strict'", - "bundle": "spago bundle-app --to js/index.js" + "bundle": "spago bundle-app --to public/js/index.js" }, "devDependencies": { "purescript": "^0.13.6", diff --git a/client/css/flare.css b/client/public/css/flare.css similarity index 100% rename from client/css/flare.css rename to client/public/css/flare.css diff --git a/client/css/index.css b/client/public/css/index.css similarity index 100% rename from client/css/index.css rename to client/public/css/index.css diff --git a/client/css/mathbox.css b/client/public/css/mathbox.css similarity index 100% rename from client/css/mathbox.css rename to client/public/css/mathbox.css diff --git a/client/css/slides.css b/client/public/css/slides.css similarity index 100% rename from client/css/slides.css rename to client/public/css/slides.css diff --git a/client/css/style.css b/client/public/css/style.css similarity index 100% rename from client/css/style.css rename to client/public/css/style.css diff --git a/client/frame.html b/client/public/frame.html similarity index 100% rename from client/frame.html rename to client/public/frame.html diff --git a/client/img/favicon-white.svg b/client/public/img/favicon-white.svg similarity index 100% rename from client/img/favicon-white.svg rename to client/public/img/favicon-white.svg diff --git a/client/img/favicon_clear-16.png b/client/public/img/favicon_clear-16.png similarity index 100% rename from client/img/favicon_clear-16.png rename to client/public/img/favicon_clear-16.png diff --git a/client/img/favicon_clear-256.png b/client/public/img/favicon_clear-256.png similarity index 100% rename from client/img/favicon_clear-256.png rename to client/public/img/favicon_clear-256.png diff --git a/client/img/favicon_clear-32.png b/client/public/img/favicon_clear-32.png similarity index 100% rename from client/img/favicon_clear-32.png rename to client/public/img/favicon_clear-32.png diff --git a/client/img/loading.gif b/client/public/img/loading.gif similarity index 100% rename from client/img/loading.gif rename to client/public/img/loading.gif diff --git a/client/index.html b/client/public/index.html similarity index 100% rename from client/index.html rename to client/public/index.html diff --git a/client/js/frame.js b/client/public/js/frame.js similarity index 100% rename from client/js/frame.js rename to client/public/js/frame.js diff --git a/deploy/nginx.conf b/deploy/nginx.conf new file mode 100644 index 00000000..0186c3d4 --- /dev/null +++ b/deploy/nginx.conf @@ -0,0 +1,78 @@ + +server { + listen 80 default_server; + listen [::]:80 default_server; + + return 301 https://$host$request_uri; +} + +server { + server_name try.purescript.org; + + listen 443 ssl http2; + listen [::]:443 ssl http2; + + # SSL configuration + # based on https://ssl-config.mozilla.org/ + ssl_certificate /etc/letsencrypt/live/try.purescript.org/fullchain.pem; + ssl_trusted_certificate /etc/letsencrypt/live/try.purescript.org/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/try.purescript.org/privkey.pem; + ssl_session_timeout 1d; + ssl_session_cache shared:ssl:10m; + ssl_session_tickets off; + ssl_stapling on; + ssl_stapling_verify on; + ssl_dhparam /etc/nginx/ssl_dhparam; + ssl_protocols TLSv1.2 TLSv1.3; + 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; + ssl_prefer_server_ciphers off; + + # HSTS + # Maybe enable this later + # Low max-age to start with, just in case + # add_header Strict-Transport-Security "max-age=60" always; + + # + # try.purescript.org specific things + # + + location / { + root /var/www/trypurescript/public; + } + +} + +server { + server_name compile.purescript.org; + + listen 443 ssl http2; + listen [::]:443 ssl http2; + + # SSL configuration + # based on https://ssl-config.mozilla.org/ + ssl_certificate /etc/letsencrypt/live/try.purescript.org/fullchain.pem; + ssl_trusted_certificate /etc/letsencrypt/live/try.purescript.org/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/try.purescript.org/privkey.pem; + ssl_session_timeout 1d; + ssl_session_cache shared:ssl:10m; + ssl_session_tickets off; + ssl_stapling on; + ssl_stapling_verify on; + ssl_dhparam /etc/nginx/ssl_dhparam; + ssl_protocols TLSv1.2 TLSv1.3; + 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; + ssl_prefer_server_ciphers off; + + # HSTS + # Maybe enable this later + # Low max-age to start with, just in case + # add_header Strict-Transport-Security "max-age=60" always; + + # + # compile.purescript.org specific things + # + + location / { + proxy_pass http://127.0.0.1:8081; + } +} diff --git a/deploy/start b/deploy/start new file mode 100644 index 00000000..6b8f3861 --- /dev/null +++ b/deploy/start @@ -0,0 +1,3 @@ +#! /usr/bin/env/bash + +exec trypurescript +RTS -N1 -A128m -M750M -RTS 8081 $(spago sources) diff --git a/deploy/trypurescript.service b/deploy/trypurescript.service new file mode 100644 index 00000000..cc4ba004 --- /dev/null +++ b/deploy/trypurescript.service @@ -0,0 +1,13 @@ +[Unit] +Description=Web service for Try PureScript + +[Service] +Type=simple +User=www-data +ExecStart=/var/www/trypurescript/deploy/start +WorkingDirectory=/var/www/trypurescript/staging +Restart=always +RestartSec=5s + +[Install] +WantedBy=multi-user.target