Skip to content

Commit

Permalink
feat: Add backstage
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneLimburg committed Oct 9, 2023
1 parent 2a0855a commit cfbf4f5
Show file tree
Hide file tree
Showing 75 changed files with 24,647 additions and 0 deletions.
80 changes: 80 additions & 0 deletions backstage/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Stage 1 - Create yarn install skeleton layer
FROM node:18-bullseye-slim AS packages

WORKDIR /app
COPY package.json yarn.lock ./

COPY packages packages

# Comment this out if you don't have any internal plugins
#COPY plugins plugins

RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -exec rm -rf {} \+

# Stage 2 - Install dependencies and build packages
FROM node:18-bullseye-slim AS build

# install sqlite3 dependencies
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends libsqlite3-dev python3 build-essential && \
yarn config set python /usr/bin/python3

USER node
WORKDIR /app

COPY --from=packages --chown=node:node /app .

# Stop cypress from downloading it's massive binary.
ENV CYPRESS_INSTALL_BINARY=0
RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \
yarn install --frozen-lockfile --network-timeout 600000

COPY --chown=node:node . .

RUN yarn tsc
RUN yarn --cwd packages/backend build
# If you have not yet migrated to package roles, use the following command instead:
# RUN yarn --cwd packages/backend backstage-cli backend:bundle --build-dependencies

RUN mkdir packages/backend/dist/skeleton packages/backend/dist/bundle \
&& tar xzf packages/backend/dist/skeleton.tar.gz -C packages/backend/dist/skeleton \
&& tar xzf packages/backend/dist/bundle.tar.gz -C packages/backend/dist/bundle

# Stage 3 - Build the actual backend image and install production dependencies
FROM node:18-bullseye-slim

# Install sqlite3 dependencies. You can skip this if you don't use sqlite3 in the image,
# in which case you should also move better-sqlite3 to "devDependencies" in package.json.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends libsqlite3-dev python3 build-essential curl && \
yarn config set python /usr/bin/python3

# From here on we use the least-privileged `node` user to run the backend.
USER node

# This should create the app dir as `node`.
# If it is instead created as `root` then the `tar` command below will fail: `can't create directory 'packages/': Permission denied`.
# If this occurs, then ensure BuildKit is enabled (`DOCKER_BUILDKIT=1`) so the app dir is correctly created as `node`.
WORKDIR /app

# Copy the install dependencies from the build stage and context
COPY --from=build --chown=node:node /app/yarn.lock /app/package.json /app/packages/backend/dist/skeleton/ ./

RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \
yarn install --frozen-lockfile --production --network-timeout 600000

# Copy the built packages from the build stage
COPY --from=build --chown=node:node /app/packages/backend/dist/bundle/ ./

# Copy any other files that we need at runtime
COPY --chown=node:node app-config.yaml ./
COPY --chown=node:node examples /examples

# This switches many Node.js dependencies to production mode.
ENV NODE_ENV production

CMD ["node", "packages/backend", "--config", "app-config.yaml"]
35 changes: 35 additions & 0 deletions backstage/app-config.production.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
app:
# Should be the same as backend.baseUrl when using the `app-backend` plugin.
baseUrl: http://localhost:30090

backend:
# Note that the baseUrl should be the URL that the browser and other clients
# should use when communicating with the backend, i.e. it needs to be
# reachable not just from within the backend host, but from all of your
# callers. When its value is "http://localhost:7007", it's strictly private
# and can't be reached by others.
baseUrl: http://localhost:30090
# The listener can also be expressed as a single <host>:<port> string. In this case we bind to
# all interfaces, the most permissive setting. The right value depends on your specific deployment.
listen: ':30090'

# config options: https://node-postgres.com/api/client
database:
client: pg
connection:
host: ${POSTGRES_HOST}
port: ${POSTGRES_PORT}
user: ${POSTGRES_USER}
password: ${POSTGRES_PASSWORD}
# https://node-postgres.com/features/ssl
# you can set the sslmode configuration option via the `PGSSLMODE` environment variable
# see https://www.postgresql.org/docs/current/libpq-ssl.html Table 33.1. SSL Mode Descriptions (e.g. require)
# ssl:
# ca: # if you have a CA file and want to verify it you can uncomment this section
# $file: <file-path>/ca/server.crt

catalog:
# Overrides the default list locations from app-config.yaml as these contain example data.
# See https://backstage.io/docs/features/software-catalog/#adding-components-to-the-catalog for more details
# on how to get entities into the catalog.
locations: []
106 changes: 106 additions & 0 deletions backstage/app-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
app:
title: Scaffolded Backstage App
baseUrl: http://localhost:30090

organization:
name: My Company

backend:
# Used for enabling authentication, secret is shared by all backend plugins
# See https://backstage.io/docs/auth/service-to-service-auth for
# information on the format
# auth:
# keys:
# - secret: ${BACKEND_SECRET}
baseUrl: http://localhost:30090
listen:
port: 7007
# Uncomment the following host directive to bind to specific interfaces
# host: 127.0.0.1
csp:
connect-src: ["'self'", 'http:', 'https:']
# Content-Security-Policy directives follow the Helmet format: https://helmetjs.github.io/#reference
# Default Helmet Content-Security-Policy values can be removed by setting the key to false
cors:
origin: http://localhost:3000
methods: [GET, HEAD, PATCH, POST, PUT, DELETE]
credentials: true
# This is for local development only, it is not recommended to use this in production
# The production database configuration is stored in app-config.production.yaml
database:
client: better-sqlite3
connection: ':memory:'
cache:
store: memory
# workingDirectory: /tmp # Use this to configure a working directory for the scaffolder, defaults to the OS temp-dir

integrations:
pact:
url: ${PACT_URL}
github:
- host: github.com
# This is a Personal Access Token or PAT from GitHub. You can find out how to generate this token, and more information
# about setting up the GitHub integration here: https://backstage.io/docs/getting-started/configuration#setting-up-a-github-integration
token: ${GITHUB_TOKEN}
### Example for how to add your GitHub Enterprise instance using the API:
# - host: ghe.example.net
# apiBaseUrl: https://ghe.example.net/api/v3
# token: ${GHE_TOKEN}

proxy:
### Example for how to add a proxy endpoint for the frontend.
### A typical reason to do this is to handle HTTPS and CORS for internal services.
# '/test':
# target: 'https://example.com'
# changeOrigin: true

# Reference documentation http://backstage.io/docs/features/techdocs/configuration
# Note: After experimenting with basic setup, use CI/CD to generate docs
# and an external cloud storage when deploying TechDocs for production use-case.
# https://backstage.io/docs/features/techdocs/how-to-guides#how-to-migrate-from-techdocs-basic-to-recommended-deployment-approach
techdocs:
builder: 'local' # Alternatives - 'external'
generator:
runIn: 'docker' # Alternatives - 'local'
publisher:
type: 'local' # Alternatives - 'googleGcs' or 'awsS3'. Read documentation for using alternatives.

auth:
# see https://backstage.io/docs/auth/ to learn about auth providers
providers: {}

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

catalog:
import:
entityFilename: catalog-info.yaml
pullRequestBranchName: backstage-integration
rules:
- allow: [Component, System, API, Resource, Location]
locations:
# Local example data, file locations are relative to the backend process, typically `packages/backend`
- type: file
target: ./../../examples/entities.yaml

# Local example template
- type: file
target: ./../../examples/template/template.yaml
rules:
- allow: [Template]

# Local example organizational data
- type: file
target: ./../../examples/org.yaml
rules:
- allow: [User, Group]

## Uncomment these lines to add more example data
# - type: url
# target: https://github.com/backstage/backstage/blob/master/packages/catalog-model/examples/all.yaml

## Uncomment these lines to add an example org
# - type: url
# target: https://github.com/backstage/backstage/blob/master/packages/catalog-model/examples/acme-corp.yaml
# rules:
# - allow: [User, Group]
3 changes: 3 additions & 0 deletions backstage/backstage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "1.13.0"
}
39 changes: 39 additions & 0 deletions backstage/examples/address-validation-service/catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"apiVersion": "backstage.io/v1alpha1",
"kind": "Component",
"metadata": {
"name": "address-validation-service",
"annotations": {
"backstage.io/managed-by-origin-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml",
"backstage.io/managed-by-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml"
}
},
"spec": {
"type": "service",
"lifecycle": "experimental",
"owner": "guests",
"providesApis": [
"address-validation-service-api"
],
"consumesApis": []
}
},
{
"apiVersion": "backstage.io/v1alpha1",
"kind": "API",
"metadata": {
"name": "address-validation-service-api",
"annotations": {
"backstage.io/managed-by-origin-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml",
"backstage.io/managed-by-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml"
}
},
"spec": {
"type": "openapi",
"lifecycle": "experimental",
"owner": "guests",
"definition": "--> Insert here the address-validation-service API definition <---"
}
}
]
39 changes: 39 additions & 0 deletions backstage/examples/billing-service/catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"apiVersion": "backstage.io/v1alpha1",
"kind": "Component",
"metadata": {
"name": "billing-service",
"annotations": {
"backstage.io/managed-by-origin-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml",
"backstage.io/managed-by-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml"
}
},
"spec": {
"type": "service",
"lifecycle": "experimental",
"owner": "guests",
"providesApis": [
"billing-service-api"
],
"consumesApis": []
}
},
{
"apiVersion": "backstage.io/v1alpha1",
"kind": "API",
"metadata": {
"name": "billing-service-api",
"annotations": {
"backstage.io/managed-by-origin-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml",
"backstage.io/managed-by-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml"
}
},
"spec": {
"type": "openapi",
"lifecycle": "experimental",
"owner": "guests",
"definition": "--> Insert here the billing-service-api API definition <---"
}
}
]
37 changes: 37 additions & 0 deletions backstage/examples/customer-service/catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{
"apiVersion": "backstage.io/v1alpha1",
"kind": "Component",
"metadata": {
"name": "customer-service",
"annotations": {
"backstage.io/managed-by-origin-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml",
"backstage.io/managed-by-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml"
}
},
"spec": {
"type": "service",
"lifecycle": "experimental",
"owner": "guests",
"providesApis": ["customer-service-api"],
"consumesApis": []
}
},
{
"apiVersion": "backstage.io/v1alpha1",
"kind": "API",
"metadata": {
"name": "customer-service-api",
"annotations": {
"backstage.io/managed-by-origin-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml",
"backstage.io/managed-by-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml"
}
},
"spec": {
"type": "openapi",
"lifecycle": "experimental",
"owner": "guests",
"definition": "--> Insert here the customer-service-api API definition <---"
}
}
]
39 changes: 39 additions & 0 deletions backstage/examples/delivery-service/catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"apiVersion": "backstage.io/v1alpha1",
"kind": "Component",
"metadata": {
"name": "delivery-service",
"annotations": {
"backstage.io/managed-by-origin-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml",
"backstage.io/managed-by-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml"
}
},
"spec": {
"type": "service",
"lifecycle": "experimental",
"owner": "guests",
"providesApis": [
"delivery-service-api"
],
"consumesApis": []
}
},
{
"apiVersion": "backstage.io/v1alpha1",
"kind": "API",
"metadata": {
"name": "delivery-service-api",
"annotations": {
"backstage.io/managed-by-origin-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml",
"backstage.io/managed-by-location": "url:http://localhost:9080/service-repository/api/backstage/catalog-info.yaml"
}
},
"spec": {
"type": "openapi",
"lifecycle": "experimental",
"owner": "guests",
"definition": "--> Insert here the delivery-service-api API definition <---"
}
}
]
Loading

0 comments on commit cfbf4f5

Please sign in to comment.