Ultima attività 6 months ago

Revisione 820459adc66f2e651a64dd3910722acc8482dd4c

deploy_traefik.sh Raw
1#!/bin/bash
2DOCKER_BASE=/srv/docker
3
4mkdir -p ${DOCKER_BASE}/traefik/container.conf
5
6cat > ${DOCKER_BASE}/traefik/container.conf/docker-compose.yml <<EOF
7version: '3.7'
8
9services:
10 traefik:
11 image: traefik:1.7-alpine
12 environment:
13 - LC_ALL=C.UTF-8
14 - TZ=Europe/Berlin
15 labels:
16 - traefik.enable=true
17 - traefik.backend=traefik
18 - traefik.port=8080
19 ports:
20 - "80:80"
21 - "443:443"
22 - "8080:8080"
23 restart: always
24 volumes:
25 - "./config/:/etc/traefik/"
26 - "/var/run/docker.sock:/var/run/docker.sock:ro"
27
28networks:
29 traefik_default:
30 external: true
31EOF
32ln -s container.conf/docker-compose.yml ${DOCKER_BASE}/traefik/
33
34cat > ${DOCKER_BASE}/traefik/container.conf/production.yml <<EOF
35version: '3.7'
36
37services:
38
39 traefik:
40 labels:
41 - traefik.frontend.rule=Host:host.test.org;PathPrefixStrip:/traefik
42 - com.centurylinklabs.watchtower.enable=true
43EOF
44
45cat > ${DOCKER_BASE}/traefik/container.conf/traefik.service <<EOF
46[Unit]
47Description=Traefik Proxy Service
48After=network.target docker.service
49Requires=docker.service
50
51[Service]
52Type=oneshot
53RemainAfterExit=yes
54
55Environment="WORK_DIR=/srv/docker/traefik/"
56WorkingDirectory=/srv/docker/traefik/
57ExecStartPre=-/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down
58ExecStart=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" up -d
59ExecStop=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down
60
61[Install]
62WantedBy=docker.service
63EOF
64ln -s ${DOCKER_BASE}/traefik/container.conf/traefik.service /etc/systemd/system/
65
66mkdir -p ${DOCKER_BASE}/traefik/config
67
68cat > ${DOCKER_BASE}/traefik/config/traefik.toml <<EOF
69logLevel = "DEBUG"
70defaultEntryPoints = ["http", "https"]
71
72# WEB interface of Traefik - it will show web page with overview of frontend and backend configurations
73[web]
74address = ":8080"
75 [web.auth.basic]
76 users = ["admin:$apr1$AAbCdQpX$ajolS9mMfKRG.lqcY/uXU/"]
77
78# Connection to docker host system (docker.sock)
79[docker]
80domain = "test.org"
81watch = true
82# This will hide all docker containers that don't have explicitly
83# set label to "enable"
84exposedbydefault = false
85
86# Force HTTPS
87[entryPoints]
88 [entryPoints.http]
89 address = ":80"
90 [entryPoints.http.redirect]
91 entryPoint = "https"
92 [entryPoints.https]
93 address = ":443"
94 [entryPoints.https.tls]
95
96# Let's encrypt configuration
97[acme]
98 email="ssladmin@test.org"
99 storage="/etc/traefik/acme.json"
100 entryPoint="https"
101 acmeLogging=true
102 onDemand=false
103 OnHostRule=true
104
105[acme.httpChallenge]
106 entryPoint = "http"
107EOF
108
109systemctl daemon-reload && systemctl enable traefik && systemctl start traefik
110