From 3ce9baee304dba8d6e05470878543ab0e78d1994 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Tue, 11 Apr 2017 13:59:34 -0700 Subject: [PATCH] added variables for docker --- Dockerfile | 15 ++++++++++++++- docker-run.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 docker-run.sh diff --git a/Dockerfile b/Dockerfile index cde62882..a3ef6c28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,18 @@ FROM alpine:3.4 MAINTAINER fehguy +ENV VERSION "v2.2.10" +ENV FOLDER "swagger-ui-2.2.10" +ENV API_URL "http://petstore.swagger.io/v2/swagger.json" +ENV API_KEY "**None**" +ENV OAUTH_CLIENT_ID "**None**" +ENV OAUTH_CLIENT_SECRET "**None**" +ENV OAUTH_REALM "**None**" +ENV OAUTH_APP_NAME "**None**" +ENV OAUTH_ADDITIONAL_PARAMS "**None**" +ENV SWAGGER_JSON "/app/swagger.json" +ENV PORT 80 + RUN apk add --update nginx RUN mkdir -p /run/nginx @@ -9,7 +21,8 @@ COPY nginx.conf /etc/nginx/ # copy swagger files to the `/js` folder ADD ./dist/* /usr/share/nginx/html/ +ADD ./docker-run.sh /usr/share/nginx/ EXPOSE 8080 -CMD exec nginx -g 'daemon off;' +CMD ["sh", "/usr/share/nginx/docker-run.sh"] diff --git a/docker-run.sh b/docker-run.sh new file mode 100644 index 00000000..6e70a77b --- /dev/null +++ b/docker-run.sh @@ -0,0 +1,46 @@ +#! /bin/sh + +set -e + +INDEX_FILE=/usr/share/nginx/html/index.html + +replace_in_index () { + if [ "$1" != "**None**" ]; then + sed -i "s|/\*||g" $INDEX_FILE + sed -i "s|\*/||g" $INDEX_FILE + sed -i "s|$1|$2|g" $INDEX_FILE + fi +} + +replace_or_delete_in_index () { + if [ -z "$2" ]; then + sed -i "/$1/d" $INDEX_FILE + else + replace_in_index $1 $2 + fi +} + +replace_in_index myApiKeyXXXX123456789 $API_KEY +replace_or_delete_in_index your-client-id $OAUTH_CLIENT_ID +replace_or_delete_in_index your-client-secret-if-required $OAUTH_CLIENT_SECRET +replace_or_delete_in_index your-realms $OAUTH_REALM +replace_or_delete_in_index your-app-name $OAUTH_APP_NAME +if [ "$OAUTH_ADDITIONAL_PARAMS" != "**None**" ]; then + replace_in_index "additionalQueryStringParams: {}" "additionalQueryStringParams: {$OAUTH_ADDITIONAL_PARAMS}" +fi + +if [[ -f $SWAGGER_JSON ]]; then + sed -i "s|http://petstore.swagger.io/v2/swagger.json|swagger.json|g" $INDEX_FILE + sed -i "s|http://example.com/api|swagger.json|g" $INDEX_FILE +else + sed -i "s|http://petstore.swagger.io/v2/swagger.json|$API_URL|g" $INDEX_FILE + sed -i "s|http://example.com/api|$API_URL|g" $INDEX_FILE +fi + +if [[ -n "$VALIDATOR_URL" ]]; then + sed -i "s|.*validatorUrl:.*$||g" $INDEX_FILE + sed -i "s|\(url: url,.*\)|\1\n validatorUrl: \"${VALIDATOR_URL}\",|g" $INDEX_FILE +fi + +#exec http-server -p $PORT $* +exec nginx -g 'daemon off;' \ No newline at end of file