From 6327bb8770a78c8696928d885c8f302cfc70cbc9 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 26 Jan 2021 13:33:56 +0100 Subject: [PATCH 1/6] chore: Added example multi-stage with the new backstage bundle command --- .../docker/multi-stage-with-bundle/Dockerfile | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 contrib/docker/multi-stage-with-bundle/Dockerfile diff --git a/contrib/docker/multi-stage-with-bundle/Dockerfile b/contrib/docker/multi-stage-with-bundle/Dockerfile new file mode 100644 index 0000000000..5e6ce770de --- /dev/null +++ b/contrib/docker/multi-stage-with-bundle/Dockerfile @@ -0,0 +1,42 @@ +# Stage 1 - Create yarn install skeleton layer +FROM node:14-buster AS packages + +WORKDIR /app +COPY package.json yarn.lock ./ + +# Uncomment this line if building a non create-app version +# COPY packages packages +COPY plugins plugins + +RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -print | xargs rm -rf + +# Stage 2 - Install dependencies and build packages +FROM node:14-buster AS build + +WORKDIR /app +COPY --from=packages /app . + +RUN yarn install --network-timeout 600000 && rm -rf "$(yarn cache dir)" + +COPY . . + +RUN yarn tsc +RUN yarn --cwd packages/backend backstage-cli backend:bundle --build-dependencies + +# Stage 3 - Build the actual backend image and install production dependencies +FROM node:14-buster + +WORKDIR /app + +# Copy from build stage +COPY --from=build /app/yarn.lock /app/package.json /app/packages/backend/dist/skeleton.tar.gz ./ +RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz + +RUN yarn install --production --network-timeout 600000 && rm -rf "$(yarn cache dir)" + +COPY --from=build /app/packages/backend/dist/bundle.tar.gz . +RUN tar xzf bundle.tar.gz && rm bundle.tar.gz + +COPY app-config.yaml app-config.production.yaml ./ + +CMD ["node", "packages/backend", "--config", "app-config.yaml", "--config", "app-config.production.yaml"] \ No newline at end of file From 294b7b087d222112134c914ca6222c37fc231ffd Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 26 Jan 2021 13:41:15 +0100 Subject: [PATCH 2/6] chore: fix newline on new file --- contrib/docker/multi-stage-with-bundle/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/docker/multi-stage-with-bundle/Dockerfile b/contrib/docker/multi-stage-with-bundle/Dockerfile index 5e6ce770de..8289a49046 100644 --- a/contrib/docker/multi-stage-with-bundle/Dockerfile +++ b/contrib/docker/multi-stage-with-bundle/Dockerfile @@ -39,4 +39,4 @@ RUN tar xzf bundle.tar.gz && rm bundle.tar.gz COPY app-config.yaml app-config.production.yaml ./ -CMD ["node", "packages/backend", "--config", "app-config.yaml", "--config", "app-config.production.yaml"] \ No newline at end of file +CMD ["node", "packages/backend", "--config", "app-config.yaml", "--config", "app-config.production.yaml"] From ad52b78b8dd50331cf535a461a1e3ae51cacd97f Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 26 Jan 2021 15:55:34 +0100 Subject: [PATCH 3/6] chore: reworking the files so that it's moved to docs instea --- .../docker/multi-stage-with-bundle/Dockerfile | 42 ------------ docs/getting-started/deployment-other.md | 64 ++++++++++++++++--- 2 files changed, 56 insertions(+), 50 deletions(-) delete mode 100644 contrib/docker/multi-stage-with-bundle/Dockerfile diff --git a/contrib/docker/multi-stage-with-bundle/Dockerfile b/contrib/docker/multi-stage-with-bundle/Dockerfile deleted file mode 100644 index 8289a49046..0000000000 --- a/contrib/docker/multi-stage-with-bundle/Dockerfile +++ /dev/null @@ -1,42 +0,0 @@ -# Stage 1 - Create yarn install skeleton layer -FROM node:14-buster AS packages - -WORKDIR /app -COPY package.json yarn.lock ./ - -# Uncomment this line if building a non create-app version -# COPY packages packages -COPY plugins plugins - -RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -print | xargs rm -rf - -# Stage 2 - Install dependencies and build packages -FROM node:14-buster AS build - -WORKDIR /app -COPY --from=packages /app . - -RUN yarn install --network-timeout 600000 && rm -rf "$(yarn cache dir)" - -COPY . . - -RUN yarn tsc -RUN yarn --cwd packages/backend backstage-cli backend:bundle --build-dependencies - -# Stage 3 - Build the actual backend image and install production dependencies -FROM node:14-buster - -WORKDIR /app - -# Copy from build stage -COPY --from=build /app/yarn.lock /app/package.json /app/packages/backend/dist/skeleton.tar.gz ./ -RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz - -RUN yarn install --production --network-timeout 600000 && rm -rf "$(yarn cache dir)" - -COPY --from=build /app/packages/backend/dist/bundle.tar.gz . -RUN tar xzf bundle.tar.gz && rm bundle.tar.gz - -COPY app-config.yaml app-config.production.yaml ./ - -CMD ["node", "packages/backend", "--config", "app-config.yaml", "--config", "app-config.production.yaml"] diff --git a/docs/getting-started/deployment-other.md b/docs/getting-started/deployment-other.md index 55582ee77a..900173a6c5 100644 --- a/docs/getting-started/deployment-other.md +++ b/docs/getting-started/deployment-other.md @@ -4,19 +4,67 @@ title: Other description: Documentation on different ways of Deployment --- -## Deploying Locally +## Docker -### Try on Docker +Here we have an example Dockerfile that you can use to build everything together +in one container. This Dockerfile uses multi-stage builds, and a +`backend:bundle` command from the CLI. -Run the following commands if you have Docker environment +It also provides caching on the `yarn install`'s so that you don't have to do it +unless absolutely necessary. -```bash -$ yarn install -$ yarn docker-build -$ docker run --rm -it -p 7000:7000 -e APP_ENV=production -e NODE_ENV=development example-backend:latest +```Dockerfile +# Stage 1 - Create yarn install skeleton layer +FROM node:14-buster AS packages + +WORKDIR /app +COPY package.json yarn.lock ./ + +COPY packages packages + +# Uncomment this line if you have a local plugins folder +# COPY plugins plugins + +RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -print | xargs rm -rf + +# Stage 2 - Install dependencies and build packages +FROM node:14-buster AS build + +WORKDIR /app +COPY --from=packages /app . + +RUN yarn install --network-timeout 600000 && rm -rf "$(yarn cache dir)" + +COPY . . + +RUN yarn tsc +RUN yarn --cwd packages/backend backstage-cli backend:bundle --build-dependencies + +# Stage 3 - Build the actual backend image and install production dependencies +FROM node:14-buster + +WORKDIR /app + +# Copy from build stage +COPY --from=build /app/yarn.lock /app/package.json /app/packages/backend/dist/skeleton.tar.gz ./ +RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz + +RUN yarn install --production --network-timeout 600000 && rm -rf "$(yarn cache dir)" + +COPY --from=build /app/packages/backend/dist/bundle.tar.gz . +RUN tar xzf bundle.tar.gz && rm bundle.tar.gz + +COPY app-config.yaml app-config.production.yaml ./ + +CMD ["node", "packages/backend", "--config", "app-config.yaml", "--config", "app-config.production.yaml"] ``` -Then open http://localhost:7000 on your browser. +You can add the Dockerfile to the root of your project, and run the following: + +```sh +$ docker build -t eaxmple-deployment . +$ docker run -p 7000:7000 example-deployment +``` ## Heroku From 6cc06d4e7f7630c6747b2a8bc0fa884cb7637366 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 26 Jan 2021 15:56:33 +0100 Subject: [PATCH 4/6] chore: fixing spelling of docs --- docs/getting-started/deployment-other.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/deployment-other.md b/docs/getting-started/deployment-other.md index 900173a6c5..6cc90c88fb 100644 --- a/docs/getting-started/deployment-other.md +++ b/docs/getting-started/deployment-other.md @@ -62,7 +62,7 @@ CMD ["node", "packages/backend", "--config", "app-config.yaml", "--config", "app You can add the Dockerfile to the root of your project, and run the following: ```sh -$ docker build -t eaxmple-deployment . +$ docker build -t example-deployment . $ docker run -p 7000:7000 example-deployment ``` From 2dee00292cbdf35d52b43401cea738eaded29e36 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 26 Jan 2021 17:34:52 +0100 Subject: [PATCH 5/6] chore: review comments --- docs/getting-started/deployment-other.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/getting-started/deployment-other.md b/docs/getting-started/deployment-other.md index 6cc90c88fb..569ef6e898 100644 --- a/docs/getting-started/deployment-other.md +++ b/docs/getting-started/deployment-other.md @@ -13,6 +13,9 @@ in one container. This Dockerfile uses multi-stage builds, and a It also provides caching on the `yarn install`'s so that you don't have to do it unless absolutely necessary. +> Note: This Dockerfile assumes that you're running SQLite, or your +> configuration is setup to connect to an external PostgreSQL Database. + ```Dockerfile # Stage 1 - Create yarn install skeleton layer FROM node:14-buster AS packages @@ -66,6 +69,8 @@ $ docker build -t example-deployment . $ docker run -p 7000:7000 example-deployment ``` +Once complete, open your browser at `http://localhost:7000` if running locally. + ## Heroku Deploying to Heroku is relatively easy following these steps. From 8080d1ef4fb0b263f08568d605406ce6c8d6728a Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 26 Jan 2021 17:39:28 +0100 Subject: [PATCH 6/6] chore: change the wording slightly --- docs/getting-started/deployment-other.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/getting-started/deployment-other.md b/docs/getting-started/deployment-other.md index 569ef6e898..6436bdb195 100644 --- a/docs/getting-started/deployment-other.md +++ b/docs/getting-started/deployment-other.md @@ -62,14 +62,21 @@ COPY app-config.yaml app-config.production.yaml ./ CMD ["node", "packages/backend", "--config", "app-config.yaml", "--config", "app-config.production.yaml"] ``` -You can add the Dockerfile to the root of your project, and run the following: +You can add the Dockerfile to the root of your project, and run the following to +build the container under a specified tag. ```sh $ docker build -t example-deployment . -$ docker run -p 7000:7000 example-deployment ``` -Once complete, open your browser at `http://localhost:7000` if running locally. +To run the image locally you can run: + +```sh +$ docker run -p -it 7000:7000 example-deployment +``` + +You should then start to get logs in your terminal, and then you can open your +browser at `http://localhost:7000` ## Heroku