mrfirdauss commited on
Commit
6c3fbed
Β·
1 Parent(s): f92437f

fix deploy .env export

Browse files
Files changed (1) hide show
  1. deploy.sh +17 -28
deploy.sh CHANGED
@@ -2,12 +2,9 @@
2
  set -e # Exit immediately if a command fails
3
 
4
  # --- Configuration ---
5
- # βœ… DEFINE THE APP DIRECTORY (from your appspec.yml)
6
  APP_DIR="/home/ubuntu/itinerary-generator"
7
  cd ${APP_DIR}
8
 
9
- # βœ… DEFINE YOUR CONTAINER/ECR REPO NAME
10
- # This must match the $CONTAINER_NAME var in your CodeBuild project
11
  export CONTAINER_NAME="itinerary-generator" # Or whatever your ECR repo is named
12
 
13
  # 1. Get environment name from CodeDeploy
@@ -17,9 +14,8 @@ if [[ -z "$APP_ENV" ]]; then
17
  exit 1
18
  fi
19
 
20
- # 2. Read the image tag from the file
21
  if [[ -f "image-tag.txt" ]]; then
22
- # βœ… Export this so docker-compose.yaml can read it
23
  export IMAGE_TAG=$(cat image-tag.txt)
24
  else
25
  echo "ERROR: image-tag.txt not found"
@@ -31,38 +27,31 @@ echo "Project Name (APP_ENV)=${APP_ENV}"
31
  echo "Container Name=${CONTAINER_NAME}"
32
  echo "Image Tag=${IMAGE_TAG}"
33
 
34
- # 3. Login to AWS ECR
35
- echo "=== Login AWS ECR ==="
36
- aws ecr get-login-password --region ap-southeast-3 | docker login --username AWS --password-stdin 825765383758.dkr.ecr.ap-southeast-3.amazonaws.com
37
-
38
- # 4. Stop and Pull
39
- echo "=== Stopping containers ==="
40
- docker-compose -p "${APP_ENV}" down || true
41
-
42
- echo "=== Pulling images ==="
43
- docker-compose -p "${APP_ENV}" -f docker-compose.yml pull
44
-
45
- # 5. βœ… CREATE THE .env FILE
46
  echo "=== Creating .env file ==="
47
- # This is the file your server.py and docker-compose.yaml need.
48
- # We will create it using the APP_ENV to build the correct SSM path.
49
-
50
- # Define the SSM Parameter Store path based on the environment
51
- # Example: /itinerary-generator/development or /itinerary-generator/production
52
  PARAM_PATH="/${CONTAINER_NAME}/${APP_ENV}"
53
 
54
- # Write the path into the .env file.
55
- # The 'echo' command creates the file.
56
  echo "AWS_PARAMETER_STORE_PATH=${PARAM_PATH}" > .env
57
- # Add any other non-secret vars your app needs from the .env
58
  echo "APP_ENV=${APP_ENV}" >> .env
59
-
60
  echo "Created .env file with SSM Path: ${PARAM_PATH}"
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  # 6. Start Containers
63
  echo "=== Starting containers ==="
64
- # Now this command will work because .env exists
65
- docker-compose -p "${APP_ENV}" -f docker-compose.yml up -d
66
 
67
  # 7. Prune
68
  echo "=== Prune unused images ==="
 
2
  set -e # Exit immediately if a command fails
3
 
4
  # --- Configuration ---
 
5
  APP_DIR="/home/ubuntu/itinerary-generator"
6
  cd ${APP_DIR}
7
 
 
 
8
  export CONTAINER_NAME="itinerary-generator" # Or whatever your ECR repo is named
9
 
10
  # 1. Get environment name from CodeDeploy
 
14
  exit 1
15
  fi
16
 
17
+ # 2. Read the image tag
18
  if [[ -f "image-tag.txt" ]]; then
 
19
  export IMAGE_TAG=$(cat image-tag.txt)
20
  else
21
  echo "ERROR: image-tag.txt not found"
 
27
  echo "Container Name=${CONTAINER_NAME}"
28
  echo "Image Tag=${IMAGE_TAG}"
29
 
30
+ # 3. βœ… CREATE THE .env FILE FIRST
 
 
 
 
 
 
 
 
 
 
 
31
  echo "=== Creating .env file ==="
 
 
 
 
 
32
  PARAM_PATH="/${CONTAINER_NAME}/${APP_ENV}"
33
 
 
 
34
  echo "AWS_PARAMETER_STORE_PATH=${PARAM_PATH}" > .env
 
35
  echo "APP_ENV=${APP_ENV}" >> .env
 
36
  echo "Created .env file with SSM Path: ${PARAM_PATH}"
37
 
38
+ # 4. Login to AWS ECR
39
+ echo "=== Login AWS ECR ==="
40
+ aws ecr get-login-password --region ap-southeast-3 | docker login --username AWS --password-stdin 825765383758.dkr.ecr.ap-southeast-3.amazonaws.com
41
+
42
+ # 5. Stop and Pull
43
+ echo "=== Stopping containers ==="
44
+ # βœ… FIX: Use 'docker-compose.yaml'
45
+ docker-compose -p "${APP_ENV}" -f docker-compose.yaml down || true
46
+
47
+ echo "=== Pulling images ==="
48
+ # βœ… FIX: Use 'docker-compose.yaml'
49
+ docker-compose -p "${APP_ENV}" -f docker-compose.yaml pull
50
+
51
  # 6. Start Containers
52
  echo "=== Starting containers ==="
53
+ # βœ… FIX: Use 'docker-compose.yaml'
54
+ docker-compose -p "${APP_ENV}" -f docker-compose.yaml up -d
55
 
56
  # 7. Prune
57
  echo "=== Prune unused images ==="