mrfirdauss commited on
Commit
0101ee2
·
1 Parent(s): 55a8b5e

fix: docker compose

Browse files
Files changed (6) hide show
  1. Dockerfile +1 -1
  2. app/util/parameter_utils.py +27 -0
  3. deploy.sh +11 -12
  4. docker-compose.yaml +2 -3
  5. requirements.txt +3 -1
  6. server.py +10 -1
Dockerfile CHANGED
@@ -5,7 +5,7 @@ WORKDIR /home/user/app
5
 
6
  COPY requirements.txt .
7
 
8
- RUN apt-get update && apt-get install -y --no-install-recommends \
9
  wget gnupg ca-certificates && \
10
  pip install --upgrade pip && \
11
  pip install --no-cache-dir -r requirements.txt && \
 
5
 
6
  COPY requirements.txt .
7
 
8
+ RUN apt-get update && apt-get install -y --no-install-recommends && \
9
  wget gnupg ca-certificates && \
10
  pip install --upgrade pip && \
11
  pip install --no-cache-dir -r requirements.txt && \
app/util/parameter_utils.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # parameter_utils.py
2
+ import os
3
+
4
+ import boto3
5
+
6
+ ssm = boto3.client('ssm', region_name='ap-southeast-3')
7
+
8
+ def init_secret(path):
9
+ next_token = None
10
+ while True:
11
+ response = ssm.get_parameters_by_path(
12
+ Path=path,
13
+ Recursive=True,
14
+ WithDecryption=True,
15
+ NextToken=next_token if next_token else "",
16
+ )
17
+ parameters = response.get("Parameters", [])
18
+ for parameter in parameters:
19
+ key = parameter.get("Name").split("/")[-1]
20
+ value = parameter.get("Value")
21
+ os.environ[key] = value
22
+ print(f"Set env variable {key}")
23
+
24
+ next_token = response.get("NextToken")
25
+ if not next_token:
26
+ break
27
+
deploy.sh CHANGED
@@ -10,21 +10,20 @@ else
10
  exit 1
11
  fi
12
 
13
- APP_ENV=${DEPLOYMENT_GROUP_NAME}
14
-
15
- if [[ "$APP_ENV" == "development" ]]; then
16
- API_PORT=5001
17
- ES_PORT=9200
18
- else
19
- API_PORT=5002
20
- ES_PORT=9201
21
- fi
22
 
23
  echo "=== Deployment Variables ==="
24
- echo "APP_ENV=${APP_ENV}"
25
  echo "IMAGE_TAG=${IMAGE_TAG}"
26
- echo "API_PORT=${API_PORT}"
27
- echo "ES_PORT=${ES_PORT}"
 
 
 
 
 
 
 
 
28
  export APP_ENV IMAGE_TAG API_PORT ES_PORT
29
 
30
  echo "=== Login AWS ==="
 
10
  exit 1
11
  fi
12
 
 
 
 
 
 
 
 
 
 
13
 
14
  echo "=== Deployment Variables ==="
15
+ echo "GOOGLE_AI_STUDIO_API_KEY=${GOOGLE_AI_STUDIO_API_KEY}"
16
  echo "IMAGE_TAG=${IMAGE_TAG}"
17
+ echo "GOOGLE_AI_STUDIO_MODEL=${GOOGLE_AI_STUDIO_MODEL}"
18
+ echo "DB_HOST=${DB_HOST}"
19
+ echo "DB_NAME=${DB_NAME}"
20
+ echo "DB_USERNAME=${DB_USERNAME}"
21
+ echo "DB_PORT=${DB_PORT}"
22
+ echo "DB_PASSWORD=${DB_PASSWORD}"
23
+
24
+ echo "PORT=${PORT}"
25
+ echo "PLAYWRIGHT_BROWSERS_PATH=${PLAYWRIGHT_BROWSERS_PATH}"
26
+
27
  export APP_ENV IMAGE_TAG API_PORT ES_PORT
28
 
29
  echo "=== Login AWS ==="
docker-compose.yaml CHANGED
@@ -7,7 +7,6 @@ services:
7
  - "7860:7860"
8
  env_file:
9
  - .env
10
- environment:
11
- - PORT=7860
12
- - PLAYWRIGHT_BROWSERS_PATH=/home/user/.cache/ms-playwright
13
  restart: always
 
7
  - "7860:7860"
8
  env_file:
9
  - .env
10
+ volumes:
11
+ - ./.env:/.env
 
12
  restart: always
requirements.txt CHANGED
@@ -15,4 +15,6 @@ fpdf
15
  pandas
16
 
17
  SQLAlchemy
18
- psycopg2-binary
 
 
 
15
  pandas
16
 
17
  SQLAlchemy
18
+ psycopg2-binary
19
+
20
+ boto3
server.py CHANGED
@@ -13,7 +13,8 @@ import io
13
 
14
  from app.util.gen_ai_base import GenAIBaseClient
15
  from app.util.browser_agent import BrowserAgent
16
- from app.util.japan_multientry_visa_letter_generator import JapanMultiEntryVisaLetterGenerator
 
17
  import sys
18
  sys.stdout.reconfigure(line_buffering=True)
19
  API = "https://api-dev.spun.global"
@@ -28,6 +29,14 @@ def create_app() -> Flask:
28
  app = Flask(__name__)
29
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
30
 
 
 
 
 
 
 
 
 
31
  @app.route('/scrape', methods=['POST'])
32
  async def scrape():
33
  try:
 
13
 
14
  from app.util.gen_ai_base import GenAIBaseClient
15
  from app.util.browser_agent import BrowserAgent
16
+ # from app.util.japan_multientry_visa_letter_generator import JapanMultiEntryVisaLetterGenerator
17
+ from app.util.parameter_utils import init_secret
18
  import sys
19
  sys.stdout.reconfigure(line_buffering=True)
20
  API = "https://api-dev.spun.global"
 
29
  app = Flask(__name__)
30
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
31
 
32
+ try:
33
+ aws_param_path = os.getenv("AWS_PARAMETER_STORE_PATH")
34
+ if aws_param_path:
35
+ init_secret(aws_param_path)
36
+ logging.info("Secrets loaded from AWS SSM Parameter Store.")
37
+ except Exception as e:
38
+ logging.exception(f"Could not load secrets from SSM: {e}")
39
+
40
  @app.route('/scrape', methods=['POST'])
41
  async def scrape():
42
  try: