added scripts

This commit is contained in:
Ulysia 2024-05-01 20:26:57 +02:00
parent 1526756e15
commit 1281e5335a
3 changed files with 45 additions and 0 deletions

View file

@ -3,6 +3,7 @@ version: '3' # Specify a Docker Compose file version
services:
site: # Name of your service
build: . # Path to your Dockerfile (assumes it's in the same directory)
container_name: site
restart: unless-stopped
ports:
- "3004:8080" # Map external port 3000 to internal port 8080

23
scripts/check.sh Normal file
View file

@ -0,0 +1,23 @@
#!/bin/bash
echo "$(date --utc +%FT%TZ): Fetching remote repository..."
git fetch
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")
if [ $LOCAL = $REMOTE]; then
echo "$(date --utc +%FT%TZ): No change detected in git"
elif [ $LOCAL = $BASE ]; then
BUILD_VERSION=$(git rev-parse HEAD)
echo "$(date --utc +%FT%TZ): Changes detected, deploying new version: $BUILD_VERSION"
./scripts/deploy.sh
elif [$REMOTE = $BASE]; then
echo "$(date --utc +%FT%TZ): Local changes detected, stashing"
git stash
./scripts/deploy.sh
else
echo "$(date --utc +%FT%TZ): Git is diverged, this is unexpected."
fi

21
scripts/deploy.sh Normal file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
git pull
BUILD_VERSION=$(git rev-parse HEAD)
echo "$(date --utc +%FT%TZ): Releasing new server version. $BUILD_VERSION"
echo "$(date --utc +%FT%TZ): Running build..."
docker compose rm -f
docker compose build
OLD_CONTAINER=$(dockerps -aqf "name=site")
echo "$(date --utc +%FT%TZ): Scaling server up..."
BUILD_VERSION=$BUILD_VERSION docker compose up -d --no-deps --scale site=2 --no-recreate site
sleep 30
echo "$(date --utc +%FT%TZ): Scaling old server down..."
docker container rm -f $OLD_CONTAINER
docker compose up -d --no-deps --scale site=1 --no-recreate site