Skip to content

Commit 8733fc9

Browse files
committed
updated the dockerfile to only include necessary folders
1 parent 6e5f4b8 commit 8733fc9

2 files changed

Lines changed: 111 additions & 3 deletions

File tree

.github/workflows/main.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- 'README.md'
9+
10+
permissions:
11+
id-token: write
12+
contents: read
13+
14+
jobs:
15+
integration:
16+
name: Continuous Integration
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout Code
20+
uses: actions/checkout@v3
21+
22+
- name: Lint code
23+
run: echo "Linting repository"
24+
25+
- name: Run unit tests
26+
run: echo "Running unit tests"
27+
28+
build-and-push-ecr-image:
29+
name: Continuous Delivery
30+
needs: integration
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout Code
34+
uses: actions/checkout@v3
35+
36+
- name: Install Utilities
37+
run: |
38+
sudo apt-get update
39+
sudo apt-get install -y jq unzip
40+
- name: Configure AWS credentials
41+
uses: aws-actions/configure-aws-credentials@v1
42+
with:
43+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
44+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
45+
aws-region: ${{ secrets.AWS_REGION }}
46+
47+
- name: Login to Amazon ECR
48+
id: login-ecr
49+
uses: aws-actions/amazon-ecr-login@v1
50+
51+
- name: Build, tag, and push image to Amazon ECR
52+
id: build-image
53+
env:
54+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
55+
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }}
56+
IMAGE_TAG: latest
57+
run: |
58+
# Build a docker container and
59+
# push it to ECR so that it can
60+
# be deployed to ECS.
61+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
62+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
63+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
64+
65+
66+
Continuous-Deployment:
67+
needs: build-and-push-ecr-image
68+
runs-on: self-hosted
69+
steps:
70+
- name: Checkout
71+
uses: actions/checkout@v3
72+
73+
- name: Configure AWS credentials
74+
uses: aws-actions/configure-aws-credentials@v1
75+
with:
76+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
77+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
78+
aws-region: ${{ secrets.AWS_REGION }}
79+
80+
- name: Login to Amazon ECR
81+
id: login-ecr
82+
uses: aws-actions/amazon-ecr-login@v1
83+
84+
85+
- name: Pull latest images
86+
run: |
87+
docker pull ${{secrets.AWS_ECR_LOGIN_URI}}/${{ secrets.ECR_REPOSITORY_NAME }}:latest
88+
89+
# - name: Stop and remove container if running
90+
# run: |
91+
# docker ps -q --filter "name=mltest" | grep -q . && docker stop mltest && docker rm -fv mltest
92+
93+
- name: Run Docker Image to serve users
94+
run: |
95+
docker run -d -p 8080:8080 --ipc="host" --name=mltest -e 'AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}' -e 'AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}' -e 'AWS_REGION=${{ secrets.AWS_REGION }}' ${{secrets.AWS_ECR_LOGIN_URI}}/${{ secrets.ECR_REPOSITORY_NAME }}:latest
96+
- name: Clean previous images and containers
97+
run: |
98+
docker system prune -f

Dockerfile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
FROM python:3.9-alpine
22
WORKDIR /app
3-
COPY . /app
43

5-
RUN apt update -y && apt install awscli -y
4+
# Copy only required files and folders
5+
COPY app.py /app/
6+
COPY requirements.txt /app/
7+
COPY artifacts/ /app/artifacts/
8+
COPY src/ /app/src/
9+
COPY static/ /app/static/
10+
COPY templates/ /app/templates/
11+
12+
# Install OS dependencies
13+
RUN apk update && apk add --no-cache ffmpeg libsm6 libxext6 unzip aws-cli
14+
15+
# Install Python dependencies
16+
RUN pip install --no-cache-dir -r requirements.txt
617

7-
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 unzip -y && pip install -r requirements.txt
818
CMD ["python3", "app.py"]

0 commit comments

Comments
 (0)