forked from doccano/doccano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.aws.yaml
156 lines (153 loc) · 4.31 KB
/
template.aws.yaml
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
AWSTemplateFormatVersion: 2010-09-09
Description: "Deploy doccano on AWS EC2"
Parameters:
Username:
Description: "The username of the superuser"
Type: String
Default: "admin"
Password:
Description: "The password of the superuser"
Type: String
Default: "password"
NoEcho: true
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
Type: AWS::EC2::KeyPair::KeyName
ConstraintDescription: must be the name of an existing EC2 KeyPair.
InstanceType:
Description: WebServer EC2 instance type
Type: String
Default: t2.small
AllowedValues:
- t2.micro
- t2.small
- t2.medium
- t2.large
ConstraintDescription: must be a valid EC2 instance type.
LatestAmiId:
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "doccano Configuration"
Parameters:
- Username
- Password
- Label:
default: "EC2 Configuration"
Parameters:
- KeyName
- InstanceType
Resources:
VPC:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: "10.0.0.0/16"
EnableDnsHostnames: true
EnableDnsSupport: true
InstanceTenancy: default
Tags:
- Key: Name
Value: doccanoVPC
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: doccano-igw
AttachGateway:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
PublicSubnet:
Type: "AWS::EC2::Subnet"
Properties:
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: { Ref: "AWS::Region" }
CidrBlock: "10.0.1.0/24"
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: doccano-public-subnet
VpcId: !Ref VPC
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: doccanoRouteTable
PublicRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: "0.0.0.0/0"
GatewayId: !Ref InternetGateway
PublicRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnet
RouteTableId: !Ref PublicRouteTable
EC2SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: "doccano-ec2-sg"
GroupDescription: "Security Group for doccano"
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: "80"
ToPort: "80"
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: "22"
ToPort: "22"
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: doccano-ec2-sg
EC2Instance:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: { Ref: "AWS::Region" }
KeyName: !Ref KeyName
ImageId: !Ref LatestAmiId
InstanceType: !Ref InstanceType
Monitoring: true
SecurityGroupIds:
- !Ref EC2SecurityGroup
SubnetId: !Ref PublicSubnet
UserData:
Fn::Base64: !Sub |
#!/bin/bash -ex
yum update -y
# Install Docker
yum install -y docker
systemctl enable docker
service docker start
# Install docker compose
curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
# Install git
yum install -y git
git clone https://github.com/doccano/doccano.git
cd doccano
sed -i s/"admin"/${Username}/g docker-compose.prod.yml
sed -i s/"password"/${Password}/g docker-compose.prod.yml
docker-compose -f docker-compose.prod.yml up -d
Tags:
- Key: Name
Value: doccano
Outputs:
PublicDNS:
Description: EC2 public DNS
Value: !GetAtt EC2Instance.PublicDnsName