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.

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