This commit is contained in:
2025-07-30 21:40:29 -04:00
parent 048333b0ec
commit 93954f3190
3 changed files with 64 additions and 36 deletions

View File

@@ -1,42 +1,47 @@
#!/bin/bash
deploydir=$DEPLOYERDIR/$REPO/$BRANCH
cd $DEPLOYMENT_DIR
mkdir -p $deploydir/src
cd $deploydir
# 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)@localhost:3000/$USER/$REPO" \
"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 ..
echo "
[Unit]
Description=Deployment of $REPO/$BRANCH
After=network.target
[Service]
Type=simple
ExecStart=make deploy
User=drm
WorkingDirectory=$deploydir/src
Restart=on-failure
StandardOutput=file:$deploydir/server.log
StandardError=file:$deploydir/server.log
[Install]
WantedBy=multi-user.target
" > deploy.service
service="deployer-$REPO-$BRANCH.service"
ln -sf $deploydir/deploy.service /etc/systemd/system/$service
service="deployer-$DOMAIN.service"
ln -sf $DEPLOYMENT_DIR/$service_file /etc/systemd/system/$service
systemctl daemon-reload
systemctl restart $service