2020-03-04 12:46:51 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-03-12 19:19:15 +00:00
|
|
|
set -e
|
|
|
|
|
2020-03-04 12:46:51 +00:00
|
|
|
# TODO basic error checking
|
|
|
|
# TODO verbosity
|
2020-03-04 12:47:24 +00:00
|
|
|
# TODO hardening
|
2020-03-04 12:46:51 +00:00
|
|
|
|
2020-03-12 19:19:15 +00:00
|
|
|
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
|
|
|
|
|
|
_server_base_url="$_domain"
|
|
|
|
|
|
|
|
echo "Provisioning: $_server_base_url$ - (whoami)@$(hostname)"
|
|
|
|
|
2020-03-04 13:37:59 +00:00
|
|
|
_docker_container_config_dir="/var/docker"
|
2020-03-04 13:02:01 +00:00
|
|
|
_docker_compose_version="1.25.4"
|
2020-03-04 12:46:51 +00:00
|
|
|
|
|
|
|
# add user
|
2020-03-12 20:01:15 +00:00
|
|
|
useradd -m -s /bin/bash "$_docker_user"
|
2020-03-04 12:46:51 +00:00
|
|
|
groupadd docker
|
2020-03-12 20:01:15 +00:00
|
|
|
usermod -aG docker "$_docker_user"
|
|
|
|
mkdir /home/"$_docker_user"/.ssh
|
|
|
|
cp /root/.ssh/authorized_keys /home/"$_docker_user"/.ssh/
|
|
|
|
chown "$_docker_user": /home/"$_docker_user"/.ssh/authorized_keys
|
2020-03-04 12:46:51 +00:00
|
|
|
|
|
|
|
apt-get update
|
2020-03-12 19:19:15 +00:00
|
|
|
apt-get upgrade --yes
|
2020-03-04 12:46:51 +00:00
|
|
|
apt-get install \
|
|
|
|
apt-transport-https \
|
|
|
|
ca-certificates \
|
|
|
|
curl \
|
|
|
|
gnupg2 \
|
|
|
|
software-properties-common \
|
|
|
|
apache2-utils \
|
|
|
|
ufw
|
|
|
|
|
|
|
|
ufw allow ssh
|
|
|
|
ufw allow http
|
|
|
|
ufw allow https
|
2020-03-12 19:19:15 +00:00
|
|
|
ufw --force enable
|
2020-03-04 12:46:51 +00:00
|
|
|
|
2020-03-12 19:19:15 +00:00
|
|
|
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
|
2020-03-04 12:46:51 +00:00
|
|
|
add-apt-repository \
|
|
|
|
"deb [arch=amd64] https://download.docker.com/linux/debian \
|
|
|
|
$(lsb_release -cs) \
|
|
|
|
stable"
|
|
|
|
apt-get update
|
|
|
|
apt-get install docker-ce docker-ce-cli containerd.io
|
|
|
|
|
2020-03-04 13:02:01 +00:00
|
|
|
curl -L "https://github.com/docker/compose/releases/download/$_docker_compose_version/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
2020-03-04 12:46:51 +00:00
|
|
|
chmod +x /usr/local/bin/docker-compose
|
|
|
|
|
2020-03-12 20:01:15 +00:00
|
|
|
echo "Basic HTTP authorisation password for user: $_docker_user"
|
|
|
|
_HT_PASSWD=$(htpasswd -nB "$_docker_user" | sed -e 's/\$/\$\$/g')
|
2020-03-04 12:46:51 +00:00
|
|
|
|
|
|
|
docker network create web
|
|
|
|
|
2020-03-04 13:37:59 +00:00
|
|
|
mkdir -p "$_docker_container_config_dir"/traefik
|
|
|
|
mkdir -p "$_docker_container_config_dir"/portainer
|
|
|
|
touch "$_docker_container_config_dir"/traefik/acme.json
|
|
|
|
chmod 600 "$_docker_container_config_dir"/traefik/acme.json
|
2020-03-04 12:46:51 +00:00
|
|
|
|
2020-03-04 13:37:59 +00:00
|
|
|
cd "$_docker_container_config_dir"/traefik || exit 20
|
2020-03-04 12:46:51 +00:00
|
|
|
echo "api:
|
|
|
|
dashboard: true
|
|
|
|
|
|
|
|
entryPoints:
|
|
|
|
http:
|
|
|
|
address: \":80\"
|
|
|
|
https:
|
|
|
|
address: \":443\"
|
|
|
|
|
|
|
|
providers:
|
|
|
|
docker:
|
|
|
|
endpoint: \"unix:///var/run/docker.sock\"
|
|
|
|
exposedByDefault: false
|
|
|
|
|
|
|
|
certificatesResolvers:
|
|
|
|
http:
|
|
|
|
acme:
|
|
|
|
email: $_lets_encrypt_email
|
|
|
|
storage: acme.json
|
|
|
|
httpChallenge:
|
|
|
|
entryPoint: http
|
|
|
|
" > traefik.yml
|
|
|
|
|
|
|
|
echo "version: '3'
|
|
|
|
|
|
|
|
services:
|
|
|
|
traefik:
|
|
|
|
image: traefik:v2.0
|
|
|
|
container_name: traefik
|
|
|
|
restart: unless-stopped
|
|
|
|
security_opt:
|
|
|
|
- no-new-privileges:true
|
|
|
|
networks:
|
|
|
|
- web
|
|
|
|
ports:
|
|
|
|
- 80:80
|
|
|
|
- 443:443
|
|
|
|
volumes:
|
|
|
|
- /etc/localtime:/etc/localtime:ro
|
|
|
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
|
|
|
- ./traefik.yml:/traefik.yml:ro
|
|
|
|
- ./acme.json:/acme.json
|
|
|
|
labels:
|
|
|
|
- \"traefik.enable=true\"
|
|
|
|
- \"traefik.http.routers.traefik.entrypoints=http\"
|
|
|
|
- \"traefik.http.routers.traefik.rule=Host(\`$_server_base_url\`)\"
|
|
|
|
- \"traefik.http.middlewares.traefik-auth.basicauth.users=$_HT_PASSWD\"
|
|
|
|
- \"traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https\"
|
|
|
|
- \"traefik.http.routers.traefik.middlewares=traefik-https-redirect\"
|
|
|
|
- \"traefik.http.routers.traefik-secure.entrypoints=https\"
|
|
|
|
- \"traefik.http.routers.traefik-secure.rule=Host(\`$_server_base_url\`)\"
|
|
|
|
- \"traefik.http.routers.traefik-secure.middlewares=traefik-auth\"
|
|
|
|
- \"traefik.http.routers.traefik-secure.tls=true\"
|
|
|
|
- \"traefik.http.routers.traefik-secure.tls.certresolver=http\"
|
|
|
|
- \"traefik.http.routers.traefik-secure.service=api@internal\"
|
|
|
|
|
|
|
|
networks:
|
|
|
|
web:
|
|
|
|
external: true
|
|
|
|
" >> docker-compose.yml
|
|
|
|
docker-compose up -d
|
|
|
|
|
2020-03-04 13:37:59 +00:00
|
|
|
cd "$_docker_container_config_dir"/portainer || exit 30
|
|
|
|
# create "$_docker_container_config_dir"/portainer/docker-compose.yml
|
2020-03-04 12:46:51 +00:00
|
|
|
_portainer_url="portainer.$_server_base_url"
|
|
|
|
echo "version: '3'
|
|
|
|
|
|
|
|
services:
|
|
|
|
portainer:
|
|
|
|
image: portainer/portainer:latest
|
|
|
|
container_name: portainer
|
|
|
|
restart: unless-stopped
|
|
|
|
security_opt:
|
|
|
|
- no-new-privileges:true
|
|
|
|
networks:
|
|
|
|
- web
|
|
|
|
volumes:
|
|
|
|
- /etc/localtime:/etc/localtime:ro
|
|
|
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
|
|
|
- ./data:/data
|
|
|
|
labels:
|
|
|
|
- \"traefik.enable=true\"
|
|
|
|
- \"traefik.http.routers.portainer.entrypoints=http\"
|
|
|
|
- \"traefik.http.routers.portainer.rule=Host(\`$_portainer_url\`)\"
|
|
|
|
- \"traefik.http.middlewares.portainer-https-redirect.redirectscheme.scheme=https\"
|
|
|
|
- \"traefik.http.routers.portainer.middlewares=portainer-https-redirect\"
|
|
|
|
- \"traefik.http.routers.portainer-secure.entrypoints=https\"
|
|
|
|
- \"traefik.http.routers.portainer-secure.rule=Host(\`$_portainer_url\`)\"
|
|
|
|
- \"traefik.http.routers.portainer-secure.tls=true\"
|
|
|
|
- \"traefik.http.routers.portainer-secure.tls.certresolver=http\"
|
|
|
|
- \"traefik.http.routers.portainer-secure.service=portainer\"
|
|
|
|
- \"traefik.http.services.portainer.loadbalancer.server.port=9000\"
|
|
|
|
- \"traefik.docker.network=web\"
|
|
|
|
|
|
|
|
networks:
|
|
|
|
web:
|
|
|
|
external: true
|
|
|
|
" >> docker-compose.yml
|
|
|
|
docker-compose up -d
|
2020-03-04 13:02:01 +00:00
|
|
|
|
2020-03-12 19:19:15 +00:00
|
|
|
echo "-------------------------------------------------------------------------"
|
|
|
|
echo ""
|
|
|
|
echo "VISIT PORTAINER URL NOW TO SET INITIAL LOGIN:"
|
2020-03-04 12:46:51 +00:00
|
|
|
echo " https://$_portainer_url"
|
2020-03-12 19:19:15 +00:00
|
|
|
echo ""
|
|
|
|
echo "Traefik URl: https://$_server_base_url"
|
|
|
|
echo ""
|
|
|
|
echo "WARNING: May get insecure SSL errors"
|
|
|
|
echo " this is temporary while certs are in process of being issued"
|
|
|
|
|
|
|
|
rm /tmp/setup.sh
|