Skip to content

Commit 7f6b52b

Browse files
feat: add docker compose file
1 parent a68248c commit 7f6b52b

File tree

9 files changed

+23748
-12
lines changed

9 files changed

+23748
-12
lines changed

.dockerignore

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
.git
2-
.yarn/cache
3-
.yarn/install-state.gz
1+
dist-types
42
node_modules
5-
packages/*/src
3+
packages/*/dist
64
packages/*/node_modules
7-
plugins
8-
*.local.yaml
5+
plugins/*/dist
6+
plugins/*/node_modules

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
POSTGRES_HOST="127.0.0.1"
2+
POSTGRES_PORT="5432"
3+
POSTGRES_USER="postgres"
4+
POSTGRES_PASSWORD="admin"

Dockerfile

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Stage 1 - Create yarn install skeleton layer
2+
FROM node:18-bookworm-slim AS packages
3+
4+
WORKDIR /app
5+
COPY package.json yarn.lock ./
6+
7+
COPY packages packages
8+
9+
# Comment this out if you don't have any internal plugins
10+
# COPY plugins plugins
11+
12+
RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -exec rm -rf {} \+
13+
14+
# Stage 2 - Install dependencies and build packages
15+
FROM node:18-bookworm-slim AS build
16+
17+
# Install isolate-vm dependencies, these are needed by the @backstage/plugin-scaffolder-backend.
18+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
19+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
20+
apt-get update && \
21+
apt-get install -y --no-install-recommends python3 g++ build-essential && \
22+
yarn config set python /usr/bin/python3
23+
24+
USER node
25+
WORKDIR /app
26+
27+
COPY --from=packages --chown=node:node /app .
28+
29+
RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \
30+
yarn install --frozen-lockfile --network-timeout 600000
31+
32+
COPY --chown=node:node . .
33+
34+
RUN yarn tsc
35+
RUN yarn --cwd packages/backend build
36+
# If you have not yet migrated to package roles, use the following command instead:
37+
# RUN yarn --cwd packages/backend backstage-cli backend:bundle --build-dependencies
38+
39+
RUN mkdir packages/backend/dist/skeleton packages/backend/dist/bundle \
40+
&& tar xzf packages/backend/dist/skeleton.tar.gz -C packages/backend/dist/skeleton \
41+
&& tar xzf packages/backend/dist/bundle.tar.gz -C packages/backend/dist/bundle
42+
43+
# Stage 3 - Build the actual backend image and install production dependencies
44+
FROM node:18-bookworm-slim
45+
46+
# Install isolate-vm dependencies, these are needed by the @backstage/plugin-scaffolder-backend.
47+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
48+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
49+
apt-get update && \
50+
apt-get install -y --no-install-recommends python3 g++ build-essential && \
51+
yarn config set python /usr/bin/python3
52+
53+
# From here on we use the least-privileged `node` user to run the backend.
54+
USER node
55+
56+
# This should create the app dir as `node`.
57+
# If it is instead created as `root` then the `tar` command below will
58+
# fail: `can't create directory 'packages/': Permission denied`.
59+
# If this occurs, then ensure BuildKit is enabled (`DOCKER_BUILDKIT=1`)
60+
# so the app dir is correctly created as `node`.
61+
WORKDIR /app
62+
63+
# Copy the install dependencies from the build stage and context
64+
COPY --from=build --chown=node:node /app/yarn.lock /app/package.json /app/packages/backend/dist/skeleton/ ./
65+
66+
RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \
67+
yarn install --frozen-lockfile --production --network-timeout 600000
68+
69+
# Copy the built packages from the build stage
70+
COPY --from=build --chown=node:node /app/packages/backend/dist/bundle/ ./
71+
72+
# Copy any other files that we need at runtime
73+
COPY --chown=node:node app-config.yaml ./
74+
75+
# This switches many Node.js dependencies to production mode.
76+
ENV NODE_ENV production
77+
78+
CMD ["node", "packages/backend", "--config", "app-config.yaml"]

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,36 @@ To start the app, run:
88
yarn install
99
yarn dev
1010
```
11+
12+
IMPORTANT:
13+
if you use docker you need a .env file
14+
15+
```sh
16+
cp .env.example .env
17+
```
18+
19+
to run in docker (this takes up to 3-5 mins):
20+
```sh
21+
docker compose up -d --build
22+
```
23+
24+
Only use the --build command if you changed something otherwise this is enough
25+
```sh
26+
docker compose up -d
27+
```
28+
29+
To remove the docker container
30+
```sh
31+
docker compose down
32+
```
33+
34+
If you to run the app locally (for quicker loading time and not having to reubild the image every time) but still connect to the docker pg database you need to run:
35+
```sh
36+
docker compose up -d pg_db
37+
```
38+
39+
And then:
40+
```sh
41+
yarn install
42+
yarn dev
43+
```

app-config.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ backend:
2828
# This is for local development only, it is not recommended to use this in production
2929
# The production database configuration is stored in app-config.production.yaml
3030
database:
31-
client: better-sqlite3
32-
connection: ':memory:'
31+
client: pg
32+
connection:
33+
host: ${POSTGRES_HOST}
34+
port: ${POSTGRES_PORT}
35+
user: ${POSTGRES_USER}
36+
password: ${POSTGRES_PASSWORD}
3337
# workingDirectory: /tmp # Use this to configure a working directory for the scaffolder, defaults to the OS temp-dir
3438

3539
integrations:
@@ -64,7 +68,12 @@ techdocs:
6468

6569
auth:
6670
# see https://backstage.io/docs/auth/ to learn about auth providers
67-
providers: {}
71+
environment: development
72+
providers:
73+
github:
74+
development:
75+
clientId: 1ae7a4924b6017077f5c
76+
clientSecret: 93c884c465bd3e4b823e7d9149722127aec63cf9
6877

6978
scaffolder:
7079
# see https://backstage.io/docs/features/software-templates/configuration for software template options

docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
services:
2+
backstage_demo:
3+
container_name: backstage_app_demo
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
environment:
8+
POSTGRES_HOST: ${POSTGRES_HOST:-backstage_pg_db}
9+
POSTGRES_PORT: ${POSTGRES_PORT:-5432}
10+
POSTGRES_USER: ${POSTGRES_USER:-postgres}
11+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-admin}
12+
ports:
13+
- 7007:7007
14+
pg_db:
15+
container_name: backstage_pg_db
16+
image: postgres:15.4
17+
environment:
18+
POSTGRES_USER: ${POSTGRES_USER:-postgres}
19+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-admin}
20+
volumes:
21+
- postgres:/data/postgres
22+
ports:
23+
- "127.0.0.1:5432:5432"
24+
25+
volumes:
26+
postgres:
27+

packages/app/src/App.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,25 @@ import { CatalogGraphPage } from '@backstage/plugin-catalog-graph';
3434
import { RequirePermission } from '@backstage/plugin-permission-react';
3535
import { catalogEntityCreatePermission } from '@backstage/plugin-catalog-common/alpha';
3636

37+
import { githubAuthApiRef } from '@backstage/core-plugin-api';
38+
import { SignInPage } from '@backstage/core-components';
39+
3740
const app = createApp({
3841
apis,
42+
components: {
43+
SignInPage: props => (
44+
<SignInPage
45+
{...props}
46+
auto
47+
provider={{
48+
id: 'github-auth-provider',
49+
title: 'GitHub',
50+
message: 'Sign in using GitHub',
51+
apiRef: githubAuthApiRef,
52+
}}
53+
/>
54+
),
55+
},
3956
bindRoutes({ bind }) {
4057
bind(catalogPlugin.externalRoutes, {
4158
createComponent: scaffolderPlugin.routes.root,

packages/backend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"@backstage/plugin-search-backend-node": "^1.2.13",
3838
"@backstage/plugin-techdocs-backend": "^1.9.2",
3939
"app": "link:../app",
40-
"better-sqlite3": "^9.0.0",
4140
"dockerode": "^3.3.1",
4241
"express": "^4.17.1",
4342
"express-promise-router": "^4.1.0",
@@ -50,7 +49,8 @@
5049
"@types/dockerode": "^3.3.0",
5150
"@types/express": "^4.17.6",
5251
"@types/express-serve-static-core": "^4.17.5",
53-
"@types/luxon": "^2.0.4"
52+
"@types/luxon": "^2.0.4",
53+
"better-sqlite3": "^9.0.0"
5454
},
5555
"files": [
5656
"dist"

0 commit comments

Comments
 (0)