Skip to content

Commit e7ca545

Browse files
committed
Add CI/CD workflow for Docker deployment and update environment variables in README and constants
1 parent 4f74390 commit e7ca545

5 files changed

Lines changed: 80 additions & 4 deletions

File tree

.github/workflows/cicd.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Deploy Application Docker Image to EC2 instance
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
Continuous-Integration:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: Configure AWS credentials
16+
uses: aws-actions/configure-aws-credentials@v1
17+
with:
18+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
19+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
20+
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
21+
22+
- name: Login to Amazon ECR
23+
id: login-ecr
24+
uses: aws-actions/amazon-ecr-login@v1
25+
26+
- name: Build, tag, and push image to Amazon ECR
27+
id: build-image
28+
env:
29+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
30+
ECR_REPOSITORY: ${{ secrets.ECR_REPO }}
31+
IMAGE_TAG: latest
32+
run: |
33+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
34+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
35+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
36+
37+
Continuous-Deployment:
38+
needs: Continuous-Integration
39+
runs-on: self-hosted
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v3
43+
44+
- name: Configure AWS credentials
45+
uses: aws-actions/configure-aws-credentials@v1
46+
with:
47+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
48+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
49+
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
50+
51+
- name: Login to Amazon ECR
52+
id: login-ecr
53+
uses: aws-actions/amazon-ecr-login@v1
54+
55+
- name: Run Docker Image to serve users
56+
run: |
57+
docker run -d -e AWS_ACCESS_KEY_ID="${{ secrets.AWS_ACCESS_KEY_ID }}" -e AWS_SECRET_ACCESS_KEY="${{ secrets.AWS_SECRET_ACCESS_KEY }}" -e AWS_DEFAULT_REGION="${{ secrets.AWS_DEFAULT_REGION }}" -e MONGODB_CLUSTER_URI="${{ secrets.MONGODB_CLUSTER_URI}}" -p 8080:8080 "${{ steps.login-ecr.outputs.registry }}"/"${{ secrets.ECR_REPO }}":latest

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:3.7-slim-buster
2+
3+
EXPOSE 8501
4+
5+
RUN apt-get update && apt-get install -y \
6+
build-essential \
7+
software-properties-common \
8+
git \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
WORKDIR /app
12+
13+
COPY . /app
14+
15+
RUN pip3 install -r requirements.txt
16+
17+
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ Create a `.env` file in the root directory:
168168
```
169169
AWS_ACCESS_KEY_ID=<your_aws_key>
170170
AWS_SECRET_ACCESS_KEY=<your_secret_key>
171-
mongodb_cluster_uri=<your_mongo_connection_string>
172-
BUCKET_NAME=usvisabucket-mlpos
171+
MONGODB_CLUSTER_URI=<your_mongo_connection_string>
172+
BUCKET_NAME=<your_s3_bucket_name>
173+
AWS_DEFAULT_REGION=<your_aws_region>
174+
ECR_REPO=<your_ecr_url>
173175
```
174176

175177
---

notebooks/mongoDB_test.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12294,7 +12294,7 @@
1229412294
"\n",
1229512295
"DB_NAME = \"US_VISA\"\n",
1229612296
"COLLECTION_NAME = \"visa_data\"\n",
12297-
"CONNECTION_URL = os.getenv(\"mongodb_cluster_uri\")\n",
12297+
"CONNECTION_URL = os.getenv(\"MONGODB_CLUSTER_URI\")\n",
1229812298
"print(CONNECTION_URL)"
1229912299
]
1230012300
},

us_visa/constants/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
COLLECTION_NAME = "visa_data"
77

8-
MONGODB_URL_KEY = "mongodb_cluster_uri"
8+
MONGODB_URL_KEY = "MONGODB_CLUSTER_URI"
99

1010
PIPELINE_NAME: str = "usvisa"
1111
ARTIFACT_DIR: str = "artifact"

0 commit comments

Comments
 (0)