-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaws-ec2-setup.sh
executable file
·108 lines (76 loc) · 2.74 KB
/
aws-ec2-setup.sh
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh
set -eu
Setup_Depedencies() {
printf "\n---> INSTALL DEPENDENCIES <---\n"
sudo yum update -y
sudo yum install -y git curl
}
Setup_Docker() {
printf "\n---> INSTALL DOCKER <---\n"
sudo amazon-linux-extras install -y docker
sudo service docker start
}
Setup_Docker_Compose() {
printf "\n---> INSTALL DOCKER COMPOSE <---\n"
local _download_url="https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)"
sudo curl -L "${_download_url}" -o /usr/bin/docker-compose
sudo chmod ug+x /usr/bin/docker-compose
}
Setup_Traefik() {
printf "\n---> INSTALL TRAEFIK <---\n"
sudo cp -r ./traefik /opt
cd /opt/traefik
sudo touch acme.json
# Traefik will not create the certificates if we don't fix the permissions
# for the file where it stores the LetsEncrypt certificates.
sudo chmod 600 acme.json
# Creates a docker network that will be used by Traefik to proxy the requests to the docker containers:
sudo docker network create traefik || true
if [ ! -f ./.env ]; then
printf "\n
===> ERROR:
Please copy the .env.example file to .env:
$ sudo cp ./traefik/.env.example /opt/traefik/.env
Now customize it to your values with:
$ sudo nano /opt/traefik/.env
Afterwards just re-run the setup again:
$ ./aws-ec2-setup.sh
\n"
exit 1
fi
# Traefik will be listening on port 80 and 443, and proxy the requests to
# the associated container for the domain. Check the README for more details.
sudo docker-compose up -d traefik
# Just give sometime for it to start in order to check the logs afterwards.
sleep 5
printf "\n---> CHECK TRAEFIK LOGS <---\n"
sudo docker-compose logs traefik
cd -
}
Main() {
Setup_Depedencies
Setup_Docker
Setup_Docker_Compose
Setup_Traefik
printf "\n\n---> DOCKER VERSION <---\n"
sudo docker version
printf "\n---> DOCKER COMPOSE VERSION <---\n"
sudo docker-compose --version
echo
printf "\n---> GIT VERSION<---\n"
git version
echo
printf "\n---> TRAEFIK installed at: /opt/traefik <---\n"
printf "\nFrom /opt/traefik folder you can ran any docker-compose command.\n"
printf "\nSome useful examples:\n"
printf "\n## Start Traefik:\n"
printf "sudo docker-compose up -d traefik\n"
printf "\n## Restart Traefik:\n"
printf "sudo docker-compose restart traefik\n"
printf "\n## Destroy Traefik:\n"
printf "sudo docker-compose down\n"
printf "\n## Tailing the Traefik logs in realtime:\n"
printf "sudo docker-compose logs --follow traefik\n"
printf "\n---> TRAEFIK is now listening for new docker containers <---\n\n"
}
Main ${@}