From 82a1adb0bc6b815e68f1b7302e08153a7e44a052 Mon Sep 17 00:00:00 2001 From: Alexander Sedelnikov Date: Fri, 15 Jun 2018 23:35:48 +0700 Subject: [PATCH] Add ability for image to read env from a file by _FILE suffix #175 --- .travis.yml | 1 + Dockerfile | 16 +++++++++++++--- Dockerfile.prod | 22 ++++++++++++++++------ custom-entrypoint.sh | 14 ++++++++++++++ docker-compose.yml | 4 ++-- 5 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 custom-entrypoint.sh diff --git a/.travis.yml b/.travis.yml index 838ab39..154c232 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ before_install: script: - cp -r .env.test .env - docker-compose build +- docker-compose run -u 0 --no-deps --rm ico yarn install - docker-compose up -d - docker-compose exec ico yarn - docker-compose exec ico yarn test diff --git a/Dockerfile b/Dockerfile index 0fd9f35..125bbe6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,20 @@ FROM mhart/alpine-node:8.9.1 -RUN apk update && apk upgrade && apk add git && apk add python && apk add make && apk add g++ && npm i -g yarn +WORKDIR /usr/src/app +COPY . . +COPY custom-entrypoint.sh /usr/local/bin/custom-entrypoint.sh + +RUN chmod 755 /usr/local/bin/custom-entrypoint.sh && \ + addgroup ico && \ + adduser -D -H -G ico ico && \ + apk add --update --no-cache git python make g++ && \ + npm i -g yarn && \ + yarn install -VOLUME /usr/src/app EXPOSE 3000 EXPOSE 4000 -WORKDIR /usr/src/app +USER ico +ENTRYPOINT ["/usr/local/bin/custom-entrypoint.sh"] +CMD ["npm", "start"] diff --git a/Dockerfile.prod b/Dockerfile.prod index d58daa6..5998234 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -1,17 +1,27 @@ FROM mhart/alpine-node:8.6 -RUN mkdir -p /usr/src/app -ADD . /usr/src/app - WORKDIR /usr/src/app -RUN mkdir -p /usr/src/app/dist -RUN cp -r src/certs dist/ +COPY . . +COPY custom-entrypoint.sh /usr/local/bin/custom-entrypoint.sh +RUN chmod 755 /usr/local/bin/custom-entrypoint.sh && \ + addgroup ico && \ + adduser -D -H -G ico ico && \ + mkdir -p /usr/src/app/dist && \ + cp -r src/certs dist/ RUN apk add --update --no-cache git python make g++ && \ npm i -g yarn && \ yarn install && \ + yarn run build && \ + yarn install --prod && \ apk del --purge git python make g++ && \ rm -rf ./src -CMD npm run serve \ No newline at end of file +EXPOSE 3000 +EXPOSE 4000 + +USER ico + +ENTRYPOINT ["/usr/local/bin/custom-entrypoint.sh"] +CMD ["npm", "run", "serve"] diff --git a/custom-entrypoint.sh b/custom-entrypoint.sh new file mode 100644 index 0000000..423c495 --- /dev/null +++ b/custom-entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -eu + +for env in $(env); do + key=${env%=*} + [ -n "${key#*_FILE}" ] && continue + val=${env#*=} + key=${key%_FILE} + val=$(cat $val) + export "${key}"="${val}" +done + +exec "$@" diff --git a/docker-compose.yml b/docker-compose.yml index 10190b5..b22dc76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,13 +9,13 @@ services: - 80:3000 - 3000:3000 - 443:4000 - volumes: - - ./:/usr/src/app links: - auth - redis - verify - rpc + volumes: + - ./:/usr/src/app depends_on: - rpc - mongo