Deploying Strapi with Fly.io and GitHub Actions: Error while running command build: Could not load js config file /opt/app/config/env/qa/database.js: host is not defined

Hello,

I’m trying to deploy with Fly.io with GitHub Actions. I’ve defined secrets within the repository scope on GitHub.

Guidance provided by: Continuous Deployment with Fly and GitHub Actions · Fly Docs

I’m getting an error on npm run build which suggests that there is an issue with reading the DATABASE_URL

#11 [8/8] RUN npm run build
#11 0.643 
#11 0.643 > ***@0.1.0 build
#11 0.643 > strapi build
#11 0.643 
#11 1.799 Error while running command build: Could not load js config file /opt/app/config/env/qa/database.js: host is not defined
#11 ERROR: executor failed running [/bin/sh -c npm run build]: exit code: 1
------
 > [8/8] RUN npm run build:
#11 0.643 
#11 0.643 > ***@0.1.0 build
#11 0.643 > strapi build
#11 0.643 
#11 1.799 Error while running command build: Could not load js config file /opt/app/config/env/qa/database.js: host is not defined
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c npm run build]: exit code: 1


Error: Process completed with exit code 1.

config/env/qa/database.js

const parse = require("pg-connection-string").parse;
const { host, port, database, user, password } = parse(process.env.DATABASE_URL);

module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: 'postgres',
        host,
        port,
        database,
        user,
        password,
        ssl: false,
      },
      debug: false,
      options: {},
    },
  },
});

GitHub Actions Secrets

Related

Thanks for your help!

Whilst not a solution for just having DATABASE_URL and using:

const parse = require("pg-connection-string").parse;
const { host, port, database, user, password } = parse(process.env.DATABASE_URL);

I’ve found that if you define the environment variables separately and then you have something like:

module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: env("DATABASE_CLIENT", "postgres"),
        host: env("DATABASE_HOST", "127.0.0.1"),
        port: env.int("DATABASE_PORT", 5432),
        database: env("DATABASE_NAME", "strapi"),
        user: env("DATABASE_USERNAME", "strapi"),
        password: env("DATABASE_PASSWORD", "strapi"),
        ssl: false,
      },
      debug: false,
      options: {},
    },
  },
});

this works.

1 Like