Skip to content

feat(.env): allow environment variables to be passed dynamically to a container #1699

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -2,3 +2,4 @@
/.data
/dist
/files
.env
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ RUN sed -i 's/\r//g' /opt/wait-for-it.sh
RUN sed -i 's/\r//g' /opt/startup.relational.dev.sh

WORKDIR /usr/src/app
RUN if [ ! -f .env ]; then cp env-example-relational .env; fi
RUN npm run build

CMD ["/opt/startup.relational.dev.sh"]
3 changes: 2 additions & 1 deletion docker-compose.document.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ services:
dockerfile: document.Dockerfile
ports:
- ${APP_PORT}:${APP_PORT}

env_file:
- .env
volumes:
boilerplate-mongo-db:
3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ services:
dockerfile: Dockerfile
ports:
- ${APP_PORT}:${APP_PORT}

env_file:
- .env
volumes:
boilerplate-db:
1 change: 0 additions & 1 deletion document.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ RUN sed -i 's/\r//g' /opt/wait-for-it.sh
RUN sed -i 's/\r//g' /opt/startup.document.dev.sh

WORKDIR /usr/src/app
RUN if [ ! -f .env ]; then cp env-example-document .env; fi
RUN npm run build

CMD ["/opt/startup.document.dev.sh"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"private": true,
"license": "MIT",
"scripts": {
"typeorm": "env-cmd ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
"typeorm": "node typeorm-cli.js",
"migration:generate": "npm run typeorm -- --dataSource=src/database/data-source.ts migration:generate",
"migration:create": "npm run typeorm -- migration:create",
"migration:run": "npm run typeorm -- --dataSource=src/database/data-source.ts migration:run",
Expand Down
15 changes: 15 additions & 0 deletions typeorm-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const child_process = require('child_process');

const args = process.argv.slice(2).join(' ');

let command;
// Create the command to run TypeORM CLI with the provided arguments
if (process.env.NODE_ENV === undefined) {
command = `env-cmd ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js ${args}`;
} else {
command = `ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js ${args}`;
}

// Execute the command with the current environment variables
child_process.execSync(command, { stdio: 'inherit', env: process.env });