Peiyan commited on
Commit
8202fe8
·
unverified ·
1 Parent(s): 03b7303

Add files via upload

Browse files
deployment/default ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This nginx config should be deployed to server
2
+
3
+
4
+ limit_req_zone $binary_remote_addr zone=mylimit:20m rate=10r/s;
5
+
6
+ ##
7
+ # You should look at the following URL's in order to grasp a solid understanding
8
+ # of Nginx configuration files in order to fully unleash the power of Nginx.
9
+ # https://www.nginx.com/resources/wiki/start/
10
+ # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
11
+ # https://wiki.debian.org/Nginx/DirectoryStructure
12
+ #
13
+ # In most cases, administrators will remove this file from sites-enabled/ and
14
+ # leave it as reference inside of sites-available where it will continue to be
15
+ # updated by the nginx packaging team.
16
+ #
17
+ # This file will automatically load configuration files provided by other
18
+ # applications, such as Drupal or Wordpress. These applications will be made
19
+ # available underneath a path with that package name, such as /drupal8.
20
+ #
21
+ # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
22
+ ##
23
+
24
+ # Default server configuration
25
+ #
26
+ server {
27
+ listen 80 default_server;
28
+ listen [::]:80 default_server;
29
+ proxy_read_timeout 600;
30
+ proxy_connect_timeout 600;
31
+ proxy_send_timeout 600;
32
+ send_timeout 600;
33
+
34
+
35
+
36
+ # SSL configuration
37
+ #
38
+ # listen 443 ssl default_server;
39
+ # listen [::]:443 ssl default_server;
40
+ #
41
+ # Note: You should disable gzip for SSL traffic.
42
+ # See: https://bugs.debian.org/773332
43
+ #
44
+ # Read up on ssl_ciphers to ensure a secure configuration.
45
+ # See: https://bugs.debian.org/765782
46
+ #
47
+ # Self signed certs generated by the ssl-cert package
48
+ # Don't use them in a production server!
49
+ #
50
+ # include snippets/snakeoil.conf;
51
+
52
+ server_name _;
53
+
54
+ location / {
55
+ # First attempt to serve request as file, then
56
+ # as directory, then fall back to displaying a 404.
57
+ limit_req zone=mylimit;
58
+
59
+ proxy_pass http://127.0.0.1:3000/;
60
+ }
61
+
62
+ # pass PHP scripts to FastCGI server
63
+ #
64
+ #location ~ \.php$ {
65
+ # include snippets/fastcgi-php.conf;
66
+ #
67
+ # # With php-fpm (or other unix sockets):
68
+ # fastcgi_pass unix:/run/php/php7.4-fpm.sock;
69
+ # # With php-cgi (or other tcp sockets):
70
+ # fastcgi_pass 127.0.0.1:9000;
71
+ #}
72
+
73
+ # deny access to .htaccess files, if Apache's document root
74
+ # concurs with nginx's one
75
+ #
76
+ #location ~ /\.ht {
77
+ # deny all;
78
+ #}
79
+ }
80
+
81
+
82
+ # Virtual Host configuration for example.com
83
+ #
84
+ # You can move that to a different file under sites-available/ and symlink that
85
+ # to sites-enabled/ to enable it.
86
+ #
87
+ #server {
88
+ # listen 80;
89
+ # listen [::]:80;
90
+ #
91
+ # server_name example.com;
92
+ #
93
+ # root /var/www/example.com;
94
+ # index index.html;
95
+ #
96
+ # location / {
97
+ # try_files $uri $uri/ =404;
98
+ # }
99
+ #}
100
+
101
+ server {
102
+
103
+ # SSL configuration
104
+ #
105
+ # listen 443 ssl default_server;
106
+ # listen [::]:443 ssl default_server;
107
+ #
108
+ # Note: You should disable gzip for SSL traffic.
109
+ # See: https://bugs.debian.org/773332
110
+ #
111
+ # Read up on ssl_ciphers to ensure a secure configuration.
112
+ # See: https://bugs.debian.org/765782
113
+ #
114
+ # Self signed certs generated by the ssl-cert package
115
+ # Don't use them in a production server!
116
+ #
117
+ # include snippets/snakeoil.conf;
118
+
119
+ server_name guardai.io www.guardai.io; # managed by Certbot
120
+ proxy_read_timeout 600;
121
+ proxy_connect_timeout 600;
122
+ proxy_send_timeout 600;
123
+ send_timeout 600;
124
+
125
+
126
+
127
+ location / {
128
+ # First attempt to serve request as file, then
129
+ # as directory, then fall back to displaying a 404.
130
+ limit_req zone=mylimit;
131
+
132
+ proxy_pass http://127.0.0.1:3000/;
133
+ }
134
+
135
+ # pass PHP scripts to FastCGI server
136
+ #
137
+ #location ~ \.php$ {
138
+ # include snippets/fastcgi-php.conf;
139
+ #
140
+ # # With php-fpm (or other unix sockets):
141
+ # fastcgi_pass unix:/run/php/php7.4-fpm.sock;
142
+ # # With php-cgi (or other tcp sockets):
143
+ # fastcgi_pass 127.0.0.1:9000;
144
+ #}
145
+
146
+ # deny access to .htaccess files, if Apache's document root
147
+ # concurs with nginx's one
148
+ #
149
+ #location ~ /\.ht {
150
+ # deny all;
151
+ #}
152
+
153
+
154
+ listen [::]:443 ssl ipv6only=on; # managed by Certbot
155
+ listen 443 ssl; # managed by Certbot
156
+ ssl_certificate /etc/letsencrypt/live/guardai.io/fullchain.pem; # managed by Certbot
157
+ ssl_certificate_key /etc/letsencrypt/live/guardai.io/privkey.pem; # managed by Certbot
158
+ include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
159
+ ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
160
+
161
+
162
+
163
+ }
164
+ server {
165
+ if ($host = www.guardai.io) {
166
+ return 301 https://$host$request_uri;
167
+ } # managed by Certbot
168
+
169
+
170
+ if ($host = guardai.io) {
171
+ return 301 https://$host$request_uri;
172
+ } # managed by Certbot
173
+
174
+
175
+ listen 80 ;
176
+ listen [::]:80 ;
177
+ server_name guardai.io www.guardai.io;
178
+ return 404; # managed by Certbot
179
+ }
deployment/docker/nginx.conf ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ server {
2
+ listen 80 default_server;
3
+ server_name guardai.io www.guardai.io;
4
+
5
+ root /usr/share/nginx/html;
6
+ client_max_body_size 100M;
7
+ proxy_read_timeout 600;
8
+ proxy_connect_timeout 600;
9
+ proxy_send_timeout 600;
10
+ send_timeout 600;
11
+
12
+ # proxy api requests to flask server
13
+ location /api/ {
14
+ proxy_pass http://127.0.0.1:5000/;
15
+ }
16
+
17
+ location / {
18
+ try_files $uri /index.html;
19
+ }
20
+ }
21
+
deployment/docker/serve.sh ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/bin/bash
2
+ nohup nginx -g "daemon off;" & cd backend && gunicorn -b 0.0.0.0:5000 --workers=3 -t 600 "app:app" "$1"
deployment/eks-cluster/README.md ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Provision
2
+
3
+ Create EKS cluster
4
+ ```
5
+ eksctl create cluster -f cluster.yaml
6
+ ```
7
+
8
+ Install LB Controller dependencies
9
+ ```
10
+ https://docs.aws.amazon.com/eks/latest/userguide/aws-load-balancer-controller.html
11
+ ```
12
+
13
+ Provision Ingress service
14
+ ```
15
+ kubectl create -f manifest/ingress.yaml
16
+ ```
17
+
18
+ Provide docker registry secret
19
+ ```
20
+ kubectl create secret docker-registry guardai-registry-key \
21
+ --docker-server=DOCKER_REGISTRY_SERVER \
22
+ --docker-username=DOCKER_USER \
23
+ --docker-password=DOCKER_PASSWORD \
24
+ --docker-email=DOCKER_EMAIL
25
+ ```
26
+
27
+ Update Docker image in deployment chart if needed, then
28
+ ```
29
+ helm install guardai ./helm/guardai/
30
+ ```
31
+
32
+
33
+ Clean up
34
+ ```
35
+ eksctl delete cluster --name cluster.k8s.local
36
+ ```
deployment/eks-cluster/cluster.yaml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ apiVersion: eksctl.io/v1alpha5
2
+ kind: ClusterConfig
3
+
4
+ metadata:
5
+ name: cluster.k8s.local
6
+ region: us-east-2
7
+ version: "1.29"
8
+ tags:
9
+ guardai: eks-cluster
10
+ vpc:
11
+ id: "vpc-99d8b3f2"
12
+ cidr: "172.31.0.0/16"
13
+ nat:
14
+ gateway: Disable
15
+ subnets:
16
+ private:
17
+ us-east-2a:
18
+ id: "subnet-64d6440f"
19
+ us-east-2b:
20
+ id: "subnet-d9ca02a4"
21
+ managedNodeGroups:
22
+ - name: ng-1
23
+ instanceType: c5.large
24
+ desiredCapacity: 5
25
+ volumeSize: 10
26
+ minSize: 5
27
+ maxSize: 5
28
+ availabilityZones:
29
+ - us-east-2a
30
+ privateNetworking: true # Set to true if you want the node group to use private subnets only
31
+ tags:
32
+ guardai: eks-cluster
deployment/eks-cluster/helm/guardai/Chart.yaml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ apiVersion: v1
2
+ appVersion: "1.0"
3
+ description: A Helm chart for Kubernetes
4
+ name: guardai
5
+ version: 0.1.0
deployment/eks-cluster/helm/guardai/templates/_helpers.tpl ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{/* vim: set filetype=mustache: */}}
2
+ {{/*
3
+ Expand the name of the chart.
4
+ */}}
5
+ {{- define "login.name" -}}
6
+ {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7
+ {{- end -}}
8
+
9
+ {{/*
10
+ Create a default fully qualified app name.
11
+ We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12
+ If release name contains chart name it will be used as a full name.
13
+ */}}
14
+ {{- define "login.fullname" -}}
15
+ {{- if .Values.fullnameOverride -}}
16
+ {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17
+ {{- else -}}
18
+ {{- $name := default .Chart.Name .Values.nameOverride -}}
19
+ {{- if contains $name .Release.Name -}}
20
+ {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21
+ {{- else -}}
22
+ {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23
+ {{- end -}}
24
+ {{- end -}}
25
+ {{- end -}}
26
+
27
+ {{/*
28
+ Create chart name and version as used by the chart label.
29
+ */}}
30
+ {{- define "login.chart" -}}
31
+ {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32
+ {{- end -}}
deployment/eks-cluster/helm/guardai/templates/configMap.yaml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ apiVersion: v1
2
+ kind: ConfigMap
3
+ metadata:
4
+ name: guardai-config
deployment/eks-cluster/helm/guardai/templates/deployment.yaml ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ apiVersion: apps/v1
2
+ kind: Deployment
3
+ metadata:
4
+ name: guardai-deployment
5
+ labels:
6
+ app: guardai
7
+ spec:
8
+ replicas: 12 # specify number of replicated Pods
9
+ selector:
10
+ matchLabels:
11
+ app: guardai
12
+
13
+ template:
14
+ metadata:
15
+ labels:
16
+ app: guardai
17
+
18
+ spec:
19
+ containers:
20
+ - name: guardai-container
21
+ image: paulcccccch/trustworthy-ai:latest
22
+ ports:
23
+ - containerPort: 8300
24
+ envFrom:
25
+ - configMapRef:
26
+ name: guardai-config
27
+ resources:
28
+ requests:
29
+ cpu: 500m
30
+ imagePullSecrets:
31
+ - name: guardai-registry-key
32
+
33
+ ---
34
+ apiVersion: autoscaling/v1
35
+ kind: HorizontalPodAutoscaler
36
+ metadata:
37
+ name: guardai-autoscaling
38
+ namespace: default
39
+ spec:
40
+ scaleTargetRef:
41
+ apiVersion: apps/v1
42
+ kind: Deployment
43
+ name: guardai-deployment
44
+ minReplicas: 12
45
+ maxReplicas: 18
46
+ targetCPUUtilizationPercentage: 50
deployment/eks-cluster/helm/guardai/templates/service.yaml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: guardai-service
5
+ annotations:
6
+ service.beta.kubernetes.io/aws-load-balancer-type: nlb
7
+ spec:
8
+ type: LoadBalancer
9
+ selector:
10
+ app: guardai
11
+ ports:
12
+ - protocol: TCP
13
+ port: 80
14
+ targetPort: 80
deployment/eks-cluster/helm/guardai/values.yaml ADDED
File without changes
deployment/eks-cluster/manifest/ingress.yaml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ apiVersion: networking.k8s.io/v1
2
+ kind: Ingress
3
+ metadata:
4
+ name: guardai-ingress
5
+ annotations:
6
+ alb.ingress.kubernetes.io/scheme: internet-facing
7
+ alb.ingress.kubernetes.io/target-type: ip
8
+ alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}, {"HTTP":80}]'
9
+ alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-2:172265936747:certificate/2f7081c3-b900-4aff-a321-a578e789655b
10
+ alb.ingress.kubernetes.io/ssl-redirect: "443"
11
+ spec:
12
+ ingressClassName: alb
13
+ defaultBackend:
14
+ service:
15
+ name: cloud
16
+ port: guardai-service
17
+ number: 80
18
+
19
+ # rules:
20
+ # - http:
21
+ # paths:
22
+ # - path: /
23
+ # pathType: Prefix
24
+ # backend:
25
+ # service:
26
+ # name: guardai-service
27
+ # port:
28
+ # number: 80
deployment/single-instance/README.md ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Provision
2
+ Run `terraform apply`
deployment/single-instance/main.tf ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Provides a resource to manage EC2 Fleets.
2
+ #
3
+ # Usage:
4
+ # Configure the credentials first with `aws configure`
5
+ # Create a file named `terraform.tfvars` and set the values of the variables defined in `variables.tf`
6
+ #
7
+ # terraform init Initialize a Terraform working directory
8
+ # terraform validate Validates the Terraform files
9
+ # terraform fmt Rewrites config files to canonical format
10
+ # terraform plan Generate and show an execution plan
11
+ # terraform apply Builds or changes infrastructure
12
+ # terraform destroy Destroy Terraform-managed infrastructure
13
+
14
+ provider "aws" {
15
+ region = var.region
16
+ }
17
+
18
+ locals {
19
+ common_tags = {
20
+ Name = "guardai"
21
+ project = var.project_tag
22
+ }
23
+ }
24
+
25
+ resource "aws_security_group" "guardai_ami_sg" {
26
+ ingress {
27
+ from_port = 22
28
+ to_port = 22
29
+ protocol = "tcp"
30
+
31
+ cidr_blocks = [
32
+ "0.0.0.0/0",
33
+ ]
34
+ }
35
+
36
+ ingress {
37
+ from_port = 80
38
+ to_port = 80
39
+ protocol = "tcp"
40
+
41
+ cidr_blocks = [
42
+ "0.0.0.0/0",
43
+ ]
44
+ }
45
+
46
+ ingress {
47
+ from_port = 443
48
+ to_port = 443
49
+ protocol = "tcp"
50
+
51
+ cidr_blocks = [
52
+ "0.0.0.0/0",
53
+ ]
54
+ }
55
+
56
+
57
+ # outbound internet access
58
+ # allowed: any egress traffic to anywhere
59
+ egress {
60
+ from_port = 0
61
+ to_port = 0
62
+ protocol = "-1"
63
+
64
+ cidr_blocks = [
65
+ "0.0.0.0/0",
66
+ ]
67
+ }
68
+
69
+ tags = local.common_tags
70
+ }
71
+
72
+ # Provides an EC2 launch template resource.
73
+ # Can be used to create EC2 instances or auto scaling groups.
74
+ resource "aws_launch_template" "guardai_ami_lt" {
75
+ name_prefix = "guard_ai_launch_template"
76
+ image_id = var.ami_id
77
+ key_name = var.key_name
78
+
79
+ vpc_security_group_ids = [
80
+ aws_security_group.guardai_ami_sg.id,
81
+ ]
82
+
83
+ instance_type = var.instance_type
84
+
85
+ tag_specifications {
86
+ # Tags of EC2 instances
87
+ resource_type = "instance"
88
+ tags = local.common_tags
89
+ }
90
+
91
+ tag_specifications {
92
+ # Tags of EBS volumes
93
+ resource_type = "volume"
94
+ tags = local.common_tags
95
+ }
96
+ }
97
+
98
+
99
+ # Assign elastic IP to the instance
100
+ resource "aws_eip_association" "eip_assoc" {
101
+ instance_id = aws_instance.main_instance.id
102
+ allocation_id = var.eip_id
103
+ }
104
+
105
+
106
+ # Launch an EC2 instance
107
+ resource "aws_instance" "main_instance" {
108
+ launch_template {
109
+ id = aws_launch_template.guardai_ami_lt.id
110
+ version = "$Latest"
111
+ }
112
+
113
+ # The tags of the Fleet resource itself.
114
+ # To tag instances at launch, specify the tags in the Launch Template.
115
+ tags = local.common_tags
116
+ availability_zone = var.zone
117
+ }
deployment/single-instance/terraform.tfvars ADDED
File without changes
deployment/single-instance/variables.tf ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ variable "region" {
3
+ default = "us-east-2"
4
+ }
5
+
6
+ variable "zone" {
7
+ default = "us-east-2a"
8
+ }
9
+
10
+ # instance type
11
+ variable "instance_type" {
12
+ default = "t3.medium"
13
+ }
14
+
15
+ variable "bid_price" {
16
+ default = "0.013"
17
+ }
18
+
19
+ variable "target_capacity_type" {
20
+ default = "on-demand"
21
+ }
22
+
23
+ # Update "project_tag" to match the tagging requirement of the ongoing project
24
+ variable "project_tag" {
25
+ default = "single-instance"
26
+ }
27
+
28
+ # Update "ami_id"
29
+ variable "ami_id" {
30
+ default = "ami-05fb0b8c1424f266b"
31
+ }
32
+
33
+ # Update "key_name" with the key pair name for SSH connection
34
+ # Note: it is NOT the path of the pem file
35
+ # you can find it in https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#KeyPairs:sort=keyName
36
+ variable "key_name" {
37
+ default = "aws-key1"
38
+ }
39
+
40
+ variable "eip_id" {
41
+ default = "eipalloc-02216567b103be40a"
42
+ }