From 6da18036a4e6defdb2382a10a893a5900dc501b0 Mon Sep 17 00:00:00 2001 From: Shyam Sunder Date: Sat, 28 Sep 2019 19:28:04 -0400 Subject: [PATCH] client/docker: improved Dockerfile --- client/Dockerfile | 30 ++++++++++++++++-------------- client/docker-start.sh | 11 +++++++++++ client/hooks/build | 9 ++++++++- 3 files changed, 35 insertions(+), 15 deletions(-) create mode 100755 client/docker-start.sh diff --git a/client/Dockerfile b/client/Dockerfile index 94ab8001..7d07bd9a 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -11,19 +11,21 @@ ARG CLIENT_BUILD_ARGS="" RUN BASE_URL="__BASEURL__" node build.js --gzip ${CLIENT_BUILD_ARGS} -FROM nginx:alpine +FROM scratch as approot + +COPY docker-start.sh / + +WORKDIR /etc/nginx +COPY nginx.conf.docker ./nginx.conf + WORKDIR /var/www - -RUN \ - # Create init file - echo "#!/bin/sh" >> /init && \ - echo 'sed -i "s|__BACKEND__|${BACKEND_HOST}|" /etc/nginx/nginx.conf' >> /init && \ - echo 'sed -i "s|__BASEURL__|${BASE_URL:-/}|g" /var/www/index.htm /var/www/manifest.json' >> /init && \ - echo 'exec nginx' >> /init && \ - chmod a+x /init - -CMD ["/init"] -VOLUME ["/data"] - -COPY nginx.conf.docker /etc/nginx/nginx.conf COPY --from=builder /opt/app/public/ . + + +FROM nginx:alpine + +RUN apk --no-cache add dumb-init +COPY --from=approot / / + +CMD ["/docker-start.sh"] +VOLUME ["/data"] diff --git a/client/docker-start.sh b/client/docker-start.sh new file mode 100755 index 00000000..9b1ba0ec --- /dev/null +++ b/client/docker-start.sh @@ -0,0 +1,11 @@ +#!/usr/bin/dumb-init /bin/sh + +# Integrate environment variables +sed -i "s|__BACKEND__|${BACKEND_HOST}|" \ + /etc/nginx/nginx.conf +sed -i "s|__BASEURL__|${BASE_URL:-/}|g" \ + /var/www/index.htm \ + /var/www/manifest.json + +# Start server +exec nginx \ No newline at end of file diff --git a/client/hooks/build b/client/hooks/build index 86d0c787..b8c2c20b 100755 --- a/client/hooks/build +++ b/client/hooks/build @@ -1,4 +1,11 @@ #!/bin/sh -BUILD_INFO=docker-$(echo $SOURCE_COMMIT | cut -c1-7)-auto + +CLOSEST_VER=$(git describe --tags --abbrev=0) +if git describe --exact-match --abbrev=0 2> /dev/null; then + BUILD_INFO="v${CLOSEST_VER}" +else + BUILD_INFO="v${CLOSEST_VER}-edge-$(echo $SOURCE_COMMIT | cut -c1-7)" +fi + echo "Using BUILD_INFO=$BUILD_INFO" docker build --build-arg BUILD_INFO=$BUILD_INFO -f $DOCKERFILE_PATH -t $IMAGE_NAME .