Ostatnio aktywny 6 months ago

Rewizja 1f3d33a0fa10438a0d8b710333c89f1e6e1be067

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