Skip to content

Commit 1e67612

Browse files
committed
🌐 Create user data files
1 parent bfd75c5 commit 1e67612

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

grand-master.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#! /bin/bash
2+
yum update -y
3+
hostnamectl set-hostname Grand-Master
4+
amazon-linux-extras install docker -y
5+
systemctl start docker
6+
systemctl enable docker
7+
usermod -a -G docker ec2-user
8+
curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" \
9+
-o /usr/local/bin/docker-compose
10+
chmod +x /usr/local/bin/docker-compose
11+
docker swarm init
12+
aws ecr get-login-password --region ${AWS::Region} | docker login --username AWS --password-stdin ${ECR_REGISTRY}
13+
docker service create \
14+
--name=viz \
15+
--publish=8080:8080/tcp \
16+
--constraint=node.role==manager \
17+
--mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
18+
dockersamples/visualizer
19+
yum install git -y
20+
# uninstall aws cli version 1
21+
rm -rf /bin/aws
22+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
23+
unzip awscliv2.zip
24+
./aws/install
25+
yum install amazon-ecr-credential-helper -y
26+
mkdir -p /home/ec2-user/.docker
27+
cd /home/ec2-user/.docker
28+
echo '{"credsStore": "ecr-login"}' > config.json
29+
aws ecr create-repository \
30+
--repository-name ${APP_REPO_NAME} \
31+
--image-scanning-configuration scanOnPush=false \
32+
--image-tag-mutability MUTABLE \
33+
--region ${AWS::Region}
34+
docker build --force-rm -t "${ECR_REGISTRY}/${APP_REPO_NAME}:latest" ${GITHUB_REPO}
35+
docker push "${ECR_REGISTRY}/${APP_REPO_NAME}:latest"
36+
mkdir -p /home/ec2-user/phonebook
37+
cd /home/ec2-user/phonebook
38+
cat << EOF | tee .env
39+
ECR_REGISTRY=${ECR_REGISTRY}
40+
APP_REPO_NAME=${APP_REPO_NAME}
41+
EOF
42+
curl -o "docker-compose.yml" -L ${GIT_FILE_URL}docker-compose.yml
43+
curl -o "init.sql" -L ${GIT_FILE_URL}init.sql
44+
docker-compose config | docker stack deploy --with-registry-auth -c - phonebook

manager.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#! /bin/bash
2+
yum update -y
3+
amazon-linux-extras install docker -y
4+
systemctl start docker
5+
systemctl enable docker
6+
usermod -a -G docker ec2-user
7+
curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" \
8+
-o /usr/local/bin/docker-compose
9+
chmod +x /usr/local/bin/docker-compose
10+
yum install python3 -y
11+
pip3 install ec2instanceconnectcli
12+
eval "$(mssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
13+
--region ${AWS::Region} ${DockerManager1} docker swarm join-token manager | grep -i 'docker')"
14+
# uninstall aws cli version 1
15+
rm -rf /bin/aws
16+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
17+
unzip awscliv2.zip
18+
./aws/install
19+
yum install amazon-ecr-credential-helper -y
20+
mkdir -p /home/ec2-user/.docker
21+
cd /home/ec2-user/.docker
22+
echo '{"credsStore": "ecr-login"}' > config.json

worker.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#! /bin/bash
2+
yum update -y
3+
amazon-linux-extras install docker -y
4+
systemctl start docker
5+
systemctl enable docker
6+
usermod -a -G docker ec2-user
7+
curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" \
8+
-o /usr/local/bin/docker-compose
9+
chmod +x /usr/local/bin/docker-compose
10+
yum install python3 -y
11+
pip3 install ec2instanceconnectcli
12+
eval "$(mssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
13+
--region ${AWS::Region} ${DockerManager1} docker swarm join-token worker | grep -i 'docker')"
14+
# uninstall aws cli version 1
15+
rm -rf /bin/aws
16+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
17+
unzip awscliv2.zip
18+
./aws/install
19+
yum install amazon-ecr-credential-helper -y
20+
mkdir -p /home/ec2-user/.docker
21+
cd /home/ec2-user/.docker
22+
echo '{"credsStore": "ecr-login"}' > config.json

0 commit comments

Comments
 (0)