added scripts
This commit is contained in:
parent
1526756e15
commit
1281e5335a
|
@ -3,6 +3,7 @@ version: '3' # Specify a Docker Compose file version
|
||||||
services:
|
services:
|
||||||
site: # Name of your service
|
site: # Name of your service
|
||||||
build: . # Path to your Dockerfile (assumes it's in the same directory)
|
build: . # Path to your Dockerfile (assumes it's in the same directory)
|
||||||
|
container_name: site
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "3004:8080" # Map external port 3000 to internal port 8080
|
- "3004:8080" # Map external port 3000 to internal port 8080
|
||||||
|
|
23
scripts/check.sh
Normal file
23
scripts/check.sh
Normal 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
21
scripts/deploy.sh
Normal 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
|
Loading…
Reference in a new issue