Initial commit

This commit is contained in:
hygienic-books 2022-06-04 04:15:59 +02:00
parent 4c3148c203
commit e379cdafe0
6 changed files with 116 additions and 0 deletions

View File

@ -0,0 +1,6 @@
{
"component_s": "grafana,nginx",
"service": "example_service",
"context": "example_context",
"project_slug": "{% if cookiecutter.service is defined and cookiecutter.service|length > 0 %}{{ cookiecutter.service.lower().replace(' ', '_').replace('-', '_') }}-{% endif %}{{ cookiecutter.component_s.lower().replace(' ', '_').replace('-', '_') }}-{{ cookiecutter.context.lower().replace(' ', '_').replace('-', '_') }}"
}

View File

@ -0,0 +1,44 @@
#print("{% set components = cookiecutter.component_s.split(',') -%}
#{% for component in components -%}
# {{ component }}
# {%- if not loop.last -%}
# ,
# {%- endif %}
#{%- endfor %}")
import os
import sys
component_subdirs = ["extras", "docker-data"]
components = ["grafana", "nginx"]
project_dir = os.getcwd()
build_context_dir_name = "build-context"
build_ctx_dir_abs = os.path.join(project_dir, build_context_dir_name)
for component in components:
component_dir_abs = os.path.join(build_ctx_dir_abs, component)
component_dir_rel = os.path.relpath(component_dir_abs, project_dir)
try:
os.mkdir(component_dir_abs)
except FileExistsError:
print(f"Dir './{component_dir_rel}' already exists when it shouldn't. Aborting and exiting 1 ...")
sys.exit(1)
for component_subdir_name in component_subdirs:
component_subdir_abs = os.path.join(component_dir_abs, component_subdir_name)
try:
os.mkdir(component_subdir_abs)
except FileExistsError:
print(f"Dir '{component_subdir_name}' inside './{component_dir_rel}' exists when it shouldn't. "
f"Aborting and exiting 1 ...")
sys.exit(1)
for root, subdirs, filelist in os.walk(project_dir):
for subdir_name in subdirs:
if subdir_name in component_subdirs:
subdir_abs = os.path.join(root, subdir_name)
gitkeep_file_abs = os.path.join(subdir_abs, ".gitkeep")
gitkeep_file_rel = os.path.relpath(gitkeep_file_abs, project_dir)
try:
with open(gitkeep_file_abs, mode='a'):
pass
except IOError:
print(f"Can't write './{gitkeep_file_rel}'. Aborting and exiting 2 ...")
sys.exit(2)

View File

@ -0,0 +1,11 @@
services:
common-settings:
environment:
TZ: "${TIMEZONE:-Etc/UTC}"
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "10"
compress: "true"
restart: "${RESTARTPOLICY:-unless-stopped}"

View File

@ -0,0 +1,12 @@
services:
{%- set components = cookiecutter.component_s_canon.split(',') -%}
{% for component in components %}
{{ component }}-build:
image: "{{ component }}:${% raw %}{{% endraw %}{{ component.upper() }}_VERSION{% raw %}}{% endraw %}"
profiles: ["build", "build-{{ component }}"]
build:
context: "build-context/{{ component }}"
dockerfile: Dockerfile
args:
EXAMPLE_ARG_FOR_DOCKERFILE: ${EXAMPLE_ARG_FROM_ENV_FILE}
{%- endfor %}

View File

@ -0,0 +1,11 @@
services:
{%- if ',' in cookiecutter.component_s_canon -%}
{%- set components = cookiecutter.component_s_canon.split(',') -%}
{% for component in components %}
{{ component }}:
container_name: {{ cookiecutter.service_canon }}-{{ component }}-${CONTEXT}
{%- endfor %}
{%- else -%}
{{ component }}:
container_name: {{ cookiecutter.component_s_canon }}-${CONTEXT}
{%- endif -%}

View File

@ -0,0 +1,32 @@
CONTEXT={{ cookiecutter.context_canon }}
# Set something sensible here and uncomment
# ---
{%- set components = cookiecutter.component_s_canon.split(',') -%}
{% for component in components %}
# {{ component.upper() }}_VERSION=x.y.z
{%- endfor %}
# A ${LOCATION} var is usually not needed. It may be helpful when a ${CONTEXT}
# extends over more than one location e.g. to bind-mount location-specific
# config files or certificates into a container.
# ---
# LOCATION=
# Feel free to leave defaults. They apply while these vars are commented out
# ---
# RESTARTPOLICY=unless-stopped
# TIMEZONE=Etc/UTC
# See 'docker-compose.override.yml' for how to make a variable available in
# a Dockerfile
# ---
# EXAMPLE_ARG_FROM_ENV_FILE=must_be_available_in_dockerfile