env infra: improve restart script
This commit is contained in:
parent
62eb507a5e
commit
6313d457b5
2
environments/infra/Jenkinsfile
vendored
2
environments/infra/Jenkinsfile
vendored
@ -6,6 +6,8 @@ pipeline {
|
|||||||
stage('Restart') {
|
stage('Restart') {
|
||||||
steps {
|
steps {
|
||||||
sshPublisher(publishers: [sshPublisherDesc(configName: 'infra.1', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''
|
sshPublisher(publishers: [sshPublisherDesc(configName: 'infra.1', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''
|
||||||
|
logger -t jenkins-ssh-publisher "Restarting infra environment"
|
||||||
|
pwd
|
||||||
cd /home/rschneider/infra/
|
cd /home/rschneider/infra/
|
||||||
git pull
|
git pull
|
||||||
cd environments/infra
|
cd environments/infra
|
||||||
|
|||||||
@ -1,20 +1,24 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
PROJECT_ROOT=$(readlink -f "$(dirname "$(realpath "$0")")/../..")
|
log() {
|
||||||
echo "Project root directory: $PROJECT_ROOT"
|
echo "$1"
|
||||||
|
logger -t infra-update "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
PROJECT_ROOT=$(readlink -f "$(dirname "$(realpath "$0")")/../..")
|
||||||
|
log "Project root directory: $PROJECT_ROOT"
|
||||||
|
|
||||||
# Restart all projects except 'traefik' and 'jenkins'
|
# Restart all projects except 'traefik' and 'jenkins'
|
||||||
for dir in $(find "$PROJECT_ROOT" -type d -path "*/docker-compose/*" -mindepth 3 -maxdepth 3 -not -path "*/docker-compose/*/*" | grep -v "/traefik/docker-compose/traefik" | grep -v "/jenkins/docker-compose/jenkins"); do
|
for dir in $(find "$PROJECT_ROOT" -mindepth 3 -maxdepth 3 -not -path "*/docker-compose/*/*" -type d -path "*/docker-compose/*" | grep -v "/traefik/docker-compose/traefik" | grep -v "/jenkins/docker-compose/jenkins"); do
|
||||||
echo "Processing directory: $dir"
|
log "Processing directory: $dir"
|
||||||
cd "$dir" || { echo "Failed to enter directory: $dir"; continue; }
|
cd "$dir" || { log "Failed to enter directory: $dir"; continue; }
|
||||||
|
|
||||||
# Execute docker compose commands
|
# Execute docker compose commands
|
||||||
if [ -f "docker-compose.yml" ] || [ -f "docker-compose.yaml" ]; then
|
if [ -f "docker-compose.yml" ] || [ -f "docker-compose.yaml" ]; then
|
||||||
echo "Running docker compose down && docker compose up -d in $dir"
|
log "Running docker compose down && docker compose up -d in $dir"
|
||||||
# docker compose down && docker compose up -d
|
docker compose down && docker compose up -d
|
||||||
else
|
else
|
||||||
echo "No docker-compose file found in $dir, skipping..."
|
log "No docker-compose file found in $dir, skipping..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Return to the project root
|
# Return to the project root
|
||||||
@ -22,16 +26,16 @@ for dir in $(find "$PROJECT_ROOT" -type d -path "*/docker-compose/*" -mindepth 3
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Restart 'traefik' project last
|
# Restart 'traefik' project last
|
||||||
TRAEFIK_DIR=$(find "$PROJECT_ROOT" -type d -path "*/traefik/docker-compose/traefik" -mindepth 3 -maxdepth 3 -not -path "*/docker-compose/*/*")
|
TRAEFIK_DIR=$(find "$PROJECT_ROOT" -mindepth 3 -maxdepth 3 -not -path "*/docker-compose/*/*" -type d -path "*/traefik/docker-compose/traefik")
|
||||||
if [ -n "$TRAEFIK_DIR" ]; then
|
if [ -n "$TRAEFIK_DIR" ]; then
|
||||||
echo "Processing traefik directory: $TRAEFIK_DIR"
|
log "Processing traefik directory: $TRAEFIK_DIR"
|
||||||
cd "$TRAEFIK_DIR" || { echo "Failed to enter traefik directory: $TRAEFIK_DIR"; exit 1; }
|
cd "$TRAEFIK_DIR" || { log "Failed to enter traefik directory: $TRAEFIK_DIR"; exit 1; }
|
||||||
|
|
||||||
# Execute docker compose commands
|
# Execute docker compose commands
|
||||||
if [ -f "docker-compose.yml" ] || [ -f "docker-compose.yaml" ]; then
|
if [ -f "docker-compose.yml" ] || [ -f "docker-compose.yaml" ]; then
|
||||||
echo "Running docker compose down && docker compose up -d in $TRAEFIK_DIR"
|
log "Running docker compose down && docker compose up -d in $TRAEFIK_DIR"
|
||||||
# docker compose down && docker compose up -d
|
docker compose down && docker compose up -d
|
||||||
else
|
else
|
||||||
echo "No docker-compose file found in $TRAEFIK_DIR, skipping..."
|
log "No docker-compose file found in $TRAEFIK_DIR, skipping..."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user