Skip to content

Commit 2db137e

Browse files
committed
add CD and correct deploy script
1 parent ab5a7fb commit 2db137e

File tree

12 files changed

+87
-18
lines changed

12 files changed

+87
-18
lines changed

Dockerfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
FROM python:3.9-alpine
1+
FROM python:3.9.15-slim
22

33
COPY . /code
44
WORKDIR /code
55

6-
RUN chmod +x ./hostscript
6+
RUN pip install --upgrade pip
7+
RUN pip install pipenv
78

8-
ENTRYPOINT ./hostscript
9+
RUN apt-get update
10+
RUN apt-get install --yes --no-install-recommends \
11+
gcc g++ libffi-dev
12+
13+
RUN pipenv install --deploy --system --ignore-pipfile
14+
15+
CMD ["gunicorn", "-c", "/code/gunicorn_config.py", "src.api.wsgi:app"]

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7-
pandas = "*"
87
numpy = "*"
8+
pandas = "*"
99
wikipedia-api = "*"
1010
farm-haystack = "*"
1111
python-dotenv = "*"

buildspec.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: 0.2
2+
3+
env:
4+
parameter-store:
5+
build_ssh_key: "/Dev/Production/chatbox-nlp-api/codebuild_ssh_key"
6+
phases:
7+
install:
8+
commands:
9+
- export DEPLOY_SCRIPT=/home/ec2-user/server/prod.sh
10+
- mkdir -p ~/.ssh
11+
- echo "$build_ssh_key" > ~/.ssh/id_rsa
12+
- chmod 600 ~/.ssh/id_rsa
13+
pre_build:
14+
commands:
15+
- echo Logging into aws ECR...
16+
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
17+
build:
18+
commands:
19+
- echo Build started on `date`
20+
- echo Building the Docker image...
21+
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
22+
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
23+
post_build:
24+
commands:
25+
- echo Build completed on `date`
26+
- echo Pushing the Docker image...
27+
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
28+
- echo Deploying the Docker image...
29+
- ssh -o "StrictHostKeyChecking no" $SERVER_URL $DEPLOY_SCRIPT
30+

docker-compose.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
version: "3.7"
12
services:
23
haystack-api:
3-
container_name: qna-api
4+
container_name: chatbox-nlp-api-gunicorn-container
5+
image: 038582424441.dkr.ecr.us-east-2.amazonaws.com/chatbox-nlp-api:latest
46
ports:
57
- 8080:8080
6-
build:
7-
context: .
8+
# build:
9+
# context: .

gunicorn_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# pidfile = 'app01.pid'
44
# worker_tmp_dir = '/dev/shm'
55
# worker_class = 'gthread'
6-
workers = 8
6+
workers = 1
77
worker_connections = 1000
8-
timeout = 60
8+
timeout = 300
99
keepalive = 2
10-
threads = 4
10+
threads = 1
1111
proc_name = 'app01'
1212
bind = '0.0.0.0:8080'
1313
backlog = 2048

hostscript

Lines changed: 0 additions & 5 deletions
This file was deleted.

prod.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
echo "Starting to deploy docker image..."
2+
3+
AWS_REGION=us-east-2
4+
DOCKER_CONTAINER_NAME=chatbox-nlp-api-gunicorn-container
5+
REPOSITORY_URI=038582424441.dkr.ecr.us-east-2.amazonaws.com/chatbox-nlp-api
6+
DEPLOY_DOCKER_COMPOSE_FILE=/home/ec2-user/server/docker-compose.yml
7+
8+
echo "Stopping previous containers..."
9+
docker ps -q --filter "name=$DOCKER_CONTAINER_NAME" | grep -q . && docker stop $DOCKER_CONTAINER_NAME && docker rm -fv $DOCKER_CONTAINER_NAME
10+
if [[ "$(docker images -q $REPOSITORY_URI:latest 2> /dev/null)" != "" ]]; then
11+
docker rmi $REPOSITORY_URI:latest
12+
fi
13+
14+
echo "Deploying new docker image..."
15+
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $REPOSITORY_URI
16+
docker-compose -f $DEPLOY_DOCKER_COMPOSE_FILE up -d
17+
18+
echo "Restarting the web server..."
19+
sudo systemctl reload nginx

run.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ python -m src.dataset.start
44
zip wiki_algos_text.zip src/dataset/general_kb/data/* -j
55

66
# connect and write to the document store
7-
python -m src.haystack.elasticsearch.db > out.txt
7+
python -m src.haystack.elasticsearch.db > out.txt
8+
9+
# refresh the dependency list
10+
pipenv lock -r > requirements.txt

src/api/__init__.py

Whitespace-only changes.

src/api/nginx/default.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
upstream flaskapi {
2+
server 127.0.0.1:8080;
3+
}
4+
5+
server {
6+
listen 80;
7+
8+
access_log /var/log/nginx/be-access.log combined;
9+
10+
location / {
11+
proxy_pass http://flaskapi;
12+
}
13+
}

0 commit comments

Comments
 (0)