From e57d47aea42726b9302ff92c6241f6a4df72b83f Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Fri, 10 May 2024 00:39:35 +0200 Subject: [PATCH] chore(gitlab): try using docker compose --- docker/gitlab/.gitignore | 3 + docker/gitlab/docker-compose.yml | 46 ++++++++++++ docker/gitlab/gitlab_root_password.txt | 1 + .../meta/{main.yml => requirements.yml} | 0 knowledge base/ansible.md | 16 ++++- knowledge base/docker.md | 53 +++++++++++++- knowledge base/gitlab.md | 21 ++++++ snippets/ansible.tasks.yml | 71 +++++++++++++++++++ snippets/check-port-is-reachable.sh | 5 ++ snippets/gitlab.docker.sh | 12 ++++ .../{gitlab.omnibus.sh => gitlab.package.sh} | 7 ++ 11 files changed, 232 insertions(+), 3 deletions(-) create mode 100644 docker/gitlab/.gitignore create mode 100644 docker/gitlab/docker-compose.yml create mode 100644 docker/gitlab/gitlab_root_password.txt rename examples/ansible/role.gitlab-omnibus-on-ec2/meta/{main.yml => requirements.yml} (100%) create mode 100644 snippets/gitlab.docker.sh rename snippets/{gitlab.omnibus.sh => gitlab.package.sh} (96%) diff --git a/docker/gitlab/.gitignore b/docker/gitlab/.gitignore new file mode 100644 index 0000000..0bc3b0e --- /dev/null +++ b/docker/gitlab/.gitignore @@ -0,0 +1,3 @@ +/config +/data +/logs diff --git a/docker/gitlab/docker-compose.yml b/docker/gitlab/docker-compose.yml new file mode 100644 index 0000000..c0f1299 --- /dev/null +++ b/docker/gitlab/docker-compose.yml @@ -0,0 +1,46 @@ +--- + +# sources: +# - https://docs.gitlab.com/ee/install/docker.html#install-gitlab-using-docker-compose + +version: '3.6' +secrets: + gitlab_root_password: + file: ./gitlab_root_password.txt +services: + gitlab: + container_name: gitlab + image: gitlab/gitlab-ce:16.11.2-ce.0 + restart: unless-stopped + hostname: gitlab.lan + environment: + GITLAB_OMNIBUS_CONFIG: + # add any other gitlab.rb configuration here, each on its own line + # https not accepteb y Let's Encrypt on .lan (not a valid public domain) + | + external_url 'http://gitlab.lan' + gitlab_rails['initial_root_password'] = File.read('/run/secrets/gitlab_root_password').gsub("\n", "") + ports: + - '8022:22' + - '8080:80' + - '8443:443' + volumes: + - ${PWD}/config:/etc/gitlab:Z + - ${PWD}/data:/var/opt/gitlab:Z + - ${PWD}/logs:/var/log/gitlab:Z + shm_size: 256m + secrets: + - gitlab_root_password + # healthcheck: + # test: >- + # test $( + # curl --fail --insecure --location --output '/dev/null' --silent --show-error --write-out "%{http_code}" + # 'http://localhost/' + # ) -eq 200 || exit 1 + # interval: 60s + # timeout: 3s + # retries: 3 + # start_period: + # # it might take longer + # # also keep an eye out for permission errors + # 300s diff --git a/docker/gitlab/gitlab_root_password.txt b/docker/gitlab/gitlab_root_password.txt new file mode 100644 index 0000000..c4a3771 --- /dev/null +++ b/docker/gitlab/gitlab_root_password.txt @@ -0,0 +1 @@ +StupidlyInsecur3-Passw0rd diff --git a/examples/ansible/role.gitlab-omnibus-on-ec2/meta/main.yml b/examples/ansible/role.gitlab-omnibus-on-ec2/meta/requirements.yml similarity index 100% rename from examples/ansible/role.gitlab-omnibus-on-ec2/meta/main.yml rename to examples/ansible/role.gitlab-omnibus-on-ec2/meta/requirements.yml diff --git a/knowledge base/ansible.md b/knowledge base/ansible.md index 04bab69..1811200 100644 --- a/knowledge base/ansible.md +++ b/knowledge base/ansible.md @@ -52,7 +52,7 @@ ansible -i 'localhost,' -c 'local' -km 'setup' 'localhost' # This will *not* execute the plays inside it. ansible-playbook 'path/to/playbook.yml' --syntax-check -# Execute a playbook. +# Execute playbooks. ansible-playbook 'path/to/playbook.yml' -i 'hosts.list' ansible-playbook … -i 'host1,host2,hostN,' -l 'hosts,list' ansible-playbook … -i 'host1,host2,other,' -l 'hosts-pattern' @@ -71,6 +71,9 @@ ansible-playbook 'path/to/playbook.yml' --list-tasks ansible-playbook … --list-tasks --tags 'configuration,packages' ansible-playbook … --list-tasks --skip-tags 'system,user' +# Debug playbooks. +ANSIBLE_ENABLE_TASK_DEBUGGER=True ansible-playbook … + # List roles installed from Galaxy. ansible-galaxy list @@ -269,9 +272,10 @@ ansible-galaxy install -r 'requirements.yml' ### Role dependencies +Set them up in `role/meta/main.yml`: + ```yaml --- -# role/meta/main.yml dependencies: - role: common vars: @@ -282,6 +286,14 @@ dependencies: other_parameter: 12 ``` +and/or in `role/meta/requirements.yml`: + +```yaml +--- +collections: + - community.dns +``` + ## Output formatting > Introduced in Ansible 2.5 diff --git a/knowledge base/docker.md b/knowledge base/docker.md index dfdb332..f971c26 100644 --- a/knowledge base/docker.md +++ b/knowledge base/docker.md @@ -5,6 +5,7 @@ 1. [Daemon configuration](#daemon-configuration) 1. [Images configuration](#images-configuration) 1. [Containers configuration](#containers-configuration) +1. [Health checks](#health-checks) 1. [Advanced build with `buildx`](#advanced-build-with-buildx) 1. [Create builders](#create-builders) 1. [Build for specific platforms](#build-for-specific-platforms) @@ -262,7 +263,55 @@ Docker mounts specific system files in all containers to forward its settings: … ``` -Those files come from the volume the docker container is using for its root, and are modified on the container's startup with the information from the CLI, the daemon itself and, when missing, the host. +Those files come from the volume the docker container is using for its root, and are modified on the container's startup +with the information from the CLI, the daemon itself and, when missing, the host. + +## Health checks + +The following have the same effect: + +
Command line + +```sh +docker run … \ + --health-cmd 'curl --fail --insecure --silent --show-error http://localhost/ || exit 1' \ + --health-interval '5m' \ + --health-timeout '3s' \ + --health-retries '4' \ + --health-start-period '10s' +``` + +
+
Dockerfile + +```Dockerfile +HEALTHCHECK --interval=5m --timeout=3s --start-period=10s --retries=4 \ + CMD curl --fail --insecure --silent --show-error http://localhost/ || exit 1 +``` + +
+
Docker-compose file + +```yaml +version: '3.6' +services: + web-server: + healthcheck: + test: curl --fail --insecure --silent --show-error http://localhost/ || exit 1 + interval: 5m + timeout: 3s + retries: 4 + start_period: 10s + … +``` + +

+ +The command's exit status indicates the health status of the container. The possible values are: + +- `0`: success - the container is healthy and ready for use +- `1`: unhealthy - the container isn't working correctly +- `2`: reserved - don't use this exit code ## Advanced build with `buildx` @@ -313,6 +362,7 @@ docker load … - [Building multi-arch images for ARM and x86 with Docker Desktop] - [OpenContainers Image Spec] - [Docker ARG, ENV and .env - a Complete Guide] +- [Configuring HealthCheck in docker-compose]