bug: Fix the TTL feature in docker staging (#832)

## Description:

Modify the docker run command to allow containers in staging to
terminate.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

---------

Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
This commit is contained in:
Scott Anderson
2025-05-21 01:47:17 -04:00
committed by GitHub
parent 95c15de218
commit aa6e252ff3
2 changed files with 16 additions and 10 deletions
+15 -9
View File
@@ -16,34 +16,40 @@ echo "======================================================"
CONTAINER_NAME="openfront-${ENV}-${SUBDOMAIN}"
echo "Pulling ${DOCKER_IMAGE} from Docker Hub..."
docker pull $DOCKER_IMAGE
docker pull "${DOCKER_IMAGE}"
echo "Checking for existing container..."
# Check for running container
RUNNING_CONTAINER=$(docker ps | grep ${CONTAINER_NAME} | awk '{print $1}')
RUNNING_CONTAINER="$(docker ps | grep ${CONTAINER_NAME} | awk '{print $1}')"
if [ -n "$RUNNING_CONTAINER" ]; then
echo "Stopping running container $RUNNING_CONTAINER..."
docker stop $RUNNING_CONTAINER
docker stop "$RUNNING_CONTAINER"
echo "Waiting for container to fully stop and release resources..."
sleep 5 # Add a 5-second delay
docker rm $RUNNING_CONTAINER
docker rm "$RUNNING_CONTAINER"
echo "Container $RUNNING_CONTAINER stopped and removed."
fi
# Also check for stopped containers with the same name
STOPPED_CONTAINER=$(docker ps -a | grep ${CONTAINER_NAME} | awk '{print $1}')
STOPPED_CONTAINER="$(docker ps -a | grep ${CONTAINER_NAME} | awk '{print $1}')"
if [ -n "$STOPPED_CONTAINER" ]; then
echo "Removing stopped container $STOPPED_CONTAINER..."
docker rm $STOPPED_CONTAINER
docker rm "$STOPPED_CONTAINER"
echo "Container $STOPPED_CONTAINER removed."
fi
if [ "${SUBDOMAIN}" = main ] || [ "${DOMAIN}" = openfront.io ]; then
RESTART=always
else
RESTART=no
fi
echo "Starting new container for ${HOST} environment..."
docker run -d \
--restart=always \
--restart="${RESTART}" \
--env-file /home/openfront/.env \
--name ${CONTAINER_NAME} \
$DOCKER_IMAGE
--name "${CONTAINER_NAME}" \
"${DOCKER_IMAGE}"
if [ $? -eq 0 ]; then
echo "Update complete! New ${CONTAINER_NAME} container is running."