forked from doccano/doccano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
awsdeploy.yml
313 lines (296 loc) · 8.58 KB
/
awsdeploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
AWSTemplateFormatVersion: 2010-09-09
Description: AWS CloudFormation Template for doccano.
Resources:
AppSG:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: 'for the app nodes that allow ssh, http and docker ports'
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
Metadata:
'AWS::CloudFormation::Designer':
id: 116a7f7b-14c5-489a-a3c8-faf276be7ab0
App:
Type: 'AWS::EC2::Instance'
Properties:
InstanceType: !Ref InstanceType
ImageId: !Ref Ubuntu16Ami
KeyName: !Ref KeyName
SecurityGroups:
- !Ref AppSG
UserData: !Base64
'Fn::Join':
- ''
- - |
#!/usr/bin/env bash
- |
sudo apt update
- >
sudo apt install -y apt-transport-https ca-certificates curl
software-properties-common
- >
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo
apt-key add -
- >
sudo add-apt-repository "deb [arch=amd64]
https://download.docker.com/linux/ubuntu bionic stable"
- |
sudo apt update
- |
apt-cache policy docker-ce
- |
sudo apt install -y docker-ce
- |
sudo usermod -aG docker ${USER}
- |
touch /env.list
- sudo tee -a /env.list <<< ADMIN=
- !Ref AdminUserName
- |+
- sudo tee -a /env.list <<< EMAIL=
- !Ref AdminEmail
- |+
- sudo tee -a /env.list <<< PASSWORD=
- !Ref AdminPassword
- |+
- sudo tee -a /env.list <<< DEBUG=
- !Ref Debug
- |+
- sudo tee -a /env.list <<< SECRET_KEY=
- !Ref SecretKey
- |+
- sudo tee -a /env.list <<< EMAIL_USE_TLS=
- !Ref EMailUseTSL
- |+
- sudo tee -a /env.list <<< EMAIL_HOST=
- !Ref EMailHost
- |+
- sudo tee -a /env.list <<< EMAIL_PORT=
- !Ref EMailHostPort
- |+
- sudo tee -a /env.list <<< EMAIL_HOST_USER=
- !Ref EMailHostUser
- |+
- sudo tee -a /env.list <<< EMAIL_HOST_PASSWORD=
- !Ref EMailHostPassword
- |+
- sudo tee -a /env.list <<< WORKERS=
- !Ref WorkersCount
- |+
- sudo tee -a /env.list <<< DEFAULT_FROM_EMAIL=
- !Ref FromEmail
- |+
- sudo tee -a /env.list <<< DOCKER_IMAGE=
- !Ref DockerImageName
- |+
- |
set -a
- |
source /env.list
- |
set +a
- |
sudo docker pull ${DOCKER_IMAGE}
- >
sudo docker run -d --name doccano --env-file /env.list -p 80:8000
${DOCKER_IMAGE}
- >
sleep 3 && sudo docker exec doccano tools/create-admin.sh ${ADMIN} ${EMAIL}
${PASSWORD}
Metadata:
'AWS::CloudFormation::Designer':
id: 3547c02e-5393-4b26-a9af-6f00dc2cbcdb
DescribeImagesRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: lambda.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: DescribeImages
PolicyDocument:
Version: '2012-10-17'
Statement:
- Action: ec2:DescribeImages
Effect: Allow
Resource: "*"
GetLatestAMI:
Type: AWS::Lambda::Function
Properties:
Runtime: python3.6
Handler: index.handler
Role: !Sub ${DescribeImagesRole.Arn}
Timeout: 60
Code:
ZipFile: |
import boto3
import cfnresponse
import json
import traceback
def handler(event, context):
try:
response = boto3.client('ec2').describe_images(
Owners=[event['ResourceProperties']['Owner']],
Filters=[
{'Name': 'name', 'Values': [event['ResourceProperties']['Name']]},
{'Name': 'architecture', 'Values': [event['ResourceProperties']['Architecture']]},
{'Name': 'root-device-type', 'Values': ['ebs']},
],
)
amis = sorted(response['Images'],
key=lambda x: x['CreationDate'],
reverse=True)
id = amis[0]['ImageId']
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, id)
except:
traceback.print_last()
cfnresponse.send(event, context, cfnresponse.FAIL, {}, "ok")
Ubuntu16Ami:
Type: Custom::FindAMI
Properties:
ServiceToken: !Sub ${GetLatestAMI.Arn}
Owner: "099720109477"
Name: "ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20190913"
Architecture: "x86_64"
Metadata:
'AWS::CloudFormation::Designer':
116a7f7b-14c5-489a-a3c8-faf276be7ab0:
size:
width: 60
height: 60
position:
x: 60
'y': 210
z: 1
embeds: []
3547c02e-5393-4b26-a9af-6f00dc2cbcdb:
size:
width: 60
height: 60
position:
x: 180
'y': 210
z: 1
embeds: []
isassociatedwith:
- 116a7f7b-14c5-489a-a3c8-faf276be7ab0
Parameters:
InstanceType:
Description: Server EC2 instance type
Type: String
Default: t2.micro
AllowedValues:
- t1.micro
- t2.micro
- t2.small
- t2.medium
- t3.micro
- t3.small
- t3.medium
ConstraintDescription: must be a valid EC2 instance type.
KeyName:
Description: Name of an EC2 KeyPair to enable SSH access to the instance.
Type: 'AWS::EC2::KeyPair::KeyName'
ConstraintDescription: must be the name of an existing EC2 KeyPair.
AdminUserName:
Description: The admin account user name
Default: 'admin'
Type: String
MinLength: 1
MaxLength: 16
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
AdminEmail:
Default: [email protected]
Description: The admin account user email
Type: String
AllowedPattern: '^[\x20-\x45]?[\w-\+]+(\.[\w]+)*@[\w-]+(\.[\w]+)*(\.[a-z]{2,})$'
AdminPassword:
Description: The admin account password
Type: String
NoEcho: true
MinLength: 1
MaxLength: 16
AllowedPattern: '^[a-zA-Z0-9]*$'
Debug:
Default: 'False'
AllowedValues:
- 'False'
- 'True'
Description: Debug mode or not
Type: String
AllowedPattern: '^[a-zA-Z0-9]*$'
SecretKey:
Default: zICc59rlKXmlFRpG
Description: Secret key for Django
Type: String
AllowedPattern: '^[a-zA-Z0-9]*$'
EMailUseTSL:
Default: 'False'
AllowedValues:
- 'False'
- 'True'
Description: SMTP will use TSL
Type: String
AllowedPattern: '^[a-zA-Z0-9]*$'
EMailHost:
Description: SMTP Host
Type: String
AllowedPattern: '^[\w-]+(\.[\w-]+)*(\.[a-z]{2,})$'
EMailHostUser:
Description: SMTP Host User
Type: String
MinLength: 1
MaxLength: 25
AllowedPattern: '^[a-zA-Z0-9][a-zA-Z0-9]{1,25}$'
EMailHostPassword:
Description: SMTP Host User password
Type: String
NoEcho: true
MinLength: 0
MaxLength: 60
AllowedPattern: '^\p{Graph}+$'
EMailHostPort:
Description: SMTP Port
Type: String
MinLength: 1
MaxLength: 5
AllowedPattern: '^\d+$'
WorkersCount:
Description: Workers Count
Type: String
MinLength: 1
MaxLength: 3
AllowedPattern: '^\d+$'
FromEmail:
Default: webmaster@localhost
Description: The email used to send from singup messages
Type: String
AllowedPattern: '^[\x20-\x45]?[\w-\+]+(\.[\w]+)*@[\w-]+(\.[\w]+)*(\.[a-z]{2,})?$'
DockerImageName:
Default: doccano/doccano:latest
Description: The Docker image name
Type: String
AllowedPattern: '^[\w_-]+/[\w_-]+:[\w_-]+$'
Outputs:
PublicDNS:
Value: !GetAtt
- App
- PublicDnsName
Description: Newly created server DNS address