Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade 16 #58

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ examples
*.github
*.log
*.git
**/.swc
1 change: 0 additions & 1 deletion app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ backend:
csp:
connect-src: [ "'self'", 'http:', 'https:' ]
img-src: [ "'self'", "*.gov.bc.ca", "data:" ]
script-src: [ "'self'", "*.gov.bc.ca" ]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was originally added when I added the snowplow js script to the header in the summer time.

I removed this line because it was interfering with the isolated-vm change. With this line in place, the website would show a blank page with the error in the web browser developer tools of:
"EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' *.gov.bc.ca"."

I checked that the current analytics is working without it by using the Chrome snowplow plugin. I could see the page view for the environment I was working in (tools).

frame-src: ["www.youtube.com"]
# 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
Expand Down
2 changes: 1 addition & 1 deletion backstage.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "1.14.2"
"version": "1.16.0"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the upgrade path, I followed the instructions on https://backstage.github.io/upgrade-helper/?from=1.14.2&to=1.16.0

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
]
},
"devDependencies": {
"@backstage/cli": "^0.22.7",
"@backstage/cli": "^0.22.9",
"@spotify/prettier-config": "^12.0.0",
"concurrently": "^6.0.0",
"lerna": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/cypress/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"jest/expect-expect": [
"error",
{
"assertFunctionNames": ["expect", "cy.contains"]
"assertFunctionNames": ["expect", "cy.contains", "cy.**.should"]
}
]
}
Expand Down
54 changes: 27 additions & 27 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@
"cy:run": "cypress run --browser chrome"
},
"dependencies": {
"@backstage/app-defaults": "^1.3.1",
"@backstage/catalog-model": "^1.3.0",
"@backstage/cli": "^0.22.7",
"@backstage/core-app-api": "^1.8.0",
"@backstage/core-components": "^0.13.1",
"@backstage/core-plugin-api": "^1.5.1",
"@backstage/integration-react": "^1.1.13",
"@backstage/plugin-api-docs": "^0.9.4",
"@backstage/plugin-catalog": "^1.11.1",
"@backstage/plugin-catalog-common": "^1.0.13",
"@backstage/plugin-catalog-graph": "^0.2.30",
"@backstage/plugin-catalog-import": "^0.9.8",
"@backstage/plugin-catalog-react": "^1.6.0",
"@backstage/plugin-github-actions": "^0.5.18",
"@backstage/plugin-home": "^0.5.2",
"@backstage/plugin-org": "^0.6.8",
"@backstage/plugin-permission-react": "^0.4.12",
"@backstage/plugin-scaffolder": "^1.13.1",
"@backstage/plugin-search": "^1.3.1",
"@backstage/plugin-search-react": "^1.6.1",
"@backstage/plugin-stack-overflow": "^0.1.16",
"@backstage/plugin-tech-radar": "^0.6.4",
"@backstage/plugin-techdocs": "^1.6.3",
"@backstage/app-defaults": "^1.4.1",
"@backstage/catalog-model": "^1.4.1",
"@backstage/cli": "^0.22.9",
"@backstage/core-app-api": "^1.9.0",
"@backstage/core-components": "^0.13.3",
"@backstage/core-plugin-api": "^1.5.3",
"@backstage/integration-react": "^1.1.15",
"@backstage/plugin-api-docs": "^0.9.6",
"@backstage/plugin-catalog": "^1.12.0",
"@backstage/plugin-catalog-common": "^1.0.15",
"@backstage/plugin-catalog-graph": "^0.2.32",
"@backstage/plugin-catalog-import": "^0.9.10",
"@backstage/plugin-catalog-react": "^1.8.0",
"@backstage/plugin-github-actions": "^0.6.1",
"@backstage/plugin-home": "^0.5.4",
"@backstage/plugin-org": "^0.6.10",
"@backstage/plugin-permission-react": "^0.4.14",
"@backstage/plugin-scaffolder": "^1.14.1",
"@backstage/plugin-search": "^1.3.3",
"@backstage/plugin-search-react": "^1.6.3",
"@backstage/plugin-stack-overflow": "^0.1.18",
"@backstage/plugin-tech-radar": "^0.6.6",
"@backstage/plugin-techdocs": "^1.6.5",
"@backstage/plugin-techdocs-module-addons-contrib": "^1.0.18",
"@backstage/plugin-techdocs-react": "^1.1.6",
"@backstage/plugin-user-settings": "^0.7.3",
"@backstage/theme": "^0.3.0",
"@backstage/plugin-techdocs-react": "^1.1.8",
"@backstage/plugin-user-settings": "^0.7.5",
"@backstage/theme": "^0.4.1",
"@bcgov/bc-sans": "^2.0.0",
"@internal/plugin-analytics-module-snowplow": "^0.1.0",
"@app/plugin-toc-fix2": "0.0.0",
Expand All @@ -62,7 +62,7 @@
"styled-components": "^6.0.0-rc.3"
},
"devDependencies": {
"@backstage/test-utils": "^1.3.1",
"@backstage/test-utils": "^1.4.1",
"@testing-library/jest-dom": "^5.10.1",
"@testing-library/react": "^12.1.3",
"@testing-library/user-event": "^14.0.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ const app = createApp({
bind(catalogPlugin.externalRoutes, {
createComponent: scaffolderPlugin.routes.root,
viewTechDoc: techdocsPlugin.routes.docRoot,
createFromTemplate: scaffolderPlugin.routes.selectedTemplate,
});

bind(scaffolderPlugin.externalRoutes, {
viewTechDoc: techdocsPlugin.routes.docRoot,
});

bind(orgPlugin.externalRoutes, {
catalogIndex: catalogPlugin.routes.catalogIndex,
});
Expand Down
10 changes: 10 additions & 0 deletions packages/app/src/components/catalog/EntityPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
isKind,
hasCatalogProcessingErrors,
isOrphan,
hasRelationWarnings,
EntityRelationWarning,
} from '@backstage/plugin-catalog';
import {
isGithubActionsAvailable,
Expand Down Expand Up @@ -101,6 +103,14 @@ const entityWarningContent = (
</EntitySwitch.Case>
</EntitySwitch>

<EntitySwitch>
<EntitySwitch.Case if={hasRelationWarnings}>
<Grid item xs={12}>
<EntityRelationWarning />
</Grid>
</EntitySwitch.Case>
</EntitySwitch>

<EntitySwitch>
<EntitySwitch.Case if={hasCatalogProcessingErrors}>
<Grid item xs={12}>
Expand Down
99 changes: 49 additions & 50 deletions packages/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,79 +1,78 @@
# From https://github.com/janus-idp/backstage-showcase/
# Stage 1 - Install dependencies
FROM registry.access.redhat.com/ubi9/nodejs-18:latest AS deps
# Stage 1 - Build nodejs skeleton
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the janus show case docker file at the v 1.15 upgrade as the basis for this docker file. It's pretty much the same except for adding in plugins and removing techdocs dependencies as techdocs are external for us


FROM registry.access.redhat.com/ubi9/nodejs-18:1-80.1699550448 AS skeleton
USER 0

RUN dnf install -y -q --allowerasing --nobest \
python3 gcc gcc-c++ zlib-devel brotli-devel openssl-devel && \
dnf update -y && dnf clean all


# Env vars
ENV YARN=./.yarn/releases/yarn-1.22.19.cjs
ENV REMOTE_SOURCES=.
ENV REMOTE_SOURCES_DIR=/opt/app-root/src
ENV EXTERNAL_SOURCE=.
ENV CONTAINER_SOURCE=/opt/app-root/src

WORKDIR $REMOTE_SOURCES_DIR/
COPY $REMOTE_SOURCES $REMOTE_SOURCES_DIR
RUN chmod +x $REMOTE_SOURCES_DIR/.yarn/releases/yarn-1.22.19.cjs
WORKDIR $CONTAINER_SOURCE/
COPY $EXTERNAL_SOURCE/.yarn ./.yarn
COPY $EXTERNAL_SOURCE/.yarnrc.yml ./
RUN chmod +x "$YARN"

# Remove all files except package.json
RUN find packages -mindepth 2 -maxdepth 2 \! -name "package.json" -exec rm -rf {} \+
# Stage 2 - Install dependencies
FROM skeleton AS deps

RUN $YARN install --frozen-lockfile --network-timeout 600000 --ignore-scripts
COPY $EXTERNAL_SOURCE/package.json $EXTERNAL_SOURCE/yarn.lock ./
COPY $EXTERNAL_SOURCE/packages/app/package.json ./packages/app/package.json
COPY $EXTERNAL_SOURCE/packages/backend/package.json ./packages/backend/package.json
COPY $EXTERNAL_SOURCE/plugins/ ./plugins/

# Stage 2 - Build packages
FROM registry.access.redhat.com/ubi9/nodejs-18:latest AS build
USER 0
RUN "$YARN" install --frozen-lockfile --network-timeout 600000

# Env vars
ENV YARN=./.yarn/releases/yarn-1.22.19.cjs
ENV REMOTE_SOURCES=.
ENV REMOTE_SOURCES_DIR=/opt/app-root/src
# Stage 3 - Build packages
FROM deps AS build

WORKDIR $REMOTE_SOURCES_DIR/
COPY $REMOTE_SOURCES $REMOTE_SOURCES_DIR
COPY --from=deps $REMOTE_SOURCES_DIR $REMOTE_SOURCES_DIR
RUN chmod +x $REMOTE_SOURCES_DIR/.yarn/releases/yarn-1.22.19.cjs
RUN git config --global --add safe.directory $REMOTE_SOURCES_DIR/
COPY $EXTERNAL_SOURCE ./
RUN git config --global --add safe.directory ./

RUN $YARN tsc
RUN $YARN build:backend

# Stage 3 - Build the actual backend image and install production dependencies
FROM registry.access.redhat.com/ubi9/nodejs-18-minimal:1 AS runner
USER 0

# Install gzip for tar and clean up
RUN microdnf install -y gzip && microdnf clean all

# Env vars
ENV YARN=./.yarn/releases/yarn-1.22.19.cjs
ENV REMOTE_SOURCES=.
ENV REMOTE_SOURCES_DIR=/opt/app-root/src

WORKDIR $REMOTE_SOURCES_DIR/
COPY --from=build --chown=1001:1001 $REMOTE_SOURCES_DIR/.yarn $REMOTE_SOURCES_DIR/.yarn
COPY --from=build --chown=1001:1001 $REMOTE_SOURCES_DIR/.yarnrc.yml $REMOTE_SOURCES_DIR/
RUN chmod +x $REMOTE_SOURCES_DIR/.yarn/releases/yarn-1.22.19.cjs
# Stage 4 - Build the actual backend image and install production dependencies
FROM skeleton AS cleanup

# Copy the install dependencies from the build stage and context
COPY --from=build --chown=1001:1001 $REMOTE_SOURCES_DIR/yarn.lock $REMOTE_SOURCES_DIR/package.json $REMOTE_SOURCES_DIR/packages/backend/dist/skeleton.tar.gz $REMOTE_SOURCES_DIR/
COPY --from=build $CONTAINER_SOURCE/yarn.lock $CONTAINER_SOURCE/package.json $CONTAINER_SOURCE/packages/backend/dist/skeleton.tar.gz ./
RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz

# Copy the built packages from the build stage
COPY --from=build --chown=1001:1001 $REMOTE_SOURCES_DIR/packages/backend/dist/bundle.tar.gz $REMOTE_SOURCES_DIR/
RUN tar xzf $REMOTE_SOURCES_DIR/bundle.tar.gz && rm $REMOTE_SOURCES_DIR/bundle.tar.gz
COPY --from=build $CONTAINER_SOURCE/packages/backend/dist/bundle.tar.gz ./
RUN tar xzf bundle.tar.gz && rm bundle.tar.gz

# Copy any other files that we need at runtime
COPY --chown=1001:1001 $REMOTE_SOURCES/app-config.yaml \
$REMOTE_SOURCES/app-config.production.yaml \
$REMOTE_SOURCES/catalog-info.yaml \
$REMOTE_SOURCES/catalog-seed.yaml $REMOTE_SOURCES_DIR/
# Copy app-config files needed in runtime
COPY $EXTERNAL_SOURCE/app-config.yaml \
$EXTERNAL_SOURCE/app-config.production.yaml \
$EXTERNAL_SOURCE/catalog-info.yaml \
$EXTERNAL_SOURCE/catalog-seed.yaml ./

# Install production dependencies
RUN $YARN install --frozen-lockfile --production --network-timeout 600000 --ignore-scripts && $YARN cache clean
RUN "$YARN" install --frozen-lockfile --production --network-timeout 600000 && "$YARN" cache clean

# Stage 5 - Build the runner image
FROM registry.access.redhat.com/ubi9/nodejs-18-minimal:1-85.1699549021 AS runner
USER 0

# Env vars
ENV YARN=./.yarn/releases/yarn-1.22.19.cjs
ENV CONTAINER_SOURCE=/opt/app-root/src

WORKDIR $CONTAINER_SOURCE/
COPY --from=cleanup --chown=1001:1001 $CONTAINER_SOURCE/ ./

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line gives a Security Hotspot warning in Sonar Cloud. But, janus-idp/backstage-showcase#374 (comment) indicates it is a false positive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to mark it as such in Sonar, if that is alright with everyone

# The fix-permissions script is important when operating in environments that dynamically use a random UID at runtime, such as OpenShift.
# The upstream backstage image does not account for this and it causes the container to fail at runtime.
RUN fix-permissions $REMOTE_SOURCES_DIR/

RUN fix-permissions ./
# Switch to nodejs user
USER 1001

ENTRYPOINT ["node", "packages/backend", "--config", "app-config.yaml", "--config", "app-config.production.yaml"]
42 changes: 22 additions & 20 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,36 @@
"build-image": "docker build ../.. -f Dockerfile --tag backstage"
},
"dependencies": {
"@backstage/backend-common": "^0.18.5",
"@backstage/backend-tasks": "^0.5.2",
"@backstage/catalog-client": "^1.4.1",
"@backstage/catalog-model": "^1.3.0",
"@backstage/config": "^1.0.7",
"@backstage/plugin-app-backend": "^0.3.45",
"@backstage/plugin-auth-backend": "^0.18.3",
"@backstage/plugin-auth-node": "^0.2.14",
"@backstage/plugin-catalog-backend": "^1.9.1",
"@backstage/plugin-catalog-backend-module-github": "^0.3.0",
"@backstage/plugin-permission-common": "^0.7.5",
"@backstage/plugin-permission-node": "^0.7.8",
"@backstage/plugin-proxy-backend": "^0.2.39",
"@backstage/plugin-scaffolder-backend": "^1.14.0",
"@backstage/plugin-search-backend": "^1.3.1",
"@backstage/plugin-search-backend-module-pg": "^0.5.6",
"@backstage/plugin-search-backend-node": "^1.2.1",
"@backstage/backend-common": "^0.19.1",
"@backstage/backend-tasks": "^0.5.4",
"@backstage/catalog-client": "^1.4.3",
"@backstage/catalog-model": "^1.4.1",
"@backstage/config": "^1.0.8",
"@backstage/plugin-app-backend": "^0.3.47",
"@backstage/plugin-auth-backend": "^0.20.0",
"@backstage/plugin-auth-node": "^0.2.16",
"@backstage/plugin-catalog-backend": "^1.11.0",
"@backstage/plugin-catalog-backend-module-github": "^0.3.2",
"@backstage/plugin-permission-common": "^0.7.7",
"@backstage/plugin-permission-node": "^0.7.10",
"@backstage/plugin-proxy-backend": "^0.4.5",
"@backstage/plugin-scaffolder-backend": "^1.15.1",
"@backstage/plugin-search-backend": "^1.3.3",
"@backstage/plugin-search-backend-module-pg": "^0.5.8",
"@backstage/plugin-search-backend-node": "^1.2.3",
"@backstage/plugin-stack-overflow-backend": "^0.2.6",
"@backstage/plugin-techdocs-backend": "^1.6.2",
"@backstage/plugin-techdocs-backend": "^1.6.4",
"app": "link:../app",
"dockerode": "^3.3.1",
"express": "^4.17.1",
"express-promise-router": "^4.1.0",
"pg": "^8.10.0",
"winston": "^3.2.1"
"winston": "^3.2.1",
"node-gyp": "^9.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add node-gyp as per backstage/backstage#20695

"isolated-vm": "4.6.0"
},
"devDependencies": {
"@backstage/cli": "^0.22.7",
"@backstage/cli": "^0.22.9",
"@types/dockerode": "^3.3.0",
"@types/express": "^4.17.6",
"@types/express-serve-static-core": "^4.17.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
notFoundHandler,
CacheManager,
DatabaseManager,
SingleHostDiscovery,
HostDiscovery,
UrlReaders,
ServerTokenManager,
} from '@backstage/backend-common';
Expand All @@ -35,7 +35,7 @@ import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
function makeCreateEnv(config: Config) {
const root = getRootLogger();
const reader = UrlReaders.default({ logger: root, config });
const discovery = SingleHostDiscovery.fromConfig(config);
const discovery = HostDiscovery.fromConfig(config);
const cacheManager = CacheManager.fromConfig(config);
const databaseManager = DatabaseManager.fromConfig(config, { logger: root });
const tokenManager = ServerTokenManager.noop();
Expand Down
Loading