Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Set the API URL at run time; stop using the deprecated onbuild base img
Browse files Browse the repository at this point in the history
Provide simple docker image for API devs #1013
  • Loading branch information
metas-ts committed Jul 15, 2017
1 parent a7b0c5f commit c74d7a1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
30 changes: 15 additions & 15 deletions docker/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
#
# this docker file that shall allow API developers to run the metasfresh-webui-frontend in a container,
# This docker file shall allow API developers to run the metasfresh-webui-frontend in a container,
# without the need to locally install npm and node.
# Maybe in future also the CI pipeline might use it.
#
# To build it, go to this repo's base dir and run something like
# docker build --file ./docker/Dockerfile-dev --build-arg API_URL=http://$(hostname):8080 --tag metasfresh-webui-frontend-dev .
# docker build --file ./docker/Dockerfile-dev --tag metasfresh-webui-frontend-dev .
#
# To run it, run something like
# docker run --name metasfresh-webui-frontend -p 3000:3000 -d metasfresh-webui-frontend-dev
# docker run --name metasfresh-webui-frontend -p 3000:3000 -e "API_URL=http://$(hostname):8080" -d metasfresh-webui-frontend-dev
#
# About `--build-arg API_URL=http://$(hostname):8080`:
# The API-URL for the webui-frontend to connect with is baked into the docker image's config.js file at build time.
# About `-e "API_URL=http://$(hostname):8080"`:
# The API-URL for the webui-api service to connect is written into the docker image's config.js file when the container is run,
# right before the nodejs server is started.
# The value `http://$(hostname):8080` assumes that you run the webui-api on port 8080 on the same host that the docker image is build on.
#
# Also see https://github.com/metasfresh/metasfresh-webui-frontend/issues/1013
#

FROM node:6-onbuild

ARG API_URL=localhost
FROM node:8

ENV DOCKER true
ENV API_URL=$API_URL

RUN npm install webpack -g

Expand All @@ -35,13 +33,15 @@ COPY . /usr/src/app/
# Install node_packages
RUN npm install

# Use default config with "hardcoded API URL
# RUN cp ./config.js.dist ./config.js

# create a config with API URL taken from $API_URL
RUN docker/config_from_env.sh > config.js
# Copy the script which shall output the correct config.js used by the server when the container starts
COPY docker/config_from_env.sh config_from_env.sh
RUN chmod +x config_from_env.sh

RUN echo "We will run with the following config.js file:" && cat config.js
# Copy the script that shall actually start the nodejs server within the container
COPY docker/provision_config_and_start_server.sh provision_config_and_start_server.sh
RUN chmod +x provision_config_and_start_server.sh

EXPOSE 3000

CMD [ "/usr/src/app/provision_config_and_start_server.sh" ]

5 changes: 3 additions & 2 deletions docker/config_from_env.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

# generates a config.js file such that the webui-frontend connects to the API-server set via API URL
#
# This script outputs a config.js file such that the webui-frontend connects to the API-server set in $API_URL
# see https://github.com/metasfresh/metasfresh-webui-frontend/issues/1013#issuecomment-314999729
#

echo "const config = {"
echo " API_URL: '$API_URL/rest/api',"
Expand Down
10 changes: 10 additions & 0 deletions docker/provision_config_and_start_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
#
# This short script calls config_from_env.sh to write the config.js with the API_URL take from the environment and then starts the nodejs server.
# See the Dockerfile for further infos.
#

/usr/src/app/config_from_env.sh > /usr/src/app/config.js && \
echo "We will run with the following config.js file:" && \
cat /usr/src/app/config.js && \
npm start

0 comments on commit c74d7a1

Please sign in to comment.