You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
4.3 KiB

  1. AWSTemplateFormatVersion: 2010-09-09
  2. Description: "Deploy doccano on AWS EC2"
  3. Parameters:
  4. Username:
  5. Description: "The username of the superuser"
  6. Type: String
  7. Default: "admin"
  8. Password:
  9. Description: "The password of the superuser"
  10. Type: String
  11. Default: "password"
  12. NoEcho: true
  13. KeyName:
  14. Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
  15. Type: AWS::EC2::KeyPair::KeyName
  16. ConstraintDescription: must be the name of an existing EC2 KeyPair.
  17. InstanceType:
  18. Description: WebServer EC2 instance type
  19. Type: String
  20. Default: t2.small
  21. AllowedValues:
  22. - t2.micro
  23. - t2.small
  24. - t2.medium
  25. - t2.large
  26. ConstraintDescription: must be a valid EC2 instance type.
  27. LatestAmiId:
  28. Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
  29. Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
  30. Metadata:
  31. AWS::CloudFormation::Interface:
  32. ParameterGroups:
  33. - Label:
  34. default: "doccano Configuration"
  35. Parameters:
  36. - Username
  37. - Password
  38. - Label:
  39. default: "EC2 Configuration"
  40. Parameters:
  41. - KeyName
  42. - InstanceType
  43. Resources:
  44. VPC:
  45. Type: "AWS::EC2::VPC"
  46. Properties:
  47. CidrBlock: "10.0.0.0/16"
  48. EnableDnsHostnames: true
  49. EnableDnsSupport: true
  50. InstanceTenancy: default
  51. Tags:
  52. - Key: Name
  53. Value: doccanoVPC
  54. InternetGateway:
  55. Type: AWS::EC2::InternetGateway
  56. Properties:
  57. Tags:
  58. - Key: Name
  59. Value: doccano-igw
  60. AttachGateway:
  61. Type: AWS::EC2::VPCGatewayAttachment
  62. Properties:
  63. VpcId: !Ref VPC
  64. InternetGatewayId: !Ref InternetGateway
  65. PublicSubnet:
  66. Type: "AWS::EC2::Subnet"
  67. Properties:
  68. AvailabilityZone:
  69. Fn::Select:
  70. - 0
  71. - Fn::GetAZs: { Ref: "AWS::Region" }
  72. CidrBlock: "10.0.1.0/24"
  73. MapPublicIpOnLaunch: true
  74. Tags:
  75. - Key: Name
  76. Value: doccano-public-subnet
  77. VpcId: !Ref VPC
  78. PublicRouteTable:
  79. Type: AWS::EC2::RouteTable
  80. Properties:
  81. VpcId: !Ref VPC
  82. Tags:
  83. - Key: Name
  84. Value: doccanoRouteTable
  85. PublicRoute:
  86. Type: AWS::EC2::Route
  87. Properties:
  88. RouteTableId: !Ref PublicRouteTable
  89. DestinationCidrBlock: "0.0.0.0/0"
  90. GatewayId: !Ref InternetGateway
  91. PublicRouteTableAssociation:
  92. Type: AWS::EC2::SubnetRouteTableAssociation
  93. Properties:
  94. SubnetId: !Ref PublicSubnet
  95. RouteTableId: !Ref PublicRouteTable
  96. EC2SecurityGroup:
  97. Type: AWS::EC2::SecurityGroup
  98. Properties:
  99. GroupName: "doccano-ec2-sg"
  100. GroupDescription: "Security Group for doccano"
  101. VpcId: !Ref VPC
  102. SecurityGroupIngress:
  103. - IpProtocol: tcp
  104. FromPort: "80"
  105. ToPort: "80"
  106. CidrIp: 0.0.0.0/0
  107. - IpProtocol: tcp
  108. FromPort: "22"
  109. ToPort: "22"
  110. CidrIp: 0.0.0.0/0
  111. Tags:
  112. - Key: Name
  113. Value: doccano-ec2-sg
  114. EC2Instance:
  115. Type: AWS::EC2::Instance
  116. Properties:
  117. AvailabilityZone:
  118. Fn::Select:
  119. - 0
  120. - Fn::GetAZs: { Ref: "AWS::Region" }
  121. KeyName: !Ref KeyName
  122. ImageId: !Ref LatestAmiId
  123. InstanceType: !Ref InstanceType
  124. Monitoring: true
  125. SecurityGroupIds:
  126. - !Ref EC2SecurityGroup
  127. SubnetId: !Ref PublicSubnet
  128. UserData:
  129. Fn::Base64: !Sub |
  130. #!/bin/bash -ex
  131. yum update -y
  132. # Install Docker
  133. yum install -y docker
  134. systemctl enable docker
  135. service docker start
  136. # Install docker compose
  137. curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  138. chmod +x /usr/local/bin/docker-compose
  139. ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  140. # Install git
  141. yum install -y git
  142. git clone https://github.com/doccano/doccano.git
  143. cd doccano
  144. sed -i s/"admin"/${Username}/g docker-compose.prod.yml
  145. sed -i s/"password"/${Password}/g docker-compose.prod.yml
  146. docker-compose -f docker-compose.prod.yml up -d
  147. Tags:
  148. - Key: Name
  149. Value: doccano
  150. Outputs:
  151. PublicDNS:
  152. Description: EC2 public DNS
  153. Value: !GetAtt EC2Instance.PublicDnsName