|
| 1 | +exit # this isn't quite a script; some parts are interactive. |
| 2 | + |
| 3 | +### Register Github App |
| 4 | +# https://github.com/bors-ng/bors-ng#step-1-register-a-new-github-app |
| 5 | +# Dashboard URL: https://hijinks.mit.edu:4002/ |
| 6 | +# Generate and download a private key (.pem file) |
| 7 | + |
| 8 | + |
| 9 | +### Install dependencies |
| 10 | + |
| 11 | +wget -q -O - https://packages.erlang-solutions.com/debian/erlang_solutions.asc | apt-key add - |
| 12 | +echo 'deb https://packages.erlang-solutions.com/debian stretch contrib' >/etc/apt/sources.list.d/erlang-solutions.list |
| 13 | + |
| 14 | +wget -q -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - |
| 15 | +echo 'deb https://deb.nodesource.com/node_13.x stretch main' >/etc/apt/sources.list.d/nodesource.list |
| 16 | + |
| 17 | +apt-get update |
| 18 | +apt-get install esl-erlang elixir postgresql nodejs |
| 19 | + |
| 20 | + |
| 21 | +# use this command to generate random secrets when called for: |
| 22 | +# </dev/urandom tr -dc 'a-zA-Z0-9' | head -c64 |
| 23 | + |
| 24 | +### User |
| 25 | +useradd -m -U borsng |
| 26 | + |
| 27 | + |
| 28 | +### Database |
| 29 | +sudo -u postgres createuser -P borsng # generate a random db password |
| 30 | +sudo -u postgres createdb -O borsng borsng |
| 31 | +sudo -u postgres psql -d borsng <<<"CREATE EXTENSION IF NOT EXISTS citext;" |
| 32 | + |
| 33 | + |
| 34 | +### Nginx configuration: requires existing nginx+certbot setup from jenkins-setup.txt |
| 35 | +# Add this location block to /etc/nginx/sites-available/hijinks |
| 36 | +cat <<EOF |
| 37 | +server { |
| 38 | + listen 4002 ssl; |
| 39 | + server_name hijinks.mit.edu; |
| 40 | + |
| 41 | + # copied from jenkins' server block: |
| 42 | + ssl_certificate /etc/letsencrypt/live/hijinks.mit.edu/fullchain.pem; |
| 43 | + ssl_certificate_key /etc/letsencrypt/live/hijinks.mit.edu/privkey.pem; |
| 44 | + include /etc/letsencrypt/options-ssl-nginx.conf; |
| 45 | + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; |
| 46 | + |
| 47 | + ssl_trusted_certificate /etc/letsencrypt/live/hijinks.mit.edu/chain.pem; |
| 48 | + ssl_stapling on; |
| 49 | + ssl_stapling_verify on; |
| 50 | + add_header Strict-Transport-Security "max-age=31536000" always; |
| 51 | + |
| 52 | + location / { |
| 53 | + include /etc/nginx/proxy_params; |
| 54 | + proxy_pass http://localhost:4001/; |
| 55 | + proxy_redirect default; |
| 56 | + } |
| 57 | +} |
| 58 | +EOF |
| 59 | + |
| 60 | +### Systemd configuration |
| 61 | +cat <<EOF >borsng.service |
| 62 | +[Unit] |
| 63 | +Description=Bors-NG |
| 64 | +After=network.target |
| 65 | + |
| 66 | +[Service] |
| 67 | +Type=simple |
| 68 | +User=borsng |
| 69 | +WorkingDirectory=/home/borsng/bors-ng |
| 70 | +EnvironmentFile=/home/borsng/bors-env |
| 71 | +Restart=on-failure |
| 72 | +ExecStart=/home/borsng/bors-ng/_build/prod/rel/bors/bin/bors start |
| 73 | +ExecStop=/home/borsng/bors-ng/_build/prod/rel/bors/bin/bors stop |
| 74 | + |
| 75 | +[Install] |
| 76 | +WantedBy=multi-user.target |
| 77 | +EOF |
| 78 | +ln -s "$(realpath borsng.service)" /etc/systemd/system |
| 79 | +systemctl enable borsng |
| 80 | + |
| 81 | + |
| 82 | +sudo -iu borsng # run all remaining commands as borsng |
| 83 | +umask go= |
| 84 | + |
| 85 | +git clone https://github.com/bors-ng/bors-ng.git |
| 86 | + |
| 87 | +cd bors-ng |
| 88 | +mix local.hex --force |
| 89 | +mix deps.get --only prod |
| 90 | +mix local.rebar --force |
| 91 | + |
| 92 | +pushd assets |
| 93 | +npm install |
| 94 | +popd |
| 95 | +npm run deploy --prefix ./assets |
| 96 | +MIX_ENV=prod mix phx.digest |
| 97 | + |
| 98 | +MIX_ENV=prod mix compile |
| 99 | +MIX_ENV=prod mix release |
| 100 | + |
| 101 | + |
| 102 | +cat >~/bors-env <<EOF |
| 103 | +PORT=4001 |
| 104 | +MIX_ENV=prod |
| 105 | +SECRET_KEY_BASE=??? # generate this randomly |
| 106 | +DATABASE_URL='ecto://borsng:<db password>@localhost/borsng' # password from earlier |
| 107 | +GITHUB_INTEGRATION_ID=??? # App id in github |
| 108 | +GITHUB_WEBHOOK_SECRET=??? # generate this randomly and input it to github |
| 109 | +GITHUB_CLIENT_ID=??? # from github |
| 110 | +GITHUB_CLIENT_SECRET=??? # from github |
| 111 | +PUBLIC_HOST=localhost |
| 112 | +EOF |
| 113 | +echo "GITHUB_INTEGRATION_PEM='$(base64 -w0 /path/to/file.private-key.pem)'" >>~bors-env # private key from github |
| 114 | + |
| 115 | +sh -ac '. ~/bors-env && POOL_SIZE=1 mix ecto.migrate' |
0 commit comments