Files
deployer/deploy.sh
2025-07-30 22:08:51 -04:00

63 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
cd $DOMAIN_DIR
# Create our service configuration
service_file=$DOMAIN.service
echo "
[Unit]
Description=Deployment of $DOMAIN (on port $PORT, from $REPO/$BRANCH:$COMMIT_HASH)
After=network.target
[Service]
Type=simple
Environment="PORT=$PORT"
ExecStart=make start
User=drm
WorkingDirectory=$DOMAIN_DIR/src
Restart=on-failure
StandardOutput=file:$LOGS_DIR/start.log
StandardError=file:$LOGS_DIR/start.log
[Install]
WantedBy=multi-user.target
" > $service_file
echo -e "SHELL := /bin/bash
status:
\tsystemctl status deployer-$DOMAIN
logs:
\tjournalctl -u deployer-$DOMAIN
stop:
\tsystemctl stop deployer-$DOMAIN
" > Makefile
# create a folder to put the source code
mkdir -p src
# put the source code in that folder
gitea=localhost:3000
git clone \
-b $BRANCH \
"http://deployer:$(cat /home/drm/deployer/token)@$gitea/$USER/$REPO" \
./src
cd src
git fetch origin $BRANCH
git reset --hard origin/$BRANCH
git checkout $COMMIT_HASH
# build the dist artifact from within the src directory
make build
cd ..
service="deployer-$DOMAIN.service"
ln -sf $DOMAIN_DIR/$service_file /etc/systemd/system/$service
systemctl daemon-reload
systemctl restart $service