2023-06-24 23:37:35 +02:00
# FIXME
2023-06-24 23:27:59 +02:00
2023-10-08 17:41:59 +02:00
Search and replace all mentions of FIXME with sensible content in this file and in [compose.yaml ](compose.yaml ).
2023-06-24 23:27:59 +02:00
2023-06-12 01:25:26 +02:00
# {{ cookiecutter.__service_slug.capitalize() }} Docker Compose files
2023-06-24 23:37:35 +02:00
Docker Compose files to spin up an instance of {{ cookiecutter.__service_slug.capitalize() }} FIXME capitalization FIXME.
2023-06-12 01:25:26 +02:00
# How to run
Add a `COMPOSE_ENV` file and save its location as a shell variable along with the location where this repo lives, here for example `/opt/containers/{{ cookiecutter.__project_slug }}` plus all other variables. At [env/fqdn_context.env.example ](env/fqdn_context.env.example ) you'll find an example environment file.
When everything's ready start {{ cookiecutter.__service_slug.capitalize() }} with Docker Compose, otherwise head down to [Initial setup ](#initial-setup ) first.
## Environment
2023-10-08 17:25:11 +02:00
2023-06-12 01:25:26 +02:00
```
export COMPOSE_DIR='/opt/containers/{{ cookiecutter.__project_slug }}'
2023-06-13 02:11:23 +02:00
export COMPOSE_CTX='ux_vilnius'
2023-06-12 01:25:26 +02:00
export COMPOSE_PROJECT='{{ cookiecutter.__service_slug }}-'"${COMPOSE_CTX}"
2023-10-08 17:41:59 +02:00
export COMPOSE_FILE="${COMPOSE_DIR}"'/compose.yaml'{% if cookiecutter.build == "yes" %}
export COMPOSE_OVERRIDE="${COMPOSE_DIR%/}"'/compose.override.yaml'{% endif %}
2023-06-12 01:25:26 +02:00
export COMPOSE_ENV=< add accordingly >
```
2023-06-24 23:12:32 +02:00
## Context
On your deployment machine create the necessary Docker context to connect to and control the Docker daemon on whatever target host you'll be using, for example:
```
docker context create fully.qualified.domain.name --docker 'host=ssh://root@fully .qualified.domain.name'
```
2023-06-12 01:25:26 +02:00
{%- if cookiecutter.build == "yes" %}
## Build
2023-06-24 23:22:41 +02:00
{%- set components = cookiecutter.__component_list_slug.split(',') -%}
{% for component in components %}
2023-10-08 17:24:44 +02:00
{% if loop.first %}
2023-06-25 00:11:22 +02:00
FIXME We build the `{{ cookiecutter.__service_slug }}` image locally. Our adjustment to the official image is simply adding `/tmp/{{ cookiecutter.__service_slug }}` to it. See {% if ',' in cookiecutter.__component_list_slug %}[build-context/{{ cookiecutter.__service_slug }}/Dockerfile ](build-context/{{ cookiecutter.__service_slug }}/Dockerfile ){%- else %}[build-context/Dockerfile ](build-context/Dockerfile ){%- endif %}. We use `/tmp/{{ cookiecutter.__service_slug }}` to bind-mount a dedicated ZFS dataset for the application's `tmpdir` location.
2023-06-24 23:22:41 +02:00
2023-06-12 01:25:26 +02:00
```
2023-06-24 23:30:37 +02:00
docker compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --file "${COMPOSE_OVERRIDE}" --env-file "${COMPOSE_ENV}" --profile 'build-{{ cookiecutter.__service_slug }}' build
2023-06-12 01:25:26 +02:00
```
{%- endif %}
2023-06-24 23:30:37 +02:00
{%- endfor %}
{%- endif %}
2023-06-12 01:25:26 +02:00
2023-06-24 23:36:59 +02:00
## Pull
2023-06-24 23:37:35 +02:00
{% if cookiecutter.build == "yes" %}FIXME Rewrite either [Build ](#build ) or this paragraph for which images are built and which ones pulled, `--profile 'full'` may not make sense FIXME {% endif %}Pull images from Docker Hub verbatim.
2023-06-24 23:36:59 +02:00
```
docker compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV}" --profile 'full' pull
```
2023-06-24 23:57:02 +02:00
## Copy to target
Copy images to target Docker host, that is assuming you deploy to a machine that itself has no network route to reach Docker Hub. Copying in its simplest form involves a local `docker save` and a remote `docker load` . Consider the helper mini-project [quico.space/Quico/copy-docker ](https://quico.space/Quico/copy-docker ) where [copy-docker.sh ](https://quico.space/Quico/copy-docker/src/branch/main/copy-docker.sh ) allows the following workflow:
```
source "${COMPOSE_ENV}"
2023-06-25 00:13:13 +02:00
# FIXME Docker Hub image name with or without slash? FIXME
2023-06-24 23:57:02 +02:00
{%- set components = cookiecutter.__component_list_slug.split(',') -%}
{%- if ',' in cookiecutter.__component_list_slug %}
for image in{% for component in components %} '{{ component }}:'"${% raw %}{{% endraw %}{{ component.upper() }}_VERSION{% raw %}}{% endraw %}"{%- endfor %}; do
copy-docker.sh "${image}" fully.qualified.domain.name
done
{%- else %}
2023-06-25 00:00:43 +02:00
copy-docker.sh '{{ cookiecutter.__component_list_slug }}:'"${% raw %}{{% endraw %}{{ cookiecutter.__component_list_slug.upper() }}_VERSION{% raw %}}{% endraw %}" fully.qualified.domain.name
2023-06-24 23:57:02 +02:00
{%- endif %}
```
2023-06-12 01:25:26 +02:00
## Start
```
{%- if ',' in cookiecutter.__component_list_slug %}
2023-06-21 00:27:23 +02:00
docker --context 'fully.qualified.domain.name' compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV}" --profile 'full' up --detach
2023-06-12 01:25:26 +02:00
{%- else %}
2023-06-21 00:27:23 +02:00
docker --context 'fully.qualified.domain.name' compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV}" up --detach
2023-06-12 01:25:26 +02:00
{%- endif %}
```
# Initial setup
We're assuming you run Docker Compose workloads with ZFS-based bind mounts. ZFS management, creating a zpool and setting adequate properties for its datasets is out of scope of this document.
## Datasets
Create ZFS datasets and set permissions as needed.
* Parent dateset
```
zfs create -o mountpoint=/opt/docker-data 'zpool/docker-data'
```
* Container-specific datasets
```
{%- if ',' in cookiecutter.__component_list_slug -%}
{%- set components = cookiecutter.__component_list_slug.split(',') -%}
{%- for component in components %}
2023-06-13 02:11:23 +02:00
zfs create -p 'zpool/docker-data/{{ cookiecutter.__service_slug }}-'"${COMPOSE_CTX}"'/{{ component }}/data/db'
zfs create -p 'zpool/docker-data/{{ cookiecutter.__service_slug }}-'"${COMPOSE_CTX}"'/{{ component }}/data/logs'
zfs create -p 'zpool/docker-data/{{ cookiecutter.__service_slug }}-'"${COMPOSE_CTX}"'/{{ component }}/config'
2023-06-12 01:25:26 +02:00
{%- endfor -%}
{%- else %}
2023-06-13 02:11:23 +02:00
zfs create -p 'zpool/docker-data/{{ cookiecutter.__service_slug }}-'"${COMPOSE_CTX}"'/{{ cookiecutter.__service_slug }}/data/db'
zfs create -p 'zpool/docker-data/{{ cookiecutter.__service_slug }}-'"${COMPOSE_CTX}"'/{{ cookiecutter.__service_slug }}/data/logs'
zfs create -p 'zpool/docker-data/{{ cookiecutter.__service_slug }}-'"${COMPOSE_CTX}"'/{{ cookiecutter.__service_slug }}/config'
2023-06-12 01:25:26 +02:00
{%- endif %}
```
2023-10-08 17:41:59 +02:00
FIXME When changing bind mount locations to real ones remember to also update `volumes:` in [compose.yaml ](compose.yaml ) FIXME
2023-06-12 01:25:26 +02:00
2023-06-13 02:11:23 +02:00
* Create subdirs
```
{%- set components = cookiecutter.__component_list_slug.split(',') -%}
{% for component in components %}
{%- if loop.first %}
mkdir -p '/opt/docker-data/{{ cookiecutter.__service_slug }}-'"${COMPOSE_CTX}"'/{{ cookiecutter.__service_slug }}/'{'.ssh','config','data','projects'}
{%- endif %}
{%- endfor %}
```
2023-06-12 01:25:26 +02:00
* Change ownership
```
{%- set components = cookiecutter.__component_list_slug.split(',') -%}
{% for component in components %}
{%- if loop.first %}
2023-06-24 23:01:00 +02:00
chown -R 1000:1000 '/opt/docker-data/{{ cookiecutter.__service_slug }}-${COMPOSE_CTX}/{{ cookiecutter.__service_slug }}/data/'{*,.*}
2023-06-12 01:25:26 +02:00
{%- endif %}
{%- endfor %}
```
2023-06-14 22:11:04 +02:00
## Additional files
Place the following files on target server. Use the directory structure at [build-context ](build-context ) as a guide, specifically at `docker-data` .
2023-06-24 23:37:35 +02:00
FIXME Add details about files that aren't self-explanatory FIXME
2023-06-24 23:27:59 +02:00
2023-06-14 22:11:04 +02:00
```
build-context/
{%- if ',' in cookiecutter.__component_list_slug -%}
{%- set components = cookiecutter.__component_list_slug.split(',') -%}
{%- for component in components %}
{%- if not loop.last %}
├── {{ component }}
│ ├── docker-data
│ | └── config
│ │ └── {{ component }}.cfg
2023-06-24 23:57:58 +02:00
│ ├── ...
│ └── ...
2023-06-14 22:11:04 +02:00
{%- else %}
└── {{ component }}
├── docker-data
| └── config
│ └── {{ component }}.cfg
2023-06-24 23:57:58 +02:00
├── ...
└── ...
2023-06-14 22:11:04 +02:00
{%- endif %}
{%- endfor %}
{%- else %}
├── docker-data
│ └── config
│ └── {{ cookiecutter.__service_slug }}.cfg
2023-06-24 23:57:58 +02:00
├── ...
└── ...
2023-06-14 22:11:04 +02:00
{%- endif %}
```
2023-06-12 01:25:26 +02:00
When done head back up to [How to run ](#how-to-run ).
2023-10-08 17:16:03 +02:00
# Development
## Conventional commits
This project uses [Conventional Commits ](https://www.conventionalcommits.org/ ) for its commit messages.
### Commit types
Commit _types_ besides `fix` and `feat` are:
- `refactor` : Keeping functionality while streamlining or otherwise improving function flow
- `docs` : Documentation for project or components
### Commit scopes
The following _scopes_ are known for this project. A Conventional Commits commit message may optionally use one of the following scopes or none:
2023-10-08 17:18:50 +02:00
{%if ',' in cookiecutter.__component_list_slug -%}
2023-10-08 17:16:03 +02:00
{%- set components = cookiecutter.__component_list_slug.split(',') -%}
{%- for component in components %}
- `{{ component }}` : A change to how the `{{ component }}` service component works
{%- endfor -%}
{%- else %}
- `{{ cookiecutter.__service_slug }}` : A change to how the `{{ cookiecutter.__service_slug }}` service component works
{%- endif %}
- `build` : Build-related changes such as `Dockerfile` fixes and features.
- `mount` : Volume or bind mount-related changes.
- `net` : Networking, IP addressing, routing changes
- `meta` : Affects the project's repo layout, file names etc.