Initial commit - SOGOMS v1.0.0
- sogoctl: supervisor avec health checks et restart auto - sogoway: gateway HTTP, auth JWT, routing par hostname - sogoms-db: microservice MariaDB avec pool par application - Protocol IPC Unix socket JSON length-prefixed - Config YAML multi-application (prokov) - Deploy script pour container Alpine gw3 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
154
deploy.sh
Executable file
154
deploy.sh
Executable file
@@ -0,0 +1,154 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script de déploiement pour SOGOMS
|
||||
# Version: 1.0 (15 décembre 2025)
|
||||
# Auteur: Pierre (avec l'aide de Claude)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Configuration SSH
|
||||
JUMP_USER="root"
|
||||
JUMP_HOST="195.154.80.116"
|
||||
JUMP_PORT="22"
|
||||
JUMP_KEY="/home/pierre/.ssh/id_rsa_mbpi"
|
||||
|
||||
# Configuration Incus
|
||||
INCUS_PROJECT="default"
|
||||
INCUS_CONTAINER="gw3"
|
||||
CONTAINER_IP="13.23.33.5"
|
||||
|
||||
# Chemins sur le container
|
||||
REMOTE_BIN="/opt/sogoms/bin"
|
||||
REMOTE_CONFIG="/config"
|
||||
REMOTE_SECRETS="/secrets"
|
||||
|
||||
# Couleurs pour les messages
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[0;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Fonctions d'affichage
|
||||
echo_step() {
|
||||
echo -e "${GREEN}==>${NC} $1"
|
||||
}
|
||||
|
||||
echo_info() {
|
||||
echo -e "${BLUE}Info:${NC} $1"
|
||||
}
|
||||
|
||||
echo_warning() {
|
||||
echo -e "${YELLOW}Warning:${NC} $1"
|
||||
}
|
||||
|
||||
echo_error() {
|
||||
echo -e "${RED}Error:${NC} $1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Répertoire du script
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Vérification de l'environnement
|
||||
echo_step "Verifying environment..."
|
||||
echo_info "Deploying SOGOMS to container $INCUS_CONTAINER ($CONTAINER_IP)"
|
||||
echo_info "Jump host: $JUMP_HOST"
|
||||
|
||||
if [ ! -d "cmd/sogoms/db" ] || [ ! -d "cmd/sogoway" ] || [ ! -d "cmd/sogoctl" ]; then
|
||||
echo_error "Source directories missing - are you in the sogoms directory?"
|
||||
fi
|
||||
|
||||
if [ ! -d "config/routes" ]; then
|
||||
echo_error "config/routes missing"
|
||||
fi
|
||||
|
||||
# Commande SSH vers IN3
|
||||
SSH_CMD="ssh -i ${JUMP_KEY} -p ${JUMP_PORT} ${JUMP_USER}@${JUMP_HOST}"
|
||||
SCP_CMD="scp -i ${JUMP_KEY} -P ${JUMP_PORT}"
|
||||
|
||||
# Lire la version
|
||||
VERSION=$(cat VERSION | tr -d '\n')
|
||||
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
|
||||
LDFLAGS="-X sogoms.com/internal/version.Version=${VERSION} -X sogoms.com/internal/version.BuildTime=${BUILD_TIME}"
|
||||
|
||||
# Étape 1: Build des binaires
|
||||
echo_step "Building binaries v${VERSION} (linux/amd64)..."
|
||||
mkdir -p bin
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o bin/sogoms-db ./cmd/sogoms/db || echo_error "Failed to build sogoms-db"
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o bin/sogoway ./cmd/sogoway || echo_error "Failed to build sogoway"
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o bin/sogoctl ./cmd/sogoctl || echo_error "Failed to build sogoctl"
|
||||
|
||||
echo_info "Built: sogoms-db, sogoway, sogoctl (v${VERSION})"
|
||||
|
||||
# Étape 2: Créer les archives
|
||||
echo_step "Creating archives..."
|
||||
TIMESTAMP=$(date +%s)
|
||||
BIN_ARCHIVE="sogoms-bin-${TIMESTAMP}.tar.gz"
|
||||
CONFIG_ARCHIVE="sogoms-config-${TIMESTAMP}.tar.gz"
|
||||
|
||||
tar -czf "/tmp/${BIN_ARCHIVE}" -C bin . || echo_error "Failed to create bin archive"
|
||||
tar -czf "/tmp/${CONFIG_ARCHIVE}" -C config . || echo_error "Failed to create config archive"
|
||||
|
||||
BIN_SIZE=$(du -h "/tmp/${BIN_ARCHIVE}" | cut -f1)
|
||||
CONFIG_SIZE=$(du -h "/tmp/${CONFIG_ARCHIVE}" | cut -f1)
|
||||
echo_info "Binaries archive: $BIN_SIZE"
|
||||
echo_info "Config archive: $CONFIG_SIZE"
|
||||
|
||||
# Étape 3: Copier vers IN3
|
||||
echo_step "Copying archives to jump server (IN3)..."
|
||||
$SCP_CMD "/tmp/${BIN_ARCHIVE}" "${JUMP_USER}@${JUMP_HOST}:/tmp/" || echo_error "Failed to copy bin archive"
|
||||
$SCP_CMD "/tmp/${CONFIG_ARCHIVE}" "${JUMP_USER}@${JUMP_HOST}:/tmp/" || echo_error "Failed to copy config archive"
|
||||
|
||||
# Étape 4: Déployer dans le container
|
||||
echo_step "Deploying to Incus container ($INCUS_CONTAINER)..."
|
||||
$SSH_CMD "
|
||||
set -euo pipefail
|
||||
|
||||
echo '📦 Switching to Incus project...'
|
||||
incus project switch ${INCUS_PROJECT} || exit 1
|
||||
|
||||
echo '📦 Pushing archives to container...'
|
||||
incus file push /tmp/${BIN_ARCHIVE} ${INCUS_CONTAINER}/tmp/ || exit 1
|
||||
incus file push /tmp/${CONFIG_ARCHIVE} ${INCUS_CONTAINER}/tmp/ || exit 1
|
||||
|
||||
echo '📁 Deploying binaries...'
|
||||
incus exec ${INCUS_CONTAINER} -- mkdir -p ${REMOTE_BIN}
|
||||
incus exec ${INCUS_CONTAINER} -- tar -xzvf /tmp/${BIN_ARCHIVE} -C ${REMOTE_BIN}/
|
||||
incus exec ${INCUS_CONTAINER} -- chmod 755 ${REMOTE_BIN}/sogoms-db ${REMOTE_BIN}/sogoway ${REMOTE_BIN}/sogoctl
|
||||
|
||||
echo '📁 Deploying config...'
|
||||
incus exec ${INCUS_CONTAINER} -- mkdir -p ${REMOTE_CONFIG}/routes ${REMOTE_CONFIG}/scenarios
|
||||
incus exec ${INCUS_CONTAINER} -- tar -xzf /tmp/${CONFIG_ARCHIVE} -C ${REMOTE_CONFIG}/
|
||||
|
||||
echo '📁 Setting up run directory...'
|
||||
incus exec ${INCUS_CONTAINER} -- mkdir -p /run
|
||||
|
||||
echo '🧹 Cleanup...'
|
||||
incus exec ${INCUS_CONTAINER} -- rm -f /tmp/${BIN_ARCHIVE} /tmp/${CONFIG_ARCHIVE}
|
||||
rm -f /tmp/${BIN_ARCHIVE} /tmp/${CONFIG_ARCHIVE}
|
||||
"
|
||||
|
||||
# Nettoyage local
|
||||
rm -f "/tmp/${BIN_ARCHIVE}" "/tmp/${CONFIG_ARCHIVE}"
|
||||
|
||||
# Résumé final
|
||||
echo_step "Deployment completed successfully!"
|
||||
echo ""
|
||||
echo_info "SOGOMS v${VERSION} deployed"
|
||||
echo_info " Host: IN3 ($JUMP_HOST)"
|
||||
echo_info " Container: $INCUS_CONTAINER ($CONTAINER_IP)"
|
||||
echo_info " Binaries: $REMOTE_BIN"
|
||||
echo_info " Config: $REMOTE_CONFIG"
|
||||
echo_info " Deployment time: $(date)"
|
||||
echo ""
|
||||
echo_warning "Next steps on gw3:"
|
||||
echo_info " 1. Edit /secrets/prokov_db_pass with real DB password"
|
||||
echo_info " 2. Start services: /opt/sogoms/bin/sogoctl"
|
||||
echo ""
|
||||
echo_info "To connect: ssh in3 -t 'incus exec $INCUS_CONTAINER -- sh'"
|
||||
|
||||
# Journaliser le déploiement
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') - SOGOMS v${VERSION} deployed to ${INCUS_CONTAINER} (${CONTAINER_IP})" >> ~/.sogoms_deploy_history
|
||||
Reference in New Issue
Block a user