diff --git a/roles/container/tasks/main.yml b/roles/container/tasks/main.yml index 39a227d..8a9c014 100644 --- a/roles/container/tasks/main.yml +++ b/roles/container/tasks/main.yml @@ -1,5 +1,20 @@ --- +- name: Deprecation warning + debug: + msg: > + The role uumas.docker.container has been deprecated. You should switch to + uumas.docker.service instead. It has the following syntax changes:\n + * container name suffixes are separated by - instead of _\n + * May require updating hostnames in configs or database\n + * May require fixing any ports, database_passwords or + docker_vhost_domains variables to new syntax\n + * May require renaming database user and database for existing database + * docker_volume_type defaults to bind. Set it to named if you want to + continue using named volumes.\n + uumas.docker.container doesn't receive any updates and may be removed + after May 2024 + - name: Container role initialization import_tasks: init.yml diff --git a/roles/service/README.md b/roles/service/README.md new file mode 100644 index 0000000..08dc257 --- /dev/null +++ b/roles/service/README.md @@ -0,0 +1 @@ +Sets up a docker service diff --git a/roles/service/defaults/main.yml b/roles/service/defaults/main.yml new file mode 100644 index 0000000..0fa855c --- /dev/null +++ b/roles/service/defaults/main.yml @@ -0,0 +1,28 @@ +--- + +docker_namespace: "{{ docker_service }}" +docker_service_suffix: "" +docker_volume_type: bind +docker_restart_policy: always + +reverse_proxy_type: caddy +docker_proxy_target_protocol: http + +docker_additional_env: {} +docker_additional_services: [] +docker_database: none +docker_mounts: [] +docker_network_mode: "" +docker_networks: [] +docker_env: {} + +docker_published_ports: [] +docker_host_user: false +dockerfile: [] + +docker_mariadb_config: {} +docker_redis_persistence: false +docker_phpmyadmin_basicauth: true +docker_phpmyadmin_basicauth_users: {} + +timezone: Etc/UTC diff --git a/roles/service/handlers/main.yml b/roles/service/handlers/main.yml new file mode 100644 index 0000000..83ff5e5 --- /dev/null +++ b/roles/service/handlers/main.yml @@ -0,0 +1,13 @@ +--- + +- name: Restart container + community.docker.docker_container: + name: "{{ docker_service_name }}" + restart: true + when: not container_out.changed + +- name: Ensure container running + community.docker.docker_container: + name: "{{ docker_service_name }}" + state: started + when: not ansible_check_mode diff --git a/roles/service/meta/argument_specs.yml b/roles/service/meta/argument_specs.yml new file mode 100644 index 0000000..b1e9116 --- /dev/null +++ b/roles/service/meta/argument_specs.yml @@ -0,0 +1,216 @@ +--- + +argument_specs: + main: + short_description: Docker service + description: "Sets up a docker service. Supports defining networks, building a custom image, setting up memcached, databases and a reverse proxy, creating a user on the host to run the container as, named volumes, bind mounts (either auto-created or existing)." + options: + docker_service: + description: "The name of the docker service (example: gitea)" + type: str + required: true + docker_namespace: + description: The namespace of the service. This can be used when multiple containers should be part of the service. Used as the default network, the name of the directory where bind mounts are created and the prefix for volume names. + type: str + required: false + default: "{{ docker_service }}" + docker_service_suffix: + description: "A suffix used to allow running multiple instances of the same service on a host. If docker_service is gitea and docker_service_suffix production, the service will be gitea-production" + type: str + required: false + default: "" + docker_image: + description: "Docker image to use for the container. If dockerfile is defined, it will be used as base for locally built image (example: gitea/gitea:latest)" + type: str + required: true + dockerfile: + description: "A list of dockerfile instructions to add to the base image" + type: list + elements: str + required: false + default: [] + docker_host_user: + description: "If true, creates a user on the host for this service. The container will run as this user's uid/gid. Bind mount volumes will be owned by this user." + type: bool + required: false + default: true + + docker_database: + description: "Database type to set up. It will be run in a docker container accessible to the service at host -db on default port." + type: str + required: false + choices: + - postgres + - mariadb + - mongo + - none + default: none + database_passwords: + description: > + database_passwords[docker_service] is a string with the password used + for communication between the service and database. Required if + docker_database is postgres or mariadb. For mariadb, you can also + define database_passwords[docker_service + '_root'] if you want to + set a password for the mariadb root user + type: dict + required: false + docker_mariadb_config: + description: | + A dict specifying config for mariadb. For example + mysqld: + innodb_buffer_pool_size: '4G' + aria_pagecache_buffer_size': '4G' + would set + [mysqld] + innodb_buffer_pool_size = 4G + aria_pagecache_buffer_size = 4G + type: dict + required: false + default: {} + docker_additional_services: + description: "List of additional services to configure (in separate containers). These will be accessible with hostname [_suffix]_" + type: list + required: false + elements: str + choices: + - memcached + - redis + default: [] + docker_redis_persistence: + description: Whether to save redis data to persistent storage + type: bool + required: false + default: false + docker_phpmyadmin_basicauth: + description: Whether to enable basicauth for phpmyadmin + type: bool + required: false + default: true + docker_phpmyadmin_basicauth_users: + description: Dict of users and their password hashes for phpmyadmin basic auth. Required if docker_phpmyadmin_basicauth is true and phpmyadmin is used. + type: dict + required: false + default: {} + + docker_volume_type: + description: "Defines whether to use named volumes or bind mounts for mounts with name" + type: str + required: false + choices: + - named + - bind + default: named + docker_mounts: + description: "List of bind mounts or volumes to be mounted inside the container. Each element is a dict with path and exactly one of name, src or template" + type: list + required: false + default: [] + elements: dict + options: + path: + description: "The path inside the container to mount at" + type: str + required: true + readonly: + description: "If true, volume will be mounted as read only inside the container. Only applies for named and src mounts." + type: bool + required: false + default: false + mode: + description: "Permissions for the created/templated directory. Defaults to '0644' for files, '0755' for directories. Doesn't apply for named volumes." + type: str + required: false + name: + description: "If docker_volume_type is named, the name of the named volume to be mounted at path. If docker_volume_type is bind, the name of the folder to create under /opt/[/suffix]/mounts/ and mount at path." + type: str + required: false + src: + description: "Host path to bind mount inside the container." + type: str + required: false + template: + description: "Name of template without .j2 extension. Will be templated at /opt/[/suffix]/mounts/