Skip to content

Commit bbcb384

Browse files
tiangolosolidnerd
authored andcommitted
📝 Update Docker Swarm guide
1 parent b3eacbd commit bbcb384

File tree

1 file changed

+20
-56
lines changed

1 file changed

+20
-56
lines changed

docs/docker-swarm-traefik-registry.md

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export GITLAB_HOST=gitlab.example.com
100100
export REGISTRY_HOST=registry.example.com
101101
```
102102

103-
You will use the domain for `GITLAB_HOST` to access GitLab in your browser and to commit with Git.
103+
You will use the domain for `GITLAB_HOST` to access GitLab in your browser and to commit and push with Git.
104104

105105
And you will use the domain for `REGISTRY_HOST` to store, push, and pull Docker images, e.g.:
106106

@@ -110,7 +110,7 @@ docker pull registry.example.com/mygroup/myproject/imagename:sometag
110110

111111
These environment variables will be used by the file `docker-compose.swarm.yml`.
112112

113-
They are used inside of the stacks and are also used to configure the domains for the Traefik load balancer. Because of that, you need to export them.
113+
They are used inside of the stacks and are also used to configure the domains for the Traefik load balancer. Because of that, you need to export them for them to be available when deploying the stack.
114114

115115
## Other environment variables
116116

@@ -120,16 +120,14 @@ Read the [main README](https://github.com/sameersbn/docker-gitlab) for all the o
120120

121121
For Registry specific options and details, check the main [GitLab Registry documentation in this repo](https://github.com/sameersbn/docker-gitlab/blob/master/docs/container_registry.md).
122122

123-
You can configure them by exporting the environment variables you want to use like you did for `GITLAB_HOST` and `REGISTRY_HOST`, or you can also edit de file `docker-compose.swarm.yml` directly.
123+
You can configure them by editing de file `docker-compose.swarm.yml`.
124124

125-
If you want to edit the file directly, you can do it in the command line with a program like `nano`, e.g.:
125+
You can do it in the command line with a program like `nano`, e.g.:
126126

127127
```bash
128128
nano docker-compose.swarm.yml
129129
```
130130

131-
You could want to edit the file directly to preserve the values that you used for deploying your stack.
132-
133131
## Set other environment variables
134132

135133
If you want anyone to sign up instead of only people with invitation, change `GITLAB_SIGNUP_ENABLED` to `true`:
@@ -155,43 +153,7 @@ You can copy it and set it in the file like:
155153
- GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alphanumeric-string
156154
```
157155
158-
Or you can do it by exporting variables like:
159-
160-
```bash
161-
export GITLAB_SECRETS_DB_KEY_BASE=$(openssl rand -hex 32)
162-
export GITLAB_SECRETS_SECRET_KEY_BASE=$(openssl rand -hex 32)
163-
export GITLAB_SECRETS_OTP_KEY_BASE=$(openssl rand -hex 32)
164-
```
165-
166-
that will assign a new random string to each environment variable.
167-
168-
* Set `GITLAB_ROOT_PASSWORD` to the key of the main first administrator user:
169-
170-
```bash
171-
export GITLAB_ROOT_PASSWORD=change-this-admin-password
172-
```
173-
174-
* Set `GITLAB_ROOT_EMAIL` to the email of the main first administrator user:
175-
176-
```bash
177-
178-
```
179-
180-
...by default `admin@${GITLAB_HOST}`.
181-
182-
* Set the appropriate email accounts for the following variables:
183-
184-
```bash
185-
186-
187-
188-
```
189-
190-
...by default:
191-
192-
* `GITLAB_EMAIL`: `notifications@${GITLAB_HOST}`
193-
* `GITLAB_EMAIL_REPLY_TO`: `noreply@${GITLAB_HOST}`
194-
* `GITLAB_INCOMING_EMAIL_ADDRESS`: `reply@${GITLAB_HOST}`
156+
There are several other settings that you might want to configure, like email accounts for notifications, SMTP credentials to send emails, etc.
195157
196158
## Copy the file
197159
@@ -207,15 +169,13 @@ and connect via SSH to your remote server, e.g.:
207169
ssh -p 2222 [email protected]
208170
```
209171

210-
If you modified the file locally and then connected to your server later, make sure you export any missing environment variables.
211-
212-
Specially `GITLAB_HOST` and `REGISTRY_HOST` that are needed as env vars even if you modified the Docker Compose file (as those are used in the Traefik labels).
172+
If you modified the file locally and then connected to your server later, make sure you export the environment variables `GITLAB_HOST` and `REGISTRY_HOST` that are needed even if you modified the Docker Compose file (as those are used in the Traefik labels).
213173

214174
## About volumes, labels, and constraints
215175

216176
Because the Docker Swarm cluster may have more than one single node (machine) in the cluster, we need to make sure that the services that need to save and read files from volumes are always deployed to the same node.
217177

218-
For example, the service for `redis` uses a volume, you can check it on the file:
178+
For example, the service for `redis` uses a volume, you can check it on the `docker-compose.swarm.yml` file:
219179

220180
```yaml
221181
volumes:
@@ -233,7 +193,7 @@ To make sure `redis` is always deployed to the same node that contains the same
233193

234194
This tells Docker that the service `redis` should be deployed to a Docker node (a machine in the cluster) with the label `node.labels.gitlab.redis-data=true`.
235195

236-
Then we can make one node have this label, and Docker Swarm will always deploy the `redis` service to the same node.
196+
Then we can make one node (only one) have this label, and Docker Swarm will always deploy the `redis` service to the same node. That way, the service will keep reading the same volume every time. Even if you re-deploy or upgrade the stack.
237197

238198
## Add constraint labels
239199

@@ -258,15 +218,15 @@ m48gz5e8ucmk59af4m6enmnaz * dog.example.com Ready Active Leade
258218
mue36qqwqnzrqt4iqi0yyd6ie gitlab.example.com Ready Active 19.03.9
259219
```
260220

261-
And select the node where you want to deploy the main `gitlab` service. In this example, in the `HOSTNAME` `gitlab.example.com`, with node ID `mue36qqwqnzrqt4iqi0yyd6ie`.
221+
And select the node where you want to deploy the main `gitlab` service. In this example, in the node that has a `HOSTNAME` with value `gitlab.example.com`, with node ID `mue36qqwqnzrqt4iqi0yyd6ie`.
262222

263-
So, you could export that environment variable with that node with:
223+
So, you could export that environment variable using the node ID with something like:
264224

265225
```bash
266226
export NODE_ID=mue36qqwqnzrqt4iqi0yyd6ie
267227
```
268228

269-
* Create a tag in that node, so that the service `gitlab` and `registry` are always deployed to the same node and use the same volumes:
229+
* Create a label in that node, so that the service `gitlab` and `registry` are always deployed to the same node and use the same volumes:
270230

271231
```bash
272232
docker node update --label-add gitlab.certs-data=true $NODE_ID
@@ -286,6 +246,8 @@ And add the label for `postgres`:
286246
docker node update --label-add gitlab.postgresql-data=true $NODE_ID
287247
```
288248

249+
**Note**: you only have to set those labels once. Not every time you want to re-deploy your stack.
250+
289251
## Deploy the stack
290252

291253
Now, having the labels set in the Docker nodes, and the environment variables exported, you can deploy your stack:
@@ -294,6 +256,8 @@ Now, having the labels set in the Docker nodes, and the environment variables ex
294256
docker stack deploy --compose-file docker-compose.swarm.yml gitlab
295257
```
296258

259+
**Note**: the environment variables `GITLAB_HOST` and `REGISTRY_HOST` have to be available every time to deploy the stack. But the node labels can be set only once, the first time you deploy.
260+
297261
You can check the status of the deployment with:
298262

299263
```bash
@@ -350,13 +314,13 @@ And the Registry is configured to look for the certificate in that same location
350314

351315
If you use GitLab and want to integrate Continuous Integration / Continuous Deployment, you can follow this section to install the GitLab runner.
352316

353-
You should create the runner using Docker standalone instead of in Docker Swarm mode, as you need the configurations to persist, and in Docker Swarm mode, the container could be deployed to a different server and you would loose those configurations.
317+
You should create the runner using Docker standalone instead of in Docker Swarm mode, as you need the configurations to persist, and in Docker Swarm mode, the container could be deployed to a different server and you would lose those configurations.
354318

355319
### Testing and Deployment
356320

357321
For testing, the GitLab runner can run in any node.
358322

359-
But if you want to deploy another runner (or the same) for deployment in the same Docker Swarm cluster, it has to run on a manager node.
323+
But if you want to deploy another runner for deployment (or use the same one), it has to run on a manager node in the Docker Swarm cluster.
360324

361325
### Create the GitLab Runner in Docker standalone mode
362326

@@ -380,19 +344,19 @@ docker exec -it gitlab-runner bash
380344
### Install the GitLab Runner
381345

382346
* Go to the GitLab "Admin Area -> Runners" section.
383-
* Get the URL and create a variable in your Docker Manager's Terminal, e.g.:
347+
* Get the URL and create a variable with it in the bash session inside of your Runner's Docker container, e.g.:
384348

385349
```bash
386350
export GITLAB_URL=https://gitlab.example.com/
387351
```
388352

389-
* Get the registration token and create a variable in your Docker Manager's Terminal, e.g.:
353+
* Get the registration token and create a variable in the bash session inside of your Runner's Docker container, e.g.:
390354

391355
```bash
392356
export GITLAB_TOKEN=WYasdfJp4sdfasdf1234
393357
```
394358

395-
* Run the next command editing the name and tags as you need, you can also edit the tags later in the web user interface.
359+
* Run the next command editing the name and tags as you need, you can also edit them later in the web user interface.
396360

397361
```bash
398362
gitlab-runner \

0 commit comments

Comments
 (0)