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 diff --git a/Dockerfile b/Dockerfile index 5337207235..cab9ede03f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,11 +8,17 @@ COPY plugins /app/plugins RUN yarn -COPY . . +COPY lerna.json tsconfig.json .eslintignore .eslintrc.js /app/ +COPY scripts/ /app/scripts 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 + +COPY docker/default.conf.template /etc/nginx/conf.d/default.conf.template +COPY docker/run.sh /usr/local/bin/run.sh +CMD run.sh + +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; } } - 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;'