File size: 1,682 Bytes
55a8b5e
f92437f
55a8b5e
f92437f
 
 
55a8b5e
65d0826
f92437f
 
 
 
 
 
 
 
6c3fbed
55a8b5e
f92437f
55a8b5e
 
 
 
 
 
f92437f
 
 
0101ee2
6c3fbed
f92437f
e77bdc9
f92437f
 
 
 
 
6c3fbed
 
 
 
 
 
 
 
 
 
 
 
 
f92437f
55a8b5e
6c3fbed
 
55a8b5e
f92437f
55a8b5e
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
set -e # Exit immediately if a command fails

# --- Configuration ---
APP_DIR="/home/ubuntu/itinerary-generator"
cd ${APP_DIR}

export CONTAINER_NAME="ec2-api-doc-tool-generator"

# 1. Get environment name from CodeDeploy
APP_ENV=${DEPLOYMENT_GROUP_NAME}
if [[ -z "$APP_ENV" ]]; then
    echo "ERROR: DEPLOYMENT_GROUP_NAME is not set."
    exit 1
fi

# 2. Read the image tag
if [[ -f "image-tag.txt" ]]; then
    export IMAGE_TAG=$(cat image-tag.txt)
else
    echo "ERROR: image-tag.txt not found"
    exit 1
fi

echo "=== Deployment Variables ==="
echo "Project Name (APP_ENV)=${APP_ENV}"
echo "Container Name=${CONTAINER_NAME}"
echo "Image Tag=${IMAGE_TAG}"

# 3. ✅ CREATE THE .env FILE FIRST
echo "=== Creating .env file ==="
PARAM_PATH="/api-doc-tool-generator"

echo "AWS_PARAMETER_STORE_PATH=${PARAM_PATH}" > .env
echo "APP_ENV=${APP_ENV}" >> .env
echo "Created .env file with SSM Path: ${PARAM_PATH}"

# 4. Login to AWS ECR
echo "=== Login AWS ECR ==="
aws ecr get-login-password --region ap-southeast-3 | docker login --username AWS --password-stdin 825765383758.dkr.ecr.ap-southeast-3.amazonaws.com

# 5. Stop and Pull
echo "=== Stopping containers ==="
# ✅ FIX: Use 'docker-compose.yaml'
docker-compose -p "${APP_ENV}" -f docker-compose.yaml down || true

echo "=== Pulling images ==="
# ✅ FIX: Use 'docker-compose.yaml'
docker-compose -p "${APP_ENV}" -f docker-compose.yaml pull

# 6. Start Containers
echo "=== Starting containers ==="
# ✅ FIX: Use 'docker-compose.yaml'
docker-compose -p "${APP_ENV}" -f docker-compose.yaml up -d

# 7. Prune
echo "=== Prune unused images ==="
docker image prune -af

echo "=== Deployment completed successfully ==="