Skip to content

Instantly share code, notes, and snippets.

@alombarte
Last active April 22, 2024 02:42
Show Gist options
  • Save alombarte/406adb859e9230b7f19a15a5b4b1003a to your computer and use it in GitHub Desktop.
Save alombarte/406adb859e9230b7f19a15a5b4b1003a to your computer and use it in GitHub Desktop.
Multi-stage build to compile krakend's flexible configuration
FROM devopsfaith/krakend as builder
ARG ENV=prod
COPY krakend.tmpl .
COPY config .
# Save temporary file to /tmp to avoid permission errors
RUN FC_ENABLE=1 \
FC_OUT=/tmp/krakend.json \
FC_PARTIALS="/etc/krakend/partials" \
FC_SETTINGS="/etc/krakend/settings/$ENV" \
FC_TEMPLATES="/etc/krakend/templates" \
krakend check -d -t -c krakend.tmpl
FROM devopsfaith/krakend
COPY --from=builder --chown=krakend /tmp/krakend.json .
@alombarte
Copy link
Author

alombarte commented Jul 16, 2020

This gist uses krakend check command with -d and -t flags, meaning that after compiling the templates will show the debug of the parsed configuration and will test starting the service. Trying to start the service is safer than just validating that the template compiled, as the file can be perfectly valid but yet have conflicting routes.

Example of the assumed file structure:

.
├── config
│   ├── partials
│   ├── settings
│   │   ├── prod
│   │   │   └── env.json
│   │   └── test
│   │       └── env.json
│   └── templates
│       └── some.tmpl
├── Dockerfile
└── krakend.tmpl

Build for another environment with:
docker build --build-arg ENV=test -t krakend-test .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment