q-shift / backstage-playground

2 stars 8 forks source link

Backstage backend fails to start with 2e2 job : Error: Missing required config value at 'backend.baseUrl' in 'app-config.local.yaml' #183

Closed cmoulliard closed 2 weeks ago

cmoulliard commented 2 weeks ago

Issue

The e2e job fails (since we merged PR with bash script) to start the backend and report this error Error: Missing required config value at 'backend.baseUrl' in 'app-config.local.yaml'

Job log

[0] Loaded config from app-config.local.yaml
[0] <i> [webpack-dev-server] Project is running at:
[0] <i> [webpack-dev-server] Loopback: http://localhost:3000/, http://[::1]:3000/
[0] <i> [webpack-dev-server] Content not from webpack is served from '/home/runner/work/backstage-playground/backstage-playground/packages/app/public' directory
[0] <i> [webpack-dev-server] 404s will fallback to '/index.html'
[0] <w> [ReactRefreshPlugin] Hot Module Replacement (HMR) is not enabled! React Refresh requires HMR to function properly.
[1] Loading config from MergedConfigSource{FileConfigSource{path="/home/runner/work/backstage-playground/backstage-playground/app-config.local.yaml"}, EnvConfigSource{count=0}}
[1] 2024-10-01T16:00:03.948Z backstage info Found 8 new secrets in config that will be redacted 
[1] 2024-10-01T16:00:03.960Z rootHttpRouter info Listening on :7007 
[1] 2024-10-01T16:00:03.964Z backstage info Plugin initialization started: 'auth', 'app', 'catalog', 'permission', 'proxy', 'scaffolder', 'search', 'techdocs', 'notifications', 'kubernetes', 'argocd', 'devtools' type=initialization
[1] /home/runner/work/backstage-playground/backstage-playground/node_modules/@backstage/backend-app-api/src/wiring/ServiceRegistry.ts:292
[1]             throw new Error(
[1]                   ^
[1] 
[1] 
[1] Error: Failed to instantiate service 'core.httpRouter' for 'auth' because the factory function threw an error, Error: Failed to instantiate service 'core.auth' for 'auth' because the factory function threw an error, Error: Failed to instantiate service 'core.discovery' for 'auth' because the factory function threw an error, Error: Missing required config value at 'backend.baseUrl' in 'app-config.local.yaml'
[1]     at <anonymous> (/home/runner/work/backstage-playground/backstage-playground/node_modules/@backstage/backend-app-api/src/wiring/ServiceRegistry.ts:292:19)
[1]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[1]     at async _ServiceRegistry.initializeEagerServicesWithScope (/home/runner/work/backstage-playground/backstage-playground/node_modules/@backstage/backend-app-api/src/wiring/ServiceRegistry.ts:212:11)
[1]     at async <anonymous> (/home/runner/work/backstage-playground/backstage-playground/node_modules/@backstage/backend-app-api/src/wiring/BackendInitializer.ts:239:9)
[1]     at async Promise.all (index 0)
[1]     at async BackendInitializer.doStart_fn (/home/runner/work/backstage-playground/backstage-playground/node_modules/@backstage/backend-app-api/src/wiring/BackendInitializer.ts:236:5)
[1]     at async BackendInitializer.start (/home/runner/work/backstage-playground/backstage-playground/node_modules/@backstage/backend-app-api/src/wiring/BackendInitializer.ts:150:5)
[1]     at async BackstageBackend.start (/home/runner/work/backstage-playground/backstage-playground/node_modules/@backstage/backend-app-api/src/wiring/BackstageBackend.ts:42:11)
[1

The error comes from PR 's change as some env var are not set properly. Here is what the job config yaml got as generated

cat <<EOF > backstage_env_secret.env
  APP_BASE_URL=http://localhost:3000
  BACKEND_BASE_URL=http://localhost:7007
  BACKSTAGE_AUTH_SECRET=$BACKSTAGE_AUTH_SECRET
  #TEMPLATE_URL=https://github.com/q-shift/backstage-playground/blob/main/locations/root.yaml
  ARGOCD_SERVER=$ARGOCD_SERVER_URL
  ARGOCD_ADMIN_USER=$ARGOCD_USERNAME
  ARGOCD_ADMIN_PASSWORD=$ARGOCD_PASSWORD
  GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_PERSONAL_ACCESS_TOKEN
  GITEA_URL=$GITEA_URL
  GITEA_USERNAME=$GITEA_USERNAME
  GITEA_PASSWORD="$GITEA_PASSWORD"
  KUBERNETES_API_URL=$API_URL
  SERVICE_ACCOUNT_TOKEN=$SERVICE_ACCOUNT_TOKEN
  EOF

  export $(grep -v '^#' backstage_env_secret.env | xargs)
  envsubst < manifest/templates/app-config.qshift.tmpl > app-config.local.yaml

  cat app-config.local.yaml
  shell: /usr/bin/bash -e {0}
  env:
    NODE_VERSION: 20.x
    IDPBUILDER_VERSION: v0.5.0
    TEKTON_VERSION: v0.60.1
    TEKTON_CLIENT_VERSION: 0.37.0
    ARGOCD_VERSION: 2.10.7
    GITEA_VERSION: 1.22
    ARGOCD_CLIENT_VERSION: v2.11.4
    KUBEVIRT_VERSION: v1.2.1
    KUBEVIRT_CDI_VERSION: v1.59.0
    REPO_NAME: my-quarkus-app-job
    REPO_ORG: q-shift
    QUAY_ORG: qshift
    KUBE_NAMESPACE: demo
    GITEA_URL: gitea.cnoe.localtest.me:8443
    GITEA_USERNAME: giteaAdmin
    GITEA_PASSWORD: t4#px>j-X>cK93_kHA!&w.[C4JN+*!/Rt@Zei&<@
    ARGOCD_SERVER_HOST: argocd.cnoe.localtest.me
    ARGOCD_SERVER_PORT: 8443
    ARGOCD_SERVER_URL: https://argocd.cnoe.localtest.me:8443/
    ARGOCD_USERNAME: admin
    ARGOCD_PASSWORD: SlGSYkyx901iUXLT
    SERVICE_ACCOUNT_TOKEN: ***
    BACKSTAGE_AUTH_SECRET: ****
    API_URL: https://127.0.0.1:40827/
    GITHUB_PERSONAL_ACCESS_TOKEN: ***
# Backstage override configuration for QShift

organization:
  name: QShift

app:
  title: QShift Backstage App
  baseUrl: 

backend:
  baseUrl: 
  listen:
    port: 7007
  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:  # Please include the port when using localhost !!
    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:'
  auth:
    # 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
    externalAccess:
      - type: static
        options:
          token: Z0X8JikXiZb72DH+dxyFUK/Q3k7DDTpO # Generate it using: node -p 'require("crypto").randomBytes(24).toString("base64")'
          subject: curl-requests

auth:
  environment: development
  # see https://backstage.io/docs/auth/ to learn about auth providers
  providers:
    guest: {
      dangerouslyAllowOutsideDevelopment: 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.

catalog:
  import:
    entityFilename: catalog-info.yaml
  rules:
    - allow: [API,Component,User,Group,Location,Resource,System,Template]
  locations:
    # Quarkus template, org, entity
    - type: file
      target: ../../locations/root.yaml
      rules:
        - allow: [API,Component,User,Group,Location,Resource,System,Template]

    #- type: url
    #  target:  # default could be : https://github.com/q-shift/backstage-playground/blob/main/locations/root.yaml
    #  rules:
    #    - allow: [API,Component,User,Group,Location,Resource,System,Template]

integrations:
  github:
    - host: github.com
      token: ***
  gitea:
    - host: 
      username: giteaAdmin
      password: "xxxxxxx"

argocd:
  username: admin
  password: SlGSYkyx901iUXLT
  baseUrl: https://argocd.cnoe.localtest.me:8443/
  appLocatorMethods:
    - type: config
      instances:
        - name: argocdQShift
          url: https://argocd.cnoe.localtest.me:8443/

kubernetes:
  serviceLocatorMethod:
    type: 'multiTenant'
  clusterLocatorMethods:
    - type: 'config'
      clusters:
        - url: https://127.0.0.1:40827/ # For in-cluster use: https://kubernetes.default.svc/
          name: ocp-qshift
          authProvider: 'serviceAccount'
          skipTLSVerify: true
          skipMetricsLookup: true
          serviceAccountToken: *** # Example: kubectl -n backstage get secret my-backstage-token-2l7b2 -o go-template='{{.data.token | base64decode}}'

FYI: @iocanel

cmoulliard commented 2 weeks ago

Here is what changed between before and now app/baseUrl: ${APP_BASE_URL} => app/baseUrl: ${BACKSTAGE_APP_BASE_URL} backend/baseUrl: ${BACKEND_BASE_URL} => backend/baseUrl: ${BACKSTAGE_BACKEND_BASE_URL} gitea/host: ${GITEA_URL} => gitea/host: ${GITEA_HOST}

cmoulliard commented 2 weeks ago

Job succeeded: https://github.com/q-shift/backstage-playground/actions/runs/11129816178