diff --git a/.circleci/config.yml b/.circleci/config.yml index 92ad620..c4e90f3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,13 +2,11 @@ version: 2 jobs: build_and_deploy: docker: - - image: docker:18.09 + - image: alpine steps: - checkout - - setup_remote_docker - - run: apk add --no-cache --no-progress bash curl make nodejs - - run: curl https://cli-assets.heroku.com/install.sh | sh - - run: make deploy + - run: apk add --no-cache --no-progress bash openssh + - run: scripts/deploy.bash workflows: version: 2 ci: diff --git a/frontend/pages/index.ejs b/frontend/pages/index.ejs index e5a2544..e32c189 100644 --- a/frontend/pages/index.ejs +++ b/frontend/pages/index.ejs @@ -6,7 +6,7 @@ -

Riju: online playground for every programming language

+

Riju: fast online playground for every programming language

Pick your favorite language to get started:
<% for (const [id, {name}] of Object.entries(langs)) { %> diff --git a/scripts/certbot-post.bash b/scripts/certbot-post.bash new file mode 100755 index 0000000..a151447 --- /dev/null +++ b/scripts/certbot-post.bash @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e +set -o pipefail + +systemctl start riju diff --git a/scripts/certbot-post.sh b/scripts/certbot-post.sh deleted file mode 100755 index 85c2533..0000000 --- a/scripts/certbot-post.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -systemctl start riju diff --git a/scripts/certbot-pre.bash b/scripts/certbot-pre.bash new file mode 100755 index 0000000..5bd2098 --- /dev/null +++ b/scripts/certbot-pre.bash @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e +set -o pipefail + +systemctl stop riju diff --git a/scripts/certbot-pre.sh b/scripts/certbot-pre.sh deleted file mode 100755 index fdc7e0e..0000000 --- a/scripts/certbot-pre.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -systemctl stop riju diff --git a/scripts/deploy.bash b/scripts/deploy.bash new file mode 100755 index 0000000..2011095 --- /dev/null +++ b/scripts/deploy.bash @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e +set -o pipefail + +tmpdir="$(mktemp -d)" +keyfile="${tmpdir}/id" + +if [[ -n "$DEPLOY_KEY" ]]; then + printf '%s\n' "$DEPLOY_KEY" | base64 -d > "$keyfile" +elif [[ -f "$HOME/.ssh/id_rsa_riju_deploy" ]]; then + cp "$HOME/.ssh/id_rsa_riju_deploy" "$keyfile" +else + echo 'deploy.bash: you must set $DEPLOY_KEY' >&2 + exit 1 +fi + +ssh -o IdentitiesOnly=yes -i "${keyfile}" deploy@209.141.54.122 /usr/bin/riju-install diff --git a/scripts/docker-install-phase6.bash b/scripts/docker-install-phase6.bash old mode 100644 new mode 100755 diff --git a/scripts/install.py b/scripts/install.py new file mode 100755 index 0000000..e776d5d --- /dev/null +++ b/scripts/install.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +import argparse +import errno +import os +import re +import signal +import subprocess +import sys +import tempfile +import time + +for pid in ( + subprocess.run(["pgrep", "-x", "riju-install"], check=True, stdout=subprocess.PIPE) + .stdout.decode() + .splitlines() +): + print(f"Found existing process {pid}, trying to kill ...", file=sys.stderr) + pid = int(pid) + os.kill(pid, signal.SIGTERM) + while True: + time.sleep(0.01) + try: + os.kill(pid, 0) + except OSError as e: + if e.errno == errno.ESRCH: + break + +with tempfile.TemporaryDirectory() as tmpdir: + os.chdir(tmpdir.name) + subprocess.run( + [ + "git", + "clone", + "https://github.com/raxod502/riju.git", + "--single-branch", + "--depth=1", + "--no-tags", + ], + check=True, + ) + os.chdir("riju") + subprocess.run(["make", "image-prod"], check=True) + subprocess.run(["docker", "system", "prune", "-f"], check=True) + subprocess.run(["systemctl", "restart", "riju"], check=True) diff --git a/scripts/riju.service b/scripts/riju.service index 67fe9ab..3ba25a9 100644 --- a/scripts/riju.service +++ b/scripts/riju.service @@ -2,7 +2,7 @@ Description=Riju online coding sandbox [Service] -ExecStart=docker run -p 0.0.0.0:6119 riju +ExecStart=docker run --rm -p 0.0.0.0:80:6119 riju:prod [Install] WantedBy=multi-user.target