Skip to content

Commit 5eb03ec

Browse files
committed
ci: Fix deployment script
1 parent 763e0a4 commit 5eb03ec

1 file changed

Lines changed: 32 additions & 27 deletions

File tree

scripts/deploy.sh

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
#!/bin/bash
2+
set -e
23

3-
# checks if container name is supplied
4-
if [ "$#" -eq 0 ]
5-
then
6-
echo "Please specify a container name!"
7-
exit 1
4+
# Checks if APPLICATION_IMAGE is specified
5+
if [ -z "$APPLICATION_IMAGE" ]; then
6+
echo "[ERROR] APPLICATION_IMAGE variable not set."
7+
exit 1
88
fi
99

10-
# checks if container exist
11-
if [ "$(docker ps -a -q -f name=$1)" ]
12-
then
13-
echo "An existing container with the name $1 was found!"
14-
15-
# checks if container is running and stop it if it is
16-
if [ "$(docker ps -aq -f status=running -f name=$1)" ]
17-
then
18-
echo "Stopping container..."
19-
docker stop $1
20-
echo "Container stopped."
21-
fi
22-
23-
# removes stopped container
24-
echo "Removing stopped container..."
25-
docker rm -f $1
26-
echo "Container removed."
27-
fi
10+
# Logs into GHCR using provided credentials (from GitHub CI/CD)
11+
echo "Logging into GitHub Container Registry..."
12+
echo "${GHCR_PAT}" | docker login ghcr.io -u "${GHCR_USER}" --password-stdin
13+
14+
# Pulls application images
15+
echo "Pulling image: $APPLICATION_IMAGE"
16+
docker pull "$APPLICATION_IMAGE"
17+
18+
# Changes directory to where the deployment files are
19+
cd "/opt/rcb-deployments/$PROJECT_NAME"
20+
21+
# Replaces placeholder string '${APPLICATION_IMAGE}' with the actual image within compose file.
22+
echo "Injecting image to override docker compose file..."
23+
sed -i "s|\${APPLICATION_IMAGE}|$APPLICATION_IMAGE|g" ./docker/docker-compose.override.yml
24+
25+
# Tears down existing containers
26+
echo "Stopping existing containers..."
27+
docker compose -p "$PROJECT_NAME" down
28+
29+
# Brings up new containers
30+
echo "Starting new containers..."
31+
docker compose -p "$PROJECT_NAME" --env-file ./config/env/.env -f ./docker/docker-compose.yml -f ./docker/docker-compose.override.yml up -d --build
2832

29-
# pull the latest image
30-
docker pull React-ChatBotify/rag-api:main
33+
# Cleans up unused docker images
34+
echo "Pruning unused Docker images..."
35+
docker image prune -f
3136

32-
# run new docker container
33-
docker run -d --restart always --name $1 --env-file ./.env React-ChatBotify/rag-api:main
37+
# Announces deployment complete
38+
echo "Deployment complete."

0 commit comments

Comments
 (0)