Files
deployer/deploy.sh
2025-08-03 11:54:52 -04:00

81 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
echo "starting build $DEPLOYMENT_ID from $USER/$REPO:$BRANCH ($COMMIT_HASH)"
echo $DEPLOYMENT_ID > metadata.txt
cd $DOMAIN_DIR
rm -f $DOMAIN_DIR/build.log
ln -s $LOGS_DIR/build.log $DOMAIN_DIR/build.log
rm -f $DOMAIN_DIR/start.log
# Create our service configuration
service_file=$DOMAIN.service
echo "
[Unit]
Description=Deployment of $DOMAIN (on port $PORT, from $REPO/$BRANCH:$COMMIT_HASH) [$DEPLOYMENT_ID]
After=network.target
[Service]
Type=simple
Environment="PORT=$PORT"
ExecStart=make start
User=drm
WorkingDirectory=$DOMAIN_DIR/src
Restart=no
StandardOutput=file:$LOGS_DIR/start.log
StandardError=file:$LOGS_DIR/start.log
[Install]
WantedBy=multi-user.target
" > $service_file
echo -e "SHELL := /bin/bash
id:
\techo $DEPLOYMENT_ID
status:
\tsystemctl status deployer-$DOMAIN
log:
\tjournalctl -u deployer-$DOMAIN
cleanlogs:
\trm -rf $DOMAIN_DIR/logs/*
buildlog:
\tless +F build.log
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
echo build complete!
cd ..
service="deployer-$DOMAIN.service"
ln -sf $DOMAIN_DIR/$service_file /etc/systemd/system/$service
systemctl daemon-reload
systemctl restart $service
ln -s $LOGS_DIR/start.log $DOMAIN_DIR/start.log