153 lines
6.3 KiB
Markdown
153 lines
6.3 KiB
Markdown
# _FIXME_
|
|
|
|
Search and replace all mentions of _FIXME_ with sensible content in this file and in [docker-compose.yml](docker-compose.yml).
|
|
|
|
# {{ cookiecutter.__service_slug.capitalize() }} Docker Compose files
|
|
|
|
Docker Compose files to spin up an instance of {{ cookiecutter.__service_slug.capitalize() }} _FIXME_ capitalization _FIXME_.
|
|
|
|
# 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
|
|
```
|
|
export COMPOSE_DIR='/opt/containers/{{ cookiecutter.__project_slug }}'
|
|
export COMPOSE_CTX='ux_vilnius'
|
|
export COMPOSE_PROJECT='{{ cookiecutter.__service_slug }}-'"${COMPOSE_CTX}"
|
|
export COMPOSE_FILE="${COMPOSE_DIR}"'/docker-compose.yml'{% if cookiecutter.build == "yes" %}
|
|
export COMPOSE_OVERRIDE="${COMPOSE_DIR%/}"'/docker-compose.override.yml'{% endif %}
|
|
export COMPOSE_ENV=<add accordingly>
|
|
```
|
|
|
|
## 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'
|
|
```
|
|
|
|
{%- if cookiecutter.build == "yes" %}
|
|
|
|
## Build
|
|
|
|
{%- set components = cookiecutter.__component_list_slug.split(',') -%}
|
|
{% for component in components %}
|
|
{%- if loop.first %}
|
|
_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 [build-context/{{ cookiecutter.__service_slug }}/Dockerfile](build-context/{{ cookiecutter.__service_slug }}/Dockerfile). We use `/tmp/{{ cookiecutter.__service_slug }}` to bind-mount a dedicated ZFS dataset for the application's `tmpdir` location.
|
|
|
|
```
|
|
docker compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --file "${COMPOSE_OVERRIDE}" --env-file "${COMPOSE_ENV}" --profile 'build-{{ cookiecutter.__service_slug }}' build
|
|
```
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
{%- endif %}
|
|
|
|
## Pull
|
|
|
|
{% 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.
|
|
|
|
```
|
|
docker compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV}" --profile 'full' pull
|
|
```
|
|
|
|
## Start
|
|
|
|
```
|
|
{%- if ',' in cookiecutter.__component_list_slug %}
|
|
docker --context 'fully.qualified.domain.name' compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV}" --profile 'full' up --detach
|
|
{%- else %}
|
|
docker --context 'fully.qualified.domain.name' compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV}" up --detach
|
|
{%- 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 %}
|
|
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'
|
|
{%- endfor -%}
|
|
{%- else %}
|
|
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'
|
|
{%- endif %}
|
|
```
|
|
_FIXME_ delete when all is done _FIXME_ When changing bind mount locations to real ones remember to also update `volumes:` in [docker-compose.yml](docker-compose.yml).
|
|
|
|
* 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 %}
|
|
```
|
|
|
|
* Change ownership
|
|
```
|
|
{%- set components = cookiecutter.__component_list_slug.split(',') -%}
|
|
{% for component in components %}
|
|
{%- if loop.first %}
|
|
chown -R 1000:1000 '/opt/docker-data/{{ cookiecutter.__service_slug }}-${COMPOSE_CTX}/{{ cookiecutter.__service_slug }}/data/'{*,.*}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
```
|
|
|
|
## 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`.
|
|
|
|
_FIXME_ Add details about files that aren't self-explanatory _FIXME_
|
|
|
|
```
|
|
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
|
|
│ ├── Dockerfile
|
|
│ └── extras
|
|
{%- else %}
|
|
└── {{ component }}
|
|
├── docker-data
|
|
| └── config
|
|
│ └── {{ component }}.cfg
|
|
├── Dockerfile
|
|
└── extras
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
{%- else %}
|
|
├── docker-data
|
|
│ └── config
|
|
│ └── {{ cookiecutter.__service_slug }}.cfg
|
|
├── Dockerfile
|
|
└── extras
|
|
{%- endif %}
|
|
```
|
|
|
|
When done head back up to [How to run](#how-to-run).
|