Skip to content

Commit 47d0ef8

Browse files
Merge pull request #10 from vectornguyen76/develop
Develop
2 parents 4848e0b + fca0fc4 commit 47d0ef8

File tree

9 files changed

+333
-15
lines changed

9 files changed

+333
-15
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
3+
- name: "configuration play."
4+
hosts: web
5+
user: ubuntu
6+
become: true
7+
gather_facts: false
8+
vars:
9+
- ansible_python_interpreter: /usr/bin/python3
10+
- ansible_host_key_checking: false
11+
- ansible_stdout_callback: yaml
12+
13+
- mlflow_image_name: vectornguyen76/mlflow
14+
- mlflow_tag_name: latest
15+
16+
- model_predictor_image_name: vectornguyen76/model_predictor
17+
- model_predictor_tag_name: latest
18+
pre_tasks:
19+
- name: "wait 600 seconds for target connection to become reachable/usable."
20+
wait_for_connection:
21+
22+
- name: Install aptitude
23+
apt:
24+
name: aptitude
25+
state: latest
26+
update_cache: true
27+
28+
- name: Install required system packages
29+
apt:
30+
pkg:
31+
- apt-transport-https
32+
- ca-certificates
33+
- curl
34+
- software-properties-common
35+
- python3-pip
36+
- virtualenv
37+
- python3-setuptools
38+
state: latest
39+
update_cache: true
40+
41+
- name: Add Docker GPG apt Key
42+
apt_key:
43+
url: https://download.docker.com/linux/ubuntu/gpg
44+
state: present
45+
46+
- name: Add Docker Repository
47+
apt_repository:
48+
repo: deb https://download.docker.com/linux/ubuntu jammy stable
49+
state: present
50+
51+
- name: Update apt and install docker-ce
52+
apt:
53+
name: docker-ce
54+
state: latest
55+
update_cache: true
56+
57+
- name: Install Docker Module for Python
58+
pip:
59+
name: docker
60+
roles:
61+
- deploy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[web]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
- name: "Creates directory"
2+
file:
3+
path: "/home/ubuntu/server"
4+
state: "directory"
5+
mode: 0755
6+
7+
- name: "Copy compressed app folder"
8+
copy:
9+
src: "artifact-app.tar.gz"
10+
dest: "/home/ubuntu/server/artifact-app.tar.gz"
11+
12+
- name: "Extract app"
13+
unarchive:
14+
remote_src: yes
15+
src: "/home/ubuntu/server/artifact-app.tar.gz"
16+
dest: "/home/ubuntu/server"
17+
18+
- name: Pull mlflow image
19+
community.docker.docker_image:
20+
name: "{{ mlflow_image_name }}"
21+
tag: "{{ mlflow_tag_name }}"
22+
source: pull
23+
24+
- name: Pull model_predictor image
25+
community.docker.docker_image:
26+
name: "{{ model_predictor_image_name }}"
27+
tag: "{{ model_predictor_tag_name }}"
28+
source: pull
29+
30+
- name: Run mlflow container
31+
become: True
32+
shell:
33+
chdir: /home/ubuntu/server
34+
cmd: "docker compose -f deployment/mlflow/docker-compose.yml up -d"
35+
36+
- name: Run model_predictor container
37+
become: True
38+
shell:
39+
chdir: /home/ubuntu/server
40+
cmd: "bash deployment/deploy.sh deploy_run_predictor data/model_config/phase-1/prob-1/model-1.yml data/model_config/phase-1/prob-2/model-1.yml 5040"

.github/workflows/development_pipeline.yml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- 5432:5432
2121
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
2222
steps:
23-
- name: Checkout code
23+
- name: Checkout Repository
2424
uses: actions/checkout@v2
2525

2626
- name: Cache Python dependencies
@@ -45,6 +45,7 @@ jobs:
4545
run: python -m flask tests
4646

4747
deploy-service:
48+
needs: build-test
4849
runs-on: ubuntu-latest
4950
env:
5051
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
@@ -53,11 +54,31 @@ jobs:
5354
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
5455
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
5556
steps:
56-
- name: Checkout code
57+
- name: Checkout Repository
5758
uses: actions/checkout@v2
5859

59-
- name: Authenticate Docker Hub
60+
- name: Login to Docker Hub
6061
id: docker_hub_auth
61-
run: docker login -u ${{ env.DOCKERHUB_USERNAME }} -p ${{ env.DOCKERHUB_PASSWORD }}
62+
uses: docker/login-action@v1
63+
with:
64+
username: ${{ secrets.DOCKERHUB_USERNAME }}
65+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
66+
67+
- name: Build Docker Image
68+
id: build_docker
69+
run: |
70+
docker compose build api_service
71+
72+
# Add tag
73+
docker tag api_image:latest ${{ secrets.DOCKERHUB_USERNAME }}/api_image:latest
6274
63-
75+
- name: Push Docker Image
76+
id: push_images
77+
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/api_image:latest
78+
79+
- name: Deploy to AWS CloudFormation
80+
uses: aws-actions/aws-cloudformation-github-deploy@v1
81+
with:
82+
name: MyStackEC2
83+
template: myStack.yaml
84+
parameter-overrides: "MyParam1=myValue,MyParam2=${{ secrets.MY_SECRET_VALUE }}"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"ParameterKey": "VpcCIDR",
4+
"ParameterValue": "10.0.0.0/16"
5+
},
6+
{
7+
"ParameterKey": "PublicSubnetCIDR",
8+
"ParameterValue": "10.0.1.0/24"
9+
},
10+
{
11+
"ParameterKey": "InstanceType",
12+
"ParameterValue": "t3.medium"
13+
},
14+
{
15+
"ParameterKey": "KeyPair",
16+
"ParameterValue": "my-keypair"
17+
},
18+
{
19+
"ParameterKey": "AMItoUse",
20+
"ParameterValue": "ami-053b0d53c279acc90"
21+
}
22+
]

.github/workflows/files/ec2.yml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
AWSTemplateFormatVersion: 2010-09-09
2+
Description: Creates EC2
3+
Parameters:
4+
VpcCIDR:
5+
Description: "VPC range"
6+
Type: String
7+
Default: ""
8+
9+
PublicSubnetCIDR:
10+
Description: "Public subnet CIDR block"
11+
Type: String
12+
Default: ""
13+
14+
InstanceType:
15+
Type: String
16+
Description: "EC2 instance type"
17+
AllowedValues:
18+
- t2.micro
19+
- t3.micro
20+
- t3.medium
21+
22+
KeyPairName:
23+
Description: "AWS key pair in us-east-1, stored in SSM Parameter Store"
24+
Type: String
25+
Default: "my-keypair"
26+
27+
AMItoUse:
28+
Description: AMI to use for our base image - Canonical, Ubuntu, 22.04 LTS, amd64 jammy image build on 2023-05-16
29+
Type: String
30+
Default: "ami-053b0d53c279acc90"
31+
32+
Resources:
33+
VPC:
34+
Type: AWS::EC2::VPC
35+
Properties:
36+
CidrBlock: !Ref VpcCIDR
37+
EnableDnsHostnames: true
38+
EnableDnsSupport: true
39+
Tags:
40+
- Key: Name
41+
Value: "Main VPC"
42+
43+
InternetGateway:
44+
Type: AWS::EC2::InternetGateway
45+
Properties:
46+
Tags:
47+
- Key: Name
48+
Value: Internet Gateway
49+
50+
AttachGateway:
51+
Type: AWS::EC2::VPCGatewayAttachment
52+
Properties:
53+
VpcId: !Ref VPC
54+
InternetGatewayId: !Ref InternetGateway
55+
56+
PublicSubnet:
57+
Type: AWS::EC2::Subnet
58+
Properties:
59+
AvailabilityZone: 'us-east-1a'
60+
VpcId: !Ref VPC
61+
CidrBlock: !Ref PublicSubnetCIDR
62+
Tags:
63+
- Key: Name
64+
Value: "Public Subnet AZ1"
65+
66+
PublicRouteTable:
67+
Type: AWS::EC2::RouteTable
68+
Properties:
69+
VpcId: !Ref VPC
70+
Tags:
71+
- Key: Name
72+
Value: "Public Route Table"
73+
74+
SubnetRouteTableAssociationPub:
75+
Type: AWS::EC2::SubnetRouteTableAssociation
76+
Properties:
77+
SubnetId: !Ref PublicSubnet
78+
RouteTableId: !Ref PublicRouteTable
79+
80+
PublicRouteNATGateway:
81+
Type: AWS::EC2::Route
82+
DependsOn: AttachGateway
83+
Properties:
84+
RouteTableId: !Ref PublicRouteTable
85+
DestinationCidrBlock: '0.0.0.0/0'
86+
GatewayId: !Ref InternetGateway
87+
88+
SecurityGroup:
89+
Type: AWS::EC2::SecurityGroup
90+
Properties:
91+
GroupName: mySecurityGroup
92+
GroupDescription: Allow http to client host
93+
VpcId: !Ref VPC
94+
SecurityGroupIngress:
95+
- IpProtocol: tcp
96+
FromPort: 80
97+
ToPort: 80
98+
CidrIp: 0.0.0.0/0
99+
- IpProtocol: tcp
100+
FromPort: 22
101+
ToPort: 22
102+
CidrIp: 0.0.0.0/0
103+
- IpProtocol: tcp
104+
FromPort: 5000
105+
ToPort: 5000
106+
CidrIp: 0.0.0.0/0
107+
- IpProtocol: tcp
108+
FromPort: 3000
109+
ToPort: 3000
110+
CidrIp: 0.0.0.0/0
111+
- IpProtocol: tcp
112+
FromPort: 5040
113+
ToPort: 5040
114+
CidrIp: 0.0.0.0/0
115+
SecurityGroupEgress:
116+
- IpProtocol: "-1"
117+
FromPort: -1
118+
ToPort: -1
119+
CidrIp: 0.0.0.0/0
120+
Tags:
121+
- Key: Name
122+
Value: SecurityGroup
123+
124+
# Server EC2 Instance
125+
ServerInstance:
126+
Type: AWS::EC2::Instance
127+
Properties:
128+
InstanceType: !Ref InstanceType
129+
ImageId: !Ref AMItoUse
130+
KeyName: !Ref KeyPairName
131+
NetworkInterfaces:
132+
- AssociatePublicIpAddress: true
133+
DeviceIndex: "0"
134+
GroupSet:
135+
- !Ref SecurityGroup
136+
SubnetId: !Ref PublicSubnet
137+
BlockDeviceMappings:
138+
- DeviceName: "/dev/sdk"
139+
Ebs:
140+
VolumeSize: 20
141+
# UserData:
142+
# Fn::Base64: !Sub |
143+
# #!/bin/bash
144+
# sudo apt-get update -y
145+
# sudo apt-get install ca-certificates curl gnupg
146+
# sudo install -m 0755 -d /etc/apt/keyrings
147+
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
148+
# sudo chmod a+r /etc/apt/keyrings/docker.gpg
149+
# echo \
150+
# "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
151+
# "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
152+
# sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
153+
# sudo apt-get update -y
154+
# apt-get install -y docker-ce
155+
# docker run -p 80:8080 tomcat:8.0
156+
Tags:
157+
- Key: Name
158+
Value: ServerInstance
159+
160+
Outputs:
161+
EC2InstanceConnection:
162+
Description: The connection for the EC2 instance
163+
Value: !Join
164+
- ""
165+
- - "ubuntu@"
166+
- !GetAtt ServerInstance.PublicIp
167+
EC2InstancePublicDNS:
168+
Description: The instance public DNS name
169+
Value: !GetAtt ServerInstance.PublicDnsName
170+
Export:
171+
Name: !Join
172+
- ""
173+
- - !Ref AWS::StackName
174+
- "-PublicDNS"

docker-compose.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ services:
2525

2626
nginx_service:
2727
container_name: nginx_container
28-
image: nginx_image
28+
image: nginx:1.25.1-alpine
2929
build:
3030
context: ./server
3131
dockerfile: Dockerfile
3232
ports:
33-
- 8080:80
33+
- 80:80
34+
volumes:
35+
- ./server/default.conf:/etc/nginx/conf.d/default.conf
36+
- ./server/log:/var/log/nginx
3437
depends_on:
3538
- api_service
3639
volumes:

server/Dockerfile

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

0 commit comments

Comments
 (0)