Created
July 10, 2025 18:03
-
-
Save marlonramirez/d1b71e9ec11d1f5d42398682a206105e to your computer and use it in GitHub Desktop.
Despliegue automatizado para docker compose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
cd /path/to/my/project | |
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REGISTRY | |
MAX_WAIT_SECONDS=300 | |
CHECK_INTERVAL_SECONDS=10 | |
SECONDS_WAITED=0 | |
VAR_NAME_TO_UPDATE=$(echo "${ECR_REPOSITORY%%-*}" | tr 'a-z' 'A-Z')_IMAGE | |
if grep -q "^${VAR_NAME_TO_UPDATE}=" ".env"; then | |
sed -i "s|^${VAR_NAME_TO_UPDATE}=.*|${VAR_NAME_TO_UPDATE}=${ECR_REGISTRY}\/${ECR_REPOSITORY}:${TAG}|" ".env" | |
else | |
echo "${VAR_NAME_TO_UPDATE}=${ECR_REGISTRY}/${ECR_REPOSITORY}:${TAG}" >> ".env" | |
fi | |
docker-compose up -d --remove-orphans | |
while true; do | |
running_jobs=$(docker ps --filter "name=conf-" --filter "status=running" --format "{{.Names}}") | |
if [ -z "${running_jobs}" ]; then | |
break | |
fi | |
if [ ${SECONDS_WAITED} -ge ${MAX_WAIT_SECONDS} ]; then | |
echo "¡ERROR! Tiempo de espera máximo alcanzado (${MAX_WAIT_SECONDS} s)." | |
echo "Los siguientes jobs no han terminado (pueden estar en un bucle de reinicio por fallo):" | |
echo "${running_job}s" | |
for job in ${running_jobs}; do | |
echo "--- Logs de ${job} ---" | |
docker logs "${job}" --tail 50 | |
done | |
exit 1 | |
fi | |
sleep ${CHECK_INTERVAL_SECONDS} | |
SECONDS_WAITED=$((SECONDS_WAITED + CHECK_INTERVAL_SECONDS)) | |
done | |
docker-compose rm -f | |
docker image prune -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment