subzerocloud / subzero-cli

Tooling to aid development of subZero/PostgREST based backend APIs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prefer externally given value for APP_DIR instead of .env file path

rike422 opened this issue · comments

Hi

Thank you for providing us with a great package.

I have been using it since version 0.1, but when I built a repository with the following monorepo format, it stopped working with both updates.

packages
|-- subzero
    |-- db
    |-- node_modules
    |-- openresty
    `-- Dockerfile
|-- pkg1  
     `-- Dockerfile
|-- pkg2
     `-- Dockerfile
`-- pkg3
     `-- Dockerfile
`-- docker-compose.yml

I checked the contents of the update and found that it had changed to using docker-compose command to get containers, so I am trying to stop using the subzero containers and run them on the host machine.

However, we do not want to change the existing directory structure significantly, so we would like to keep what is under packages/subzero.
I tried to give the APP_DIR value set in env.js from an environment variable to make it work, but this value seems to be forced to be set in the same location as the .env file.

If I can set that value arbitrarily (the one specified in the environment variable has a higher priority), it appears to solve my problem.

I would like to send a PR if you approve this content, can I get your opinion?

Seems like a good change,
basically you are saying that on this line https://github.com/subzerocloud/subzero-cli/blob/master/src/env.js#L16
set the APP_DIR value to the location of the env file only if it's not yet set from the env file itself or from an external env var.

Sure, i can incorporate that change/pr.

PS: Can you please share (here or using other channels) some details about your project and the painpoints (and the good parts) of using subzero-cli setup in the long term? For me it was mostly about big diffs when views changed (they had to be dropped, which in turn generated reset of the permissions). This is what led to the latest structure of not diffing permissions/grants and having a file that resets all of them after each migration.

@ruslantalpa

Thanks for the quick response.
I am sorry if I misunderstood your intention, as I am not good at English.

In the current code, even if APP_DIR is set in .env, it will be overwritten and executed at the following location.

//It is assumed that the following settings have been made
// 1. .env files exist in the repository root
// 2. in .env, APP_DIR is given as "/repositoryRoot/packages/subzero/".

if (fs.existsSync(cfg.path) && fs.statSync(cfg.path).isFile()) {
  config(cfg);//.env file vars added to process.env
  process.env.ENV_FILE = resolve(cfg.path).replace(/\\/g, '/');
  console.log(process.env.APP_DIR)
  // output /repositoryRoot/packages/subzero/
  process.env.APP_DIR = dirname(process.env.ENV_FILE);
  console.log(process.env.APP_DIR)
  // output /repositoryRoot
}

set the APP_DIR value to the location of the env file only if it's not yet set from the env file itself or from an external env var.

process.env.APP_DIR = process.env.APP_DIR || dirname(process.env.ENV_FILE);

Is this perception correct?

Can you please share (here or using other channels) some details about your project and the painpoints (and the good parts) of using subzero-cli setup in the long term?

I see. I will ask the developer's boss if I can share it, since I am not the owner of that project.

Probably like this (please test if it works as you expect)

process.env.APP_DIR = (process.env.APP_DIR && dirname(process.env.APP_DIR)) || dirname(process.env.ENV_FILE);

@ruslantalpa
I created a pull request for this issue. Please confirm.

merged, i'll make a new release later

@ruslantalpa Hi

I have been away from projects using subzero for a while and it seems that the problem has arisen because a release of this change has not been made.
Could you please do a release incorporating this change?