| 1 | #!/bin/bash |
| 2 | DOCKER_BASE=/srv/docker |
| 3 | |
| 4 | mkdir -p ${DOCKER_BASE}/watchtower/container.conf |
| 5 | |
| 6 | [ $(grep -c "healthcheck:" ${DOCKER_BASE}/watchtower/container.conf/production.yml) -eq 0 ] && sed -i '/labels:/i\ healthcheck:\n\ test: ["CMD", "/watchtower", "--health-check"]\n\ interval: 30s\n\ timeout: 10s\n\ retries: 3\n\ start_period: 40s' ${DOCKER_BASE}/watchtower/container.conf/docker-compose.yml && cd ${DOCKER_BASE}/watchtower/ && docker-compose -f docker-compose.yml -f container.conf/production.yml config && systemctl restart watchtower |
| 7 |
waja / gist:98a2b64c5a8145218b9bc84a0c6cd661
Last active 3 months ago
Revision f7590577ba90a14ccb78b7329d0d3702d5d9fd57
| 1 | #!/bin/bash |
| 2 | DOCKER_BASE=/srv/docker |
| 3 | |
| 4 | mkdir -p ${DOCKER_BASE}/watchtower/container.conf |
| 5 | |
| 6 | cat > ${DOCKER_BASE}/watchtower/container.conf/docker-compose.yml <<EOF |
| 7 | version: '3.7' |
| 8 | |
| 9 | services: |
| 10 | watchtower: |
| 11 | image: ghcr.io/nicholas-fedor/watchtower |
| 12 | healthcheck: |
| 13 | test: |
| 14 | - CMD |
| 15 | - /watchtower |
| 16 | - --health-check |
| 17 | timeout: 10s |
| 18 | interval: 30s |
| 19 | retries: 3 |
| 20 | start_period: 40s |
| 21 | labels: |
| 22 | com.centurylinklabs.watchtower.enable: "true" |
| 23 | restart: on-failure |
| 24 | volumes: |
| 25 | - /var/run/docker.sock:/var/run/docker.sock |
| 26 | - /etc/localtime:/etc/localtime:ro |
| 27 | - /etc/timezone:/etc/timezone:ro |
| 28 | command: --interval 3600 --label-enable |
| 29 | EOF |
| 30 | ln -s container.conf/docker-compose.yml ${DOCKER_BASE}/watchtower/ |
| 31 | |
| 32 | cat > ${DOCKER_BASE}/watchtower/container.conf/production.yml <<EOF |
| 33 | version: '3.7' |
| 34 | EOF |
| 35 | |
| 36 | cat > ${DOCKER_BASE}/watchtower/container.conf/watchtower.service <<EOF |
| 37 | [Unit] |
| 38 | Description=Watchtower Service |
| 39 | After=network.target docker.service |
| 40 | Requires=docker.service |
| 41 | |
| 42 | [Service] |
| 43 | Type=oneshot |
| 44 | RemainAfterExit=yes |
| 45 | |
| 46 | Environment="WORK_DIR=/srv/docker/watchtower/" |
| 47 | WorkingDirectory=/srv/docker/watchtower/ |
| 48 | ExecStartPre=-/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down |
| 49 | ExecStartPre=-/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" pull |
| 50 | ExecStart=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" up -d |
| 51 | ExecStop=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down |
| 52 | |
| 53 | [Install] |
| 54 | WantedBy=docker.service |
| 55 | EOF |
| 56 | ln -s ${DOCKER_BASE}/watchtower/container.conf/watchtower.service /etc/systemd/system/ |
| 57 | |
| 58 | systemctl daemon-reload && systemctl enable watchtower && systemctl start watchtower |
| 59 |
| 1 | #!/bin/bash |
| 2 | DOCKER_BASE=/srv/docker |
| 3 | WATCHTOWER_PATH=${DOCKER_BASE}/watchtower |
| 4 | DC_COMMAND="docker-compose -f docker-compose.yml" |
| 5 | |
| 6 | cd ${WATCHTOWER_PATH} || exit |
| 7 | [ -f container.conf/production.yml ] && DC_COMMAND="${DC_COMMAND} -f container.conf/production.yml" |
| 8 | [ "$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATIONS" | awk '{print $2}')" != "email" ] && exit |
| 9 | cp container.conf/production.yml container.conf/production.yml.old |
| 10 | |
| 11 | SMTP_HOST="$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATION_EMAIL_SERVER:" | awk '{print $2}')" |
| 12 | SMTP_FROM="$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATION_EMAIL_FROM:" | awk '{print $2}')" |
| 13 | SMTP_TO="$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATION_EMAIL_TO:" | awk '{print $2}')" |
| 14 | |
| 15 | [ ! -e ${WATCHTOWER_PATH}/.env ] && ln -s container.conf/.env ${WATCHTOWER_PATH}/.env |
| 16 | touch ${WATCHTOWER_PATH}/container.conf/.env |
| 17 | sed -iE '/^SMTP_/d' ${WATCHTOWER_PATH}/container.conf/.env |
| 18 | cat >> ${WATCHTOWER_PATH}/container.conf/.env <<EOF |
| 19 | SMTP_HOST=${SMTP_HOST} |
| 20 | SMTP_FROM=${SMTP_FROM} |
| 21 | SMTP_TO=${SMTP_TO} |
| 22 | EOF |
| 23 | |
| 24 | sed -i 's/WATCHTOWER_NOTIFICATIONS.*email/WATCHTOWER_NOTIFICATIONS=shoutrrr/' ${WATCHTOWER_PATH}/container.conf/production.yml |
| 25 | sed -i 's#WATCHTOWER_NOTIFICATION_EMAIL_FROM.*"#WATCHTOWER_NOTIFICATION_URL=smtp://:@\${SMTP_HOST}/?auth=None\&encryption=None\&fromaddress=\${SMTP_FROM}\&fromname=Watchtower\&starttls=No\&toaddresses=\${SMTP_TO}\&usehtml=No"#' ${WATCHTOWER_PATH}/container.conf/production.yml |
| 26 | sed -iE '/WATCHTOWER_NOTIFICATION_EMAIL_/d' ${WATCHTOWER_PATH}/container.conf/production.yml |
| 27 |
| 1 | #!/bin/bash |
| 2 | DOCKER_BASE=/srv/docker |
| 3 | |
| 4 | mkdir -p ${DOCKER_BASE}/watchtower/container.conf |
| 5 | |
| 6 | sed -i s/v2tec/containrrr/g ${DOCKER_BASE}/watchtower/container.conf/docker-compose.yml |
| 7 | |
| 8 | systemctl restart watchtower && docker image rm v2tec/watchtower |
| 9 |
| 1 | #!/bin/bash |
| 2 | DOCKER_BASE=/srv/docker |
| 3 | |
| 4 | mkdir -p ${DOCKER_BASE}/watchtower/container.conf |
| 5 | |
| 6 | sed -i "s/image: containrrr\/watchtower/image: ghcr.io\/nicholas-fedor\/watchtower/" ${DOCKER_BASE}/watchtower/container.conf/docker-compose.yml && cd ${DOCKER_BASE}/watchtower && systemctl restart watchtower && docker-compose -f docker-compose.yml -f container.conf/production.yml logs -f; docker image rm containrrr/watchtower |
| 7 |