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