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.

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