containerAdmin/run_admin_container.sh
2025-05-20 07:40:23 +00:00

50 lines
1.7 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e
# vars via Semaphore UI
MAIN_BR="${MAIN_BR:-main}" # Branche du dépôt main_playbooks
ENV="${ENV:-staging}" # Nom de l'environnement (staging, prod, etc.)
ENV_BR="${ENV_BR:-test_feature}" # Branche des fichiers d'env
PLAYBOOK_FILE="${PLAYBOOK_FILE:-base.yaml}" # Nom du fichier playbook dans /playbooks/
# Setup SSH and known_hosts
echo "[INFO] Setting up SSH environment..."
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Add git.felcloud.io to known_hosts to avoid interactive prompt
echo "[INFO] Adding git.felcloud.io to known_hosts..."
ssh-keyscan git.felcloud.io >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
# Debug SSH keys
echo "[DEBUG] Available SSH keys:"
ls -la ~/.ssh
# 1/Cloner les dépôts nécessaires:
echo "[INFO] Cloning repositories..."
git clone git@git.felcloud.io:felcloud/ansible_core_init_ansible.git
git clone git@git.felcloud.io:felcloud/ansible_env_staging.git
cd ansible_core_init_ansible
git checkout "$ENV_BR"
# 2/Build local de limage Docker admin:
echo "[INFO] Building Docker image locally..."
docker build --no-cache --build-arg branch=fix_packages_dependencies -t ansible-pulumi:local .
# 3/Lancer le conteneur admin avec le playbook choisi:
echo "[INFO] Running the admin container with playbook: $PLAYBOOK_FILE"
docker run --rm -it \
-v "$(pwd)/../ansible_env_staging:/home/cloud/ansible_env_staging" \
-e MAIN_BR="$MAIN_BR" \
-e ENV="$ENV" \
-e ENV_BR="$ENV_BR" \
ansible-pulumi:local bash -c "
cd /home/cloud/ansible-pulumi && \
source /home/cloud/venv/bin/activate && \
ansible-playbook playbooks/${PLAYBOOK_FILE} -i /home/cloud/ansible_env_staging/hosts"