-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add VPS baseline provisioning assets #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| server { | ||
| listen 80; | ||
| server_name api.drdnt.org; | ||
|
|
||
| location / { | ||
| proxy_pass http://127.0.0.1:3001; | ||
| proxy_http_version 1.1; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| server { | ||
| listen 80; | ||
| server_name bot.drdnt.org; | ||
|
|
||
| # Placeholder upstream until station-bot is deployed on the VPS. | ||
| location / { | ||
| proxy_pass http://127.0.0.1:3999; | ||
| proxy_http_version 1.1; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| server { | ||
| listen 80; | ||
| server_name station.drdnt.org; | ||
|
|
||
| location / { | ||
| proxy_pass http://127.0.0.1:3000; | ||
| proxy_http_version 1.1; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| if [ "$(id -u)" -ne 0 ]; then | ||
| echo "Run this script as root." | ||
| exit 1 | ||
| fi | ||
|
|
||
| DEPLOY_USER="deploy" | ||
| DEPLOY_HOME="/home/${DEPLOY_USER}" | ||
| STATION_ROOT="/opt/station" | ||
|
|
||
| apt update | ||
| apt upgrade -y | ||
|
|
||
| apt install -y ca-certificates curl gnupg lsb-release | ||
|
|
||
| install -m 0755 -d /etc/apt/keyrings | ||
| if [ ! -f /etc/apt/keyrings/docker.asc ]; then | ||
| curl -fsSL https://download.docker.com/linux/ubuntu/gpg \ | ||
| | gpg --dearmor -o /etc/apt/keyrings/docker.asc | ||
| chmod a+r /etc/apt/keyrings/docker.asc | ||
| fi | ||
|
|
||
| ARCH="$(dpkg --print-architecture)" | ||
| CODENAME="$(. /etc/os-release && echo "${VERSION_CODENAME}")" | ||
| echo \ | ||
| "deb [arch=${ARCH} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu ${CODENAME} stable" \ | ||
| > /etc/apt/sources.list.d/docker.list | ||
|
|
||
| apt update | ||
| apt install -y \ | ||
| docker-ce \ | ||
| docker-ce-cli \ | ||
| containerd.io \ | ||
| docker-buildx-plugin \ | ||
| docker-compose-plugin \ | ||
| nginx \ | ||
| certbot \ | ||
| python3-certbot-nginx | ||
|
|
||
| systemctl enable --now docker | ||
| systemctl enable --now nginx | ||
|
|
||
| if ! id -u "${DEPLOY_USER}" >/dev/null 2>&1; then | ||
| useradd -m -s /bin/bash "${DEPLOY_USER}" | ||
| fi | ||
|
|
||
| usermod -aG docker "${DEPLOY_USER}" | ||
|
|
||
| install -d -m 700 -o "${DEPLOY_USER}" -g "${DEPLOY_USER}" "${DEPLOY_HOME}/.ssh" | ||
| touch "${DEPLOY_HOME}/.ssh/authorized_keys" | ||
| chmod 600 "${DEPLOY_HOME}/.ssh/authorized_keys" | ||
| chown "${DEPLOY_USER}:${DEPLOY_USER}" "${DEPLOY_HOME}/.ssh/authorized_keys" | ||
|
|
||
| if [ -n "${DEPLOY_SSH_PUBLIC_KEY:-}" ]; then | ||
| if ! grep -Fqx "${DEPLOY_SSH_PUBLIC_KEY}" "${DEPLOY_HOME}/.ssh/authorized_keys"; then | ||
| echo "${DEPLOY_SSH_PUBLIC_KEY}" >> "${DEPLOY_HOME}/.ssh/authorized_keys" | ||
| chown "${DEPLOY_USER}:${DEPLOY_USER}" "${DEPLOY_HOME}/.ssh/authorized_keys" | ||
| fi | ||
| else | ||
| echo "DEPLOY_SSH_PUBLIC_KEY is not set. Add the deploy key to ${DEPLOY_HOME}/.ssh/authorized_keys manually." | ||
| fi | ||
|
|
||
| install -d -m 755 -o "${DEPLOY_USER}" -g "${DEPLOY_USER}" "${STATION_ROOT}" | ||
| install -d -m 755 -o "${DEPLOY_USER}" -g "${DEPLOY_USER}" "${STATION_ROOT}/logs" | ||
|
|
||
| bash "$(dirname "$0")/setup-swap.sh" | ||
|
|
||
| echo | ||
| echo "Bootstrap complete." | ||
| echo "- Install Nginx configs from infra/nginx/ into /etc/nginx/sites-available/" | ||
| echo "- Enable the sites and reload Nginx." | ||
| echo "- Run infra/scripts/issue-certs.sh once DNS is live." | ||
| echo "- Confirm the deploy user can SSH and run Docker commands without sudo." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| if [ "$(id -u)" -ne 0 ]; then | ||
| echo "Run this script as root." | ||
| exit 1 | ||
| fi | ||
|
|
||
| certbot --nginx \ | ||
| -d api.drdnt.org \ | ||
| -d station.drdnt.org \ | ||
| -d bot.drdnt.org | ||
|
|
||
| certbot renew --dry-run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| if [ "$(id -u)" -ne 0 ]; then | ||
| echo "Run this script as root." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if swapon --show | grep -q '^/swapfile'; then | ||
| echo "/swapfile is already active." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [ ! -f /swapfile ]; then | ||
| fallocate -l 2G /swapfile | ||
| chmod 600 /swapfile | ||
| fi | ||
|
|
||
| if ! blkid -o value -s TYPE /swapfile 2>/dev/null | grep -qx 'swap'; then | ||
| mkswap /swapfile | ||
| fi | ||
|
|
||
| swapon /swapfile | ||
|
|
||
| if ! grep -q '^/swapfile none swap sw 0 0$' /etc/fstab; then | ||
| echo '/swapfile none swap sw 0 0' >> /etc/fstab | ||
| fi | ||
|
|
||
| echo "Swap is active:" | ||
| swapon --show | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.