Files
deployer/deploy.sh
2025-07-30 21:40:29 -04:00

50 lines
991 B
Bash
Executable File

#!/bin/bash
cd $DEPLOYMENT_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=make start
User=drm
WorkingDirectory=$DEPLOYMENT_DIR/src
Restart=on-failure
StandardOutput=file:$DEPLOYMENT_DIR/start.log
StandardError=file:$DEPLOYMENT_DIR/start.log
[Install]
WantedBy=multi-user.target
" > $service_file
# 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 $DEPLOYMENT_DIR/$service_file /etc/systemd/system/$service
systemctl daemon-reload
systemctl restart $service