Last active
July 25, 2023 14:52
-
-
Save ozzpy/55643e5b6470233e426fc2983567a355 to your computer and use it in GitHub Desktop.
traefik-builder.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
IMAGE=$1 | |
CNAME=$2 | |
PORT=$3 | |
function buildTraefik { | |
cat << EOF > ~/up.sh | |
#!/bin/bash | |
docker image rm ${IMAGE} | |
docker pull ${IMAGE} | |
docker stack deploy -c stack-compose.yml traefik | |
EOF | |
cat << EOF > down.sh | |
#!/bin/bash | |
docker stack rm traefik | |
EOF | |
cat << EOF > ~/traefik.yml | |
entryPoints: | |
http: | |
address: ":80" | |
https: | |
address: ":443" | |
serversTransport: | |
insecureSkipVerify: true | |
providers: | |
docker: | |
endpoint: "unix:///var/run/docker.sock" | |
EOF | |
cat << EOF > ~/stack-compose.yml | |
version: "3" | |
services: | |
# INVIZZO CLOUD NETWORK | |
# do not open the port using ports: when using traefik loadbalancer | |
# images has they own default port, depending of the service image running | |
# so for internal usage, we do not need to expose or configure it, | |
# just route to default port using loadbalancer label | |
################################################## | |
# traefik proxy | |
proxy: | |
image: traefik:v2.9 | |
command: --providers.docker # see traefik.yml for full traefik configuration labels | |
ports: | |
- "80:80" | |
volumes: | |
- /etc/localtime:/etc/localtime:ro | |
- /var/run/docker.sock:/var/run/docker.sock | |
- ./traefik.yml:/traefik.yml | |
labels: | |
- "traefik.docker.network=traefic_proxy" | |
- "traefik.enable=true" | |
###################################################### | |
# spring-boot application | |
application-srv: | |
image: ${IMAGE} | |
hostname: application-srv | |
deploy: | |
mode: replicated | |
replicas: 2 | |
restart_policy: | |
condition: any | |
delay: 5s | |
max_attempts: 3 | |
window: 120s | |
#resources: | |
# limits: | |
# cpus: '0.75' | |
# memory: 512M | |
# pids: 1 | |
# reservations: | |
# cpus: '0.25' | |
# memory: 256M | |
labels: | |
- "traefik.http.routers.application-srv.rule=Host(\`${CNAME}.kgsc.com.br\`)" | |
- "traefik.http.services.application-srv.loadbalancer.server.port=${PORT}" | |
- "traefik.http.services.application-srv.loadbalancer.server.scheme=http" | |
- "traefik.http.routers.application-srv.entrypoints=http" | |
EOF | |
} | |
if [ -z "$IMAGE" ] || [ -z "$CNAME" ] || [ -z "$PORT" ]; | |
then | |
echo "Usage: $0 <image> <cname> <port>" | |
exit 1 | |
else | |
buildTraefik | |
fi; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment