Skip to content

Commit

Permalink
Dev server deploy script (#2228)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph authored Jun 30, 2023
1 parent 594c14f commit edbcb8e
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 38 deletions.
21 changes: 0 additions & 21 deletions bin/update-ord-dev

This file was deleted.

34 changes: 34 additions & 0 deletions deploy/deploy-ord-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
set -euxo pipefail

# This script deploys whatever is currently
# in working directory to our dev server
DOMAIN="ordinals-dev.com"

# Current local working state
BRANCH=$(git rev-parse --abbrev-ref HEAD)
COMMIT=$(git rev-parse --short HEAD)
DIR="ord-${BRANCH}-${COMMIT}"

# Edit service file if you want
$EDITOR ./deploy/ord-dev.service

# Create own directory for every deploy
ssh root@${DOMAIN} "mkdir -p /var/lib/ord/${DIR}/repo"
rsync -avz --exclude-from='.gitignore' --exclude ".git" --exclude "*.redb" ./ root@${DOMAIN}:/var/lib/ord/${DIR}/repo

# Store deployment info in environmental variables
ssh root@${DOMAIN} "echo 'BRANCH=${BRANCH}' >> /etc/environment \
&& echo 'COMMIT=${COMMIT}' >> /etc/environment \
&& echo 'DIR=${DIR}' >> /etc/environment"

# Deploy
ssh root@${DOMAIN} "cd /var/lib/ord/${DIR}/repo \
&& /root/.cargo/bin/cargo build --release \
&& systemctl stop ord-dev \
&& cp ./target/release/ord /usr/local/bin/ord \
&& cp /var/lib/ord/${DIR}/repo/deploy/ord-dev.service /etc/systemd/system/ \
&& systemctl daemon-reload \
&& systemctl enable ord-dev \
&& systemctl restart ord-dev \
&& systemctl status ord-dev"
19 changes: 12 additions & 7 deletions deploy/ord-dev.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ StartLimitIntervalSec=10m
AmbientCapabilities=CAP_NET_BIND_SERVICE
Environment=RUST_BACKTRACE=1
Environment=RUST_LOG=info
ExecStart=/usr/local/bin/ord-dev \
ExecStart=/usr/local/bin/ord \
--bitcoin-data-dir /var/lib/bitcoind \
--chain ${CHAIN} \
--data-dir /var/lib/ord-dev \
--index-sats \
--data-dir /var/lib/ord \
# --index-sats \
server \
--http-port 8080
--acme-contact mailto:[email protected] \
--http \
--https
Group=ord
LimitNOFILE=65536
MemoryDenyWriteExecute=true
NoNewPrivileges=true
PrivateDevices=true
Expand All @@ -24,9 +26,12 @@ ProtectHome=true
ProtectSystem=full
Restart=on-failure
RestartSec=5s
StateDirectory=ord-dev
StateDirectory=ord
StateDirectoryMode=0700
TimeoutStopSec=10m
Type=simple
User=ord
WorkingDirectory=/var/lib/ord-dev
WorkingDirectory=/var/lib/ord

[Install]
WantedBy=multi-user.target
17 changes: 17 additions & 0 deletions deploy/save-ord-dev-state
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail

# Stops, copies index and exports state of running instance
systemctl stop ord-dev

cd /var/lib/ord

# Still have to manually set --index-sats or --height-limit
/usr/local/bin/ord --bitcoin-data-dir /var/lib/bitcoind \
--data-dir /var/lib/ord \
index export

mv inscription_number_to_id.tsv ./${DIR}/inscription_number_to_id-${BRANCH}-${COMMIT}.tsv

mv index.redb ./${DIR}/index-${BRANCH}-${COMMIT}.redb

17 changes: 7 additions & 10 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ deploy-signet branch="master": (deploy branch "signet" "signet.ordinals.net")

deploy-testnet branch="master": (deploy branch "test" "testnet.ordinals.net")

ord-dev-save-state domain="ordinals-dev.com":
scp ./deploy/save-ord-dev-state root@{{domain}}:~
ssh root@{{domain}} "./save-ord-dev-state"

ord-dev-deploy:
./deploy/deploy-ord-dev

log unit="ord" domain="ordinals.net":
ssh root@{{domain}} 'journalctl -fu {{unit}}'

Expand Down Expand Up @@ -69,16 +76,6 @@ open:
doc:
cargo doc --all --open

update-ord-dev:
./bin/update-ord-dev

rebuild-ord-dev-database: && update-ord-dev
systemctl stop ord-dev
rm -f /var/lib/ord-dev/index.redb
rm -f /var/lib/ord-dev/*/index.redb
journalctl --unit ord-dev --rotate
journalctl --unit ord-dev --vacuum-time 1s

prepare-release revision='master':
#!/usr/bin/env bash
set -euxo pipefail
Expand Down

0 comments on commit edbcb8e

Please sign in to comment.