Skip to content

Commit

Permalink
Merge pull request #3782 from camptocamp/template-config
Browse files Browse the repository at this point in the history
 Add template interpretation in config
  • Loading branch information
sbrunner committed Jun 1, 2018
2 parents fc29569 + e0dc449 commit 79feadc
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 43 deletions.
8 changes: 8 additions & 0 deletions docker/build/bin/eval-templates
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e

find /app/ -name *.tmpl -print | while read file
do
envsubst < ${file} > ${file%.tmpl}
done

exec "$@"
4 changes: 2 additions & 2 deletions docker/build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Babel==2.5.3 # i18n
boto3==1.7.4 # Tile generation
bottle==0.12.13 # geoportal
c2c.cssmin==0.7.dev6 # CGXP build
c2c.template==2.0.9 # geoportal
c2c.template==2.1.0.dev1 # geoportal
c2cgeoform==2.0.dev20180527 # commons
codacy-coverage==1.3.11 # Codacy send report
codespell==1.12.0 # Lint
Expand Down Expand Up @@ -65,7 +65,7 @@ Sphinx==1.7.2 # doc
sphinx-prompt==1.0.0 # doc
SQLAlchemy==1.2.6
tilecloud==0.5.1 # Tile generation
tilecloud-chain==1.5.0 # Tile generation
tilecloud-chain==1.5.2 # Tile generation
transaction==2.2.1 # commons, geoportal
transifex-client==0.12.5 # Makefile, rq.filter: >=0.14
translationstring==1.3 # admin
Expand Down
39 changes: 17 additions & 22 deletions geoportal/c2cgeoportal_geoportal/scaffolds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ def _epsg2bbox(srid):
return None


def fix_executables(output_dir, patterns, in_const_create_template=False):
if os.name == 'posix':
for pattern in patterns:
if in_const_create_template:
pattern = os.path.join(output_dir, "CONST_create_template", pattern)
else:
pattern = os.path.join(output_dir, pattern)
for file_ in glob.glob(pattern):
subprocess.check_call(["chmod", "+x", file_])


class TemplateCreate(BaseTemplate): # pragma: no cover
_template_dir = "create"
summary = "Template used to create a c2cgeoportal project"
Expand All @@ -157,10 +168,7 @@ def post(self, command, output_dir, vars_):
Overrides the base template class to print the next step.
"""

if os.name == 'posix':
for file_ in ("docker-run", "docker-compose-run"):
dest = os.path.join(output_dir, file_)
subprocess.check_call(["chmod", "+x", dest])
fix_executables(output_dir, ("docker-run", "docker-compose-run", "bin/*"))

self.out("\nContinue with:")
self.out(colorize(
Expand Down Expand Up @@ -198,10 +206,8 @@ def post(self, command, output_dir, vars_):
after a successful scaffolding rendering.
"""

if os.name == 'posix':
for file_ in ("docker-run", "docker-compose-run"):
dest = os.path.join(output_dir, "CONST_create_template", file_)
subprocess.check_call(["chmod", "+x", dest])
fix_executables(output_dir, ("docker-run", "docker-compose-run", "bin/*"), True)

self.out(colorize("\nWelcome to c2cgeoportal!", GREEN))

return BaseTemplate.post(self, command, output_dir, vars_)
Expand All @@ -216,13 +222,8 @@ def pre(self, command, output_dir, vars_):
return super().pre(command, output_dir, vars_)

def post(self, command, output_dir, vars_):
if os.name == 'posix':
for glob_ in (
"get-pip-dependencies",
"deploy/hooks/*",
):
for file_ in glob.glob(os.path.join(output_dir, glob_)):
subprocess.check_call(["chmod", "+x", file_])
fix_executables(output_dir, ("get-pip-dependencies", "deploy/hooks/*"))

return super().post(command, output_dir, vars_)


Expand All @@ -236,12 +237,6 @@ def pre(self, command, output_dir, vars_):
return BaseTemplate.pre(self, command, output_dir, vars_)

def post(self, command, output_dir, vars_):
if os.name == 'posix':
for glob_ in (
"get-pip-dependencies",
"deploy/hooks/*",
):
for file_ in glob.glob(os.path.join(output_dir, "CONST_create_template", glob_)):
subprocess.check_call(["chmod", "+x", file_])
fix_executables(output_dir, ("get-pip-dependencies", "deploy/hooks/*"), True)

return BaseTemplate.post(self, command, output_dir, vars_)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*
!bin/
!front/
!mapserver/
!qgisserver/
Expand Down
16 changes: 13 additions & 3 deletions geoportal/c2cgeoportal_geoportal/scaffolds/create/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
FROM tianon/true:latest
FROM debian:jessie
LABEL maintainer Camptocamp "info@camptocamp.com"

RUN \
apt-get update && \
apt-get install --assume-yes --no-install-recommends gettext-base && \
apt-get clean && \
rm --recursive --force /var/lib/apt/lists/*

COPY bin/* /usr/bin/

COPY mapserver /etc/mapserver
VOLUME /etc/mapserver

Expand All @@ -10,11 +18,13 @@ VOLUME /etc/mapserver
COPY mapcache /mapcache
VOLUME /mapcache

COPY tilegeneration /tilecloudchain
VOLUME /tilecloudchain
COPY tilegeneration /etc/tilecloudchain
VOLUME /etc/tilecloudchain

COPY print/print-apps /usr/local/tomcat/webapps/ROOT/print-apps
VOLUME /usr/local/tomcat/webapps/ROOT/print-apps

COPY front /etc/haproxy
VOLUME /etc/haproxy

ENTRYPOINT [ "/usr/bin/eval-templates" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e

find /etc /mapcache -name *.tmpl -print | while read file
do
envsubst < ${file} > ${file%.tmpl}
done

exec "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ backend geoportal


backend tilecloudchain
option httpchk GET /tiles HTTP/1.0\r\nUser-Agent:\ healthcheck
option httpchk GET ${VISIBLE_ENTRY_POINT}tiles HTTP/1.0\r\nUser-Agent:\ healthcheck
http-check expect status 200
server linked tilecloudchain:80 resolvers dns #check

Expand All @@ -69,7 +69,7 @@ frontend plain
http-request set-var(req.path) path

# If the path starts with /tiles/, use the tilecloudchain backend
acl is_tiles var(req.path) -m beg /tiles/
acl is_tiles var(req.path) -m beg ${VISIBLE_ENTRY_POINT}tiles/
use_backend tilecloudchain if is_tiles

# Redirect all to geoportal by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ RUN pip install --disable-pip-version-check --no-cache-dir --no-deps --editable=
python -m compileall -q /app/${package}_geoportal -x /app/${package}_geoportal/static.* && \
c2cwsgiutils_genversion.py $GIT_HASH

ENTRYPOINT []
ENTRYPOINT [ "/usr/bin/eval-templates" ]
CMD ["c2cwsgiutils_run"]
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ caches:
folder: /var/sig/tiles
wmtscapabilities_file: ${wmtscapabilities_path}
# for GetCapabilities
http_url: https://%(host)s/tiles/
hosts:
- wmts0.<host>
- wmts1.<host>
- wmts2.<host>
- wmts3.<host>
- wmts4.<host>
http_url: ${web_protocol}://${host}${entry_point}tiles/
s3:
type: s3
bucket: tiles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ DOCKER_ENTRY_POINT ?= /
else
DOCKER_ENTRY_POINT ?= /_$(INSTANCE)/
endif
DOCKER_WEB_HOST ?= localhost
DOCKER_WEB_PROTOCOL ?= 443
export DOCKER_ENTRY_POINT
export DOCKER_WEB_HOST
export DOCKER_WEB_PROTOCOL

MAPSERVER ?= TRUE

Expand Down Expand Up @@ -473,11 +477,13 @@ endif

%: %.mako /build/c2ctemplate-cache.json
$(PRERULE_CMD)
c2c-template --cache /build/c2ctemplate-cache.json --engine mako --files $<
c2c-template --cache /build/c2ctemplate-cache.json --engine mako \
--runtime-environment-pattern '$${{'{{'}}{}}}' --files $<

%: %.jinja /build/c2ctemplate-cache.json
$(PRERULE_CMD)
c2c-template --cache /build/c2ctemplate-cache.json --engine jinja --files $<
c2c-template --cache /build/c2ctemplate-cache.json --engine jinja \
--runtime-environment-pattern '$${{'{{'}}{}}}' --files $<

geoportal/config.yaml: /build/c2ctemplate-cache.json
$(PRERULE_CMD)
Expand Down Expand Up @@ -710,7 +716,8 @@ testdb/11-schemas.sql: $(ALEMBIC_YAML_FILE) testdb/11-schemas.sql_mako vars.yaml
$(PRERULE_CMD)
rm --force testdb/11-schemas.sql.mako
ln -s 11-schemas.sql_mako testdb/11-schemas.sql.mako
c2c-template --vars $< --engine mako --files testdb/11-schemas.sql.mako
c2c-template --vars $< --engine mako --runtime-environment-pattern '$${{'{{'}}{}}}' \
--files testdb/11-schemas.sql.mako
rm testdb/11-schemas.sql.mako

testdb/12-alembic.sql: alembic.ini alembic.yaml $(shell ls -1 /opt/alembic/main/*.py)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,30 @@ vars:
web_protocol: '{VISIBLE_WEB_PROTOCOL}'
entry_point: '{VISIBLE_ENTRY_POINT}'
dev_server_port: '{DEV_SERVER_PORT}'
docker_entry_point: '{DOCKER_ENTRY_POINT}'
docker_host: '{DOCKER_WEB_HOST}'
docker_web_protocol: '{DOCKER_WEB_PROTOCOL}'

# Docker base image name (comes from the makefile).
docker_base: '{DOCKER_BASE}'
docker_tag: '{DOCKER_TAG}'
docker_global_front: false
docker_services:
config:
environment:
VISIBLE_WEB_HOST: '{docker_entry_point}'
VISIBLE_WEB_PROTOCOL: '{docker_web_protocol}'
VISIBLE_ENTRY_POINT: '{docker_entry_point}'
db:
environment:
POSTGRES_DB: geomapfish
POSTGRES_USER: www-data
POSTGRES_PASSWORD: www-data
geoportal:
environment:
VISIBLE_WEB_HOST: localhost:80
VISIBLE_WEB_PROTOCOL: https
VISIBLE_ENTRY_POINT: '{DOCKER_ENTRY_POINT}'
VISIBLE_WEB_HOST: '{docker_entry_point}'
VISIBLE_WEB_PROTOCOL: '{docker_web_protocol}'
VISIBLE_ENTRY_POINT: '{docker_entry_point}'
PGHOST: 172.17.0.1
PGHOST_SLAVE: 172.17.0.1
PGPORT: 5432
Expand All @@ -44,6 +52,10 @@ vars:
PRINT_URL: http://print:8080/print/
REDIS_HOST: redis
REDIS_PORT: 6379
tilecloudchain:
environment:
VISIBLE_ENTRY_POINT: '{docker_entry_point}'
TILEGENERATION_CONFIGFILE: /etc/tilegeneration/config.yaml
front:
port: 80

Expand Down Expand Up @@ -496,6 +508,8 @@ environment:
- GEOMAPFISH_VERSION
- DOCKER_BASE
- DOCKER_TAG
- DOCKER_WEB_PROTOCOL
- DOCKER_WEB_HOST
- DOCKER_ENTRY_POINT
- DEVELOPMENT
- WMTSCAPABILITIES_PATH
Expand Down

0 comments on commit 79feadc

Please sign in to comment.