From 9a5ed723c48c3d2f932b2c28741db4435bdf8fe0 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 31 Mar 2020 00:17:15 +0200 Subject: [PATCH 1/4] deployment: merge into root dockerfile --- Dockerfile | 9 ++++++- deployment/Dockerfile.heroku | 24 ------------------- deployment/default.conf.template | 8 ------- .../{default.conf => default.conf.template} | 3 +-- 4 files changed, 9 insertions(+), 35 deletions(-) delete mode 100644 deployment/Dockerfile.heroku delete mode 100644 deployment/default.conf.template rename docker/{default.conf => default.conf.template} (95%) diff --git a/Dockerfile b/Dockerfile index 5337207235..f26f69297b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,4 +15,11 @@ RUN yarn build FROM nginx:mainline COPY --from=builder /app/packages/app/build /usr/share/nginx/html -COPY ./docker/default.conf /etc/nginx/conf.d/default.conf + +# Run nginx as root +RUN sed -i 's/user nginx.*$//' /etc/nginx/nginx.conf + +COPY docker/default.conf.template /etc/nginx/conf.d/default.conf.template +CMD /bin/bash -c "envsubst '\$PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;' + +ENV PORT 80 diff --git a/deployment/Dockerfile.heroku b/deployment/Dockerfile.heroku deleted file mode 100644 index 15878c67da..0000000000 --- a/deployment/Dockerfile.heroku +++ /dev/null @@ -1,24 +0,0 @@ -FROM node:12 as builder -WORKDIR /app - -COPY package.json yarn.lock .yarnrc .npmrc /app/ -COPY .yarn /app/.yarn -COPY packages /app/packages -COPY plugins /app/plugins - -RUN yarn - -COPY . . - -RUN yarn build - -FROM nginx:mainline - -COPY --from=builder /app/packages/app/build /usr/share/nginx/html - -# Run nginx as root -RUN sed -i 's/user nginx.*$//' /etc/nginx/nginx.conf - -# Copy in the nginx conf template and replace "$PORT" with the environment variable set by heroku -COPY deployment/default.conf.template /etc/nginx/conf.d/default.conf.template -CMD /bin/bash -c "envsubst '\$PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;' diff --git a/deployment/default.conf.template b/deployment/default.conf.template deleted file mode 100644 index 61c32aa95e..0000000000 --- a/deployment/default.conf.template +++ /dev/null @@ -1,8 +0,0 @@ -server { - listen $PORT default_server; - - location / { - root /usr/share/nginx/html; - index index.html; - } -} diff --git a/docker/default.conf b/docker/default.conf.template similarity index 95% rename from docker/default.conf rename to docker/default.conf.template index d01be24dc7..29252f9625 100644 --- a/docker/default.conf +++ b/docker/default.conf.template @@ -1,5 +1,5 @@ server { - listen 80; + listen $PORT; server_name localhost; #charset koi8-r; @@ -20,4 +20,3 @@ server { root /usr/share/nginx/html; } } - From afb77c88239671f3956acd5aec83bf3011c04a12 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 31 Mar 2020 00:51:12 +0200 Subject: [PATCH 2/4] DEPLOYMENT: update heroku deployment instructions --- DEPLOYMENT.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index 47cd67e8ef..be77f0d4de 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -17,18 +17,7 @@ You _might_ also need to set your Heroku app's stack to `container` $ heroku stack:set container -a ``` -There are two small tweaks made to Backstage's default Dockerfile to run on Heroku: - -1. Do not run nginx as the `nginx` user. -2. Replace the standard port (80) in `/etc/nginx/conf.d/default.conf` with the wildcard `$PORT`, which Heroku will set for us. - -These changes are in the `deployment/Dockerfile.heroku` file, which you will need to copy into your root directory before deploying: - -```bash -$ cp deployment/Dockerfile.heroku Dockerfile -``` - -With these changes, we can build/push the Docker image to Heroku's container registry and release it to the `web` worker. +We can now build/push the Docker image to Heroku's container registry and release it to the `web` worker. ```bash $ heroku container:push web -a From ae3d5ffe9df5740acfdc0035e7a111e3d2296fe3 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 31 Mar 2020 00:51:34 +0200 Subject: [PATCH 3/4] Dockerfile: optimize copying a bit --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f26f69297b..8415a5eebc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,8 @@ COPY plugins /app/plugins RUN yarn -COPY . . +COPY lerna.json tsconfig.json .eslintignore .eslintrc.js /app/ +COPY scripts/ /app/scripts RUN yarn build From 912bd3ee18f603f02eee363e4a4053f147a52514 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 31 Mar 2020 01:11:34 +0200 Subject: [PATCH 4/4] Dockerfile: move nginx config templating to run script --- Dockerfile | 6 ++---- docker/run.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100755 docker/run.sh diff --git a/Dockerfile b/Dockerfile index 8415a5eebc..cab9ede03f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,10 +17,8 @@ FROM nginx:mainline COPY --from=builder /app/packages/app/build /usr/share/nginx/html -# Run nginx as root -RUN sed -i 's/user nginx.*$//' /etc/nginx/nginx.conf - COPY docker/default.conf.template /etc/nginx/conf.d/default.conf.template -CMD /bin/bash -c "envsubst '\$PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;' +COPY docker/run.sh /usr/local/bin/run.sh +CMD run.sh ENV PORT 80 diff --git a/docker/run.sh b/docker/run.sh new file mode 100755 index 0000000000..7bc5f5fa39 --- /dev/null +++ b/docker/run.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +# Run nginx as root +sed -i 's/user nginx.*$//' /etc/nginx/nginx.conf + +# Write selected env vars to nginx config +envsubst '$PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf + +exec nginx -g 'daemon off;'