We follow the tutorial at DockerSwarm.rocks version 2.
The idea is to have a main load balancer/proxy that covers all the Docker Swarm cluster and handles HTTPS certificates and requests for each domain.
But doing it in a way that allows you to have other Traefik services inside each stack without interfering with each other, to redirect based on path in the same stack (e.g. one container handles / for a web frontend and another handles /api for an API under the same domain), or to redirect from HTTP to HTTPS selectively.
The Petra containers and the Traefik container have to run independent from each other. Make sure to follow these steps first and continue with the Petra stack afterwards.
First, ssh into the Petra server and follow the steps from the tutorial to set up the docker network with the required environment variables.
Next, create a folder named traefik and paste the content from the tutorial into traefik.yml or simply do curl -L dockerswarm.rocks/traefik.yml -o traefik.yml. Now, deploy the stack with:
$ docker stack deploy -c traefik.yml traefik
and check its status via
$ docker stack ps traefik $ docker service logs traefik_traefik
unless otherwise stated.
Since the traefik backend is running, we have two options,
Assume recent docker containers are located in the gitlab registry (i.e. step 1 & 2 in manual deployment, generate the docker-stack.yml and copy to the petra server.
Set the required environment variables in your bash session as specified in home and create the upload folder as defined by HOST_UPLOAD_FOLDER.
Now, to start the stack manually, enter
$ docker stack deploy -c docker-stack.yml --with-registry-auth example-com
and verify its status via
$ docker stack ps example-com $ docker service logs <id>
All these steps can be automated via Gitlab CI. The following procedure has to be done only once and as soon as it is working properly, each commit triggers the pipeline to publish a new version of petra.
First, setup the gitlab-runner via docker on the server as specified in Traefik Gitlab CI and credentials from Settings -> CI/CD -> Runners.
Make sure, environment variables in Settings -> CI/CD -> Variables are set correctly including the tokens.
Finally, create the pipeline in gitlab by using the .gitlab-ci.yml provided by the repository.
Now, every commit to master triggers the pipeline building the containers and publishing the stack to traefik.