-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcftemplate.yml
66 lines (62 loc) · 2.34 KB
/
cftemplate.yml
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
AWSTemplateFormatVersion: 2010-09-09
Description: >
This Cloudformation Template creates a Docker machine on EC2 Instance.
Docker Machine will run on Amazon Linux 2 (ami-0947d2ba12ee1ff75) EC2 Instance with
custom security group allowing SSH connections from anywhere on port 22.
Parameters:
KeyPairName:
Description: Enter the name of your Key Pair for SSH connections.
Type: AWS::EC2::KeyPair::KeyName
ConstraintDescription: Must one of the existing EC2 KeyPair
Resources:
DockerMachineSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH for Docker Machine
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
DockerMachine:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0947d2ba12ee1ff75
InstanceType: t2.micro
KeyName: !Ref KeyPairName
SecurityGroupIds:
- !GetAtt DockerMachineSecurityGroup.GroupId
Tags:
-
Key: Name
Value: !Sub Docker Machine of ${AWS::StackName}
UserData:
Fn::Base64: |
#! /bin/bash
yum update -y
amazon-linux-extras install docker -y
systemctl start docker
systemctl enable docker
usermod -a -G docker ec2-user
# install docker-compose
curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
cd /home/ec2-user
mkdir app
cd app
wget https://raw.githubusercontent.com/jokerinya2013/bookstore_trail/main/Dockerfile
wget https://raw.githubusercontent.com/jokerinya2013/bookstore_trail/main/my.py
wget https://raw.githubusercontent.com/jokerinya2013/bookstore_trail/main/docker-compose.yml
wget https://raw.githubusercontent.com/jokerinya2013/bookstore_trail/main/requirements.txt
docker-compose up
Outputs:
WebsiteURL:
Description: Docker Machine DNS Name
Value: !Sub
- ${PublicAddress}
- PublicAddress: !GetAtt DockerMachine.PublicDnsName