Comments (8)
@jcloutz you can also load the .env file within docker-compose using env_file
instead of enumerating each value:
version: '3.1'
services:
pgsql:
image: postgres:9
ports:
- ${TYPEORM_PORT}:5432
env_file:
- .env
volumes:
- pg_data:/var/lib/postgres/data
volumes:
pg_data:
from typeorm.
@otroboe another cool thing you can do with direnv is create shell scripts for a specific project and modify the path for the current working directory.
This works like a charm with typeorm, i got annoyed having to invoke ts-node everytime i wanted to create or run migrations.
#!/bin/bash
#/path/to/program/bin/typeorm
./node_modules/.bin/ts-node ./node_modules/.bin/typeorm $1 $2 $3 $4 $5
from typeorm.
You don't need to do that with docker-compose, it loads the .env
file automatically.
https://docs.docker.com/compose/environment-variables/#the-env-file
from typeorm.
I'm closing it, it's not related to Nest, but TypeORM :-)
from typeorm.
@otroboe Take a look at using a .env file for config. It has some limitations with typeorm if you want to use more than one database but it should get the job done in most cases
Docker Compose Environment Vars & Typeorm
If you couple with something like Direnv to parse the .env file when you enter the directory it should work out pretty good.
# .env
HOST=localhost
PORT=8000
NODE_ENV=development
LOG_LEVEL=debug
TYPEORM_CONNECTION=postgres
TYPEORM_HOST=localhost
TYPEORM_USERNAME=postgres
TYPEORM_PASSWORD=postgres
TYPEORM_DATABASE=project_database
TYPEORM_PORT=5432
TYPEORM_SYNCHRONIZE=false
TYPEORM_DROP_SCHEMA=false
TYPEORM_LOGGING=all
TYPEORM_ENTITIES=src/common/entity/**/*.ts
TYPEORM_MIGRATIONS=src/database/migrations/**/*.ts
TYPEORM_SUBSCRIBERS=src/database/subscribers/**/*.ts
# .envrc used for direnv to modify shell when entering directory
# add {project_dir}/bin to path for helpers
export PATH=$(PWD)/bin:$PATH
# parse .env file when entering project dir
export $(egrep -v '^#' .env | xargs)
version: '3.1'
services:
pgsql:
image: postgres:9
ports:
- ${TYPEORM_PORT}:5432
environment:
POSTGRES_PASSWORD: ${TYPEORM_PASSWORD}
POSTGRES_DB: ${TYPEORM_DATABASE}
volumes:
- pg_data:/var/lib/postgres/data
volumes:
pg_data:
from typeorm.
Thank you ! I'll test your solution as soon as I can.
from typeorm.
@otroboe That's convenient! I guess in my habit of being explicit with Docker, that nuance got lost on me.
from typeorm.
You can still use the env_file
option for files not called .env
;-)
Like if you need different env files for each container.
from typeorm.
Related Issues (20)
- add nestjs v9 as a peer dependency of `@nestjs/typeorm` v8 HOT 1
- Nest could not find DataSource element HOT 3
- Result of query with comment is inconsistent and random HOT 20
- TypeOrmModule.forRoot() report errors: ConnectionNotFoundError: Connection "default" was not found. HOT 4
- '"typeorm"' has no exported member named 'InjectRepository'. Did you mean 'getRepository'? HOT 3
- setting synchronize to true gives me a typeorm error HOT 1
- When a custom converter is used on a column, migration fails.(nestjs+typeorm) HOT 1
- Testing mocker issues HOT 1
- Option to not initialize DataSource in createDataSourceFactory HOT 6
- Many to many relation is finding a column that doesn't exists HOT 1
- Polymorphic association #12750 HOT 1
- createTypeOrmProviders should inject EntityManager instead of Connection HOT 1
- Bring back keepConnectionAlive HOT 1
- auto db connection close problem When Execute Graceful shtudown with pm2 HOT 1
- Every migration:generate creates DROP/CREATES constraints and keys HOT 1
- Inject ConfigService into an Entity or Subscriber HOT 4
- Nestjs warns about "TypeOrmModule" taking a long time to serialize HOT 8
- TypeOrmModule makes @Request() unusable HOT 1
- When connectionstring param used, Hostname and database name are not correctly extracted HOT 2
- perhaps Typeorm module didn't passing request response to controller HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeorm.