Files
deployer/deploy.sh
2025-07-30 21:57:31 -04:00

64 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
cd $DOMAIN_DIR
# Create our service configuration
service_file=$DOMAIN.service
echo "
[Unit]
Description=Deployment of $DOMAIN (from $REPO/$BRANCH)
After=network.target
[Service]
Type=simple
ExecStart='PORT=$PORT 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 "
SHELL := /bin/bash
status:
systemctl status deployer-$DOMAIN
logs:
journalctl -u deployer-$DOMAIN
stop
systemctl 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