Skip to content

Commit 9b7f811

Browse files
committed
add deploy to new server
1 parent d258c5d commit 9b7f811

File tree

6 files changed

+162
-0
lines changed

6 files changed

+162
-0
lines changed

deploy/51.210.222.18/Caddyfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
web.omnipackage.org {
2+
file_server
3+
root public/
4+
@notStatic {
5+
not file
6+
}
7+
reverse_proxy @notStatic 127.0.0.1:30000
8+
encode zstd gzip
9+
}
10+
11+
#https://storage.omnipackage.org:9002 {
12+
# reverse_proxy 127.0.0.1:9001
13+
#}
14+
15+
#https://storage.omnipackage.org {
16+
# reverse_proxy 127.0.0.1:9000
17+
#}

deploy/51.210.222.18/caddy.service

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=OmniPackage web Caddy
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
WorkingDirectory=/home/debian/omnipackage-web
8+
Environment=HOME=/root
9+
ExecStart=caddy run --config deploy/51.210.222.18/Caddyfile
10+
11+
RestartSec=1
12+
Restart=on-failure
13+
14+
[Install]
15+
WantedBy=multi-user.target

deploy/51.210.222.18/deploy.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
3+
HOST="51.210.222.18"
4+
USER="debian"
5+
DIR="/home/$USER/omnipackage-web"
6+
BRANCH=`git branch --show-current`
7+
8+
SKIP_CADDY=0
9+
SKIP_SIDEKIQ=0
10+
11+
POSITIONAL_ARGS=()
12+
while [[ $# -gt 0 ]]; do
13+
case $1 in
14+
-c|--console)
15+
ssh -t $USER@$HOST "bash -lic 'cd $DIR && bin/rails c -e production'"
16+
exit $?
17+
;;
18+
-s|--shell)
19+
ssh -t $USER@$HOST "cd $DIR && RAILS_ENV=production bash -li"
20+
exit $?
21+
shift
22+
;;
23+
--skip-caddy)
24+
SKIP_CADDY=1
25+
shift
26+
;;
27+
--skip-sidekiq)
28+
SKIP_SIDEKIQ=1
29+
shift
30+
;;
31+
-*|--*)
32+
echo "Unknown option $1"
33+
exit 1
34+
;;
35+
*)
36+
POSITIONAL_ARGS+=("$1") # save positional arg
37+
shift # past argument
38+
;;
39+
esac
40+
done
41+
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
42+
43+
ssh -T $USER@$HOST <<EOL
44+
set -xEeuo pipefail
45+
cd ~/.rbenv/ && git pull && cd ~/.rbenv/plugins/ruby-build/ && git pull
46+
cd $DIR
47+
git checkout $BRANCH
48+
git pull
49+
50+
export RAILS_ENV=production
51+
rbenv install --skip-existing
52+
bundle config --local without development test
53+
bundle config set deployment true
54+
# bundle config build.pg --with-pg-include=/usr/pgsql-16/include/ --with-pg-lib=/usr/pgsql-16/lib/
55+
56+
bin/bundle install
57+
bin/rails assets:clean
58+
bin/rails assets:precompile
59+
bin/rails db:migrate
60+
61+
sudo systemctl daemon-reload
62+
if (( $SKIP_SIDEKIQ == 0 )); then
63+
sudo systemctl restart sidekiq@default
64+
sudo systemctl restart sidekiq@long
65+
sudo systemctl restart sidekiq@publish
66+
fi
67+
if (( $SKIP_CADDY == 0 )); then
68+
sudo systemctl restart caddy
69+
fi
70+
sudo systemctl restart puma
71+
EOL
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[Unit]
2+
Description=OmniPackage embedded agents
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
Environment=RAILS_ENV=production
8+
Environment=RAILS_LOG_TO_STDOUT=1
9+
Environment=EMBEDDED_AGENTS_APIHOST=http://localhost:30000
10+
WorkingDirectory=/home/debian/omnipackage-web
11+
ExecStart=/bin/bash -lci 'bundle exec rails embedded_agents:run'
12+
13+
User=debian
14+
Group=debian
15+
UMask=0002
16+
RestartSec=1
17+
Restart=on-failure
18+
19+
[Install]
20+
WantedBy=multi-user.target

deploy/51.210.222.18/puma.service

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[Unit]
2+
Description=OmniPackage web Puma
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
Environment=RAILS_ENV=production
8+
Environment=RAILS_LOG_TO_STDOUT=1
9+
WorkingDirectory=/home/debian/omnipackage-web
10+
ExecStart=/bin/bash -lci 'bundle exec puma -C config/puma/production.rb'
11+
12+
User=debian
13+
Group=debian
14+
UMask=0002
15+
RestartSec=1
16+
Restart=on-failure
17+
18+
[Install]
19+
WantedBy=multi-user.target
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[Unit]
2+
Description=OmniPackage web Sidekiq %i
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
Environment=RAILS_ENV=production
8+
Environment=RAILS_LOG_TO_STDOUT=1
9+
WorkingDirectory=/home/debian/omnipackage-web
10+
ExecStart=/bin/bash -lci 'bundle exec sidekiq -C config/sidekiq/%i.yml -t 30'
11+
12+
User=debian
13+
Group=debian
14+
UMask=0002
15+
RestartSec=1
16+
Restart=on-failure
17+
TimeoutStopSec=31
18+
19+
[Install]
20+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)