11#! /bin/sh
2- # This script is run without arguments, in the deployment user's home directory.
3- # This is a modified version of https://github.com/SwanX1/cernavskis.dev/blob/main/deploy.sh
4- # It does not have administrative privileges.
52
63SERVICE_NAME=" webapp"
7- SERVICE_USER=" github"
8- GIT_REMOTE=" https://github.com/infernalstudios.org.git"
94GIT_BRANCH=" stable"
105
11- # Check if the script is run as root
126if [ " $( id -u) " -eq 0 ]; then
137 echo " This script must not be run as root."
148 exit 1
159fi
1610
17- # Check if bun is installed
18- if [ -z $( command -v yarn) ]; then
19- echo " yarn is not installed. Please install it first."
20- exit 1
21- fi
22-
23- # Check if screen is installed
24- if [ -z $( command -v screen) ]; then
25- echo " screen is not installed. Please install it first."
26- exit 1
27- fi
28-
29- echo " Running as $( whoami) in $( pwd) ."
30-
3111# Find service path
3212if [ ! -f " $( pwd) /.service_paths" ]; then
3313 echo " Did you initialize the service using server-init.sh?: .service_paths not found."
3616
3717SERVICE_PATH=$( cat $( pwd) /.service_paths | grep $SERVICE_NAME | cut -d' ' -f2)
3818
39- if [ -z " $SERVICE_PATH " ]; then
40- echo " Did you initialize the service using server-init.sh?: Service path not found in .service_paths."
41- exit 1
42- fi
43-
44- if [ ! -d " $SERVICE_PATH " ]; then
45- echo " Did you initialize the service using server-init.sh?: Service path does not exist."
19+ if [ -z " $SERVICE_PATH " ] || [ ! -d " $SERVICE_PATH " ]; then
20+ echo " Service path invalid or missing."
4621 exit 1
4722fi
4823
4924cd $SERVICE_PATH
5025
51- # Checkout the latest commit on GIT_BRANCH
26+ # Checkout the latest commit
5227git fetch origin -v
53- if [ " $! " -ne 0 ]; then
54- echo " Failed to fetch."
55- exit 1
56- fi
5728git checkout origin/$GIT_BRANCH
58- if [ " $! " -ne 0 ]; then
59- echo " Failed to checkout the latest commit."
60- exit 1
61- fi
6229
63- # Install the dependencies
64- yarn install --frozen-lockfile --non-interactive --verbose
30+ # Use Docker Compose
31+ echo " Building and starting Docker containers..."
32+ docker compose up -d --build
6533
66- if [ " $! " -ne 0 ]; then
67- echo " Failed to install the dependencies ."
34+ if [ " $? " -ne 0 ]; then
35+ echo " Docker compose failed to start the service ."
6836 exit 1
6937fi
7038
71- # We use build:only here, because we don't want to run any checks beforehand. Those are handled by GH Actions.
72- yarn build:only
73-
74- if [ " $! " -ne 0 ]; then
75- echo " Failed to build, this should be unreachable."
76- echo " Ignoring this, since tsc and webpack transpiles everything regardless of errors."
77- echo " This should have been caught by GH Actions."
78- fi
79-
80- if [ ! -z " $( screen -ls $SERVICE_NAME | grep $SERVICE_NAME ) " ]; then
81- echo " Service is already running, stopping it."
82- screen -S $SERVICE_NAME -X quit
83- if [ " $! " -ne 0 ]; then
84- echo " Failed to stop the service."
85- exit 1
86- fi
87- fi
88-
89- echo " Starting the service."
90- screen -dmqS $SERVICE_NAME yarn start
91-
92- if [ " $! " -ne 0 ]; then
93- echo " Failed to start the service."
94- exit 1
95- fi
39+ echo " Deployment successful."
40+ docker image prune -f
0 commit comments