Git Product home page Git Product logo

Comments (8)

joshuamanns avatar joshuamanns commented on May 20, 2024 3

@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.

jcloutz avatar jcloutz commented on May 20, 2024 1

@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.

otroboe avatar otroboe commented on May 20, 2024 1

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.

otroboe avatar otroboe commented on May 20, 2024

I'm closing it, it's not related to Nest, but TypeORM :-)

from typeorm.

jcloutz avatar jcloutz commented on May 20, 2024

@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.

otroboe avatar otroboe commented on May 20, 2024

Thank you ! I'll test your solution as soon as I can.

from typeorm.

joshuamanns avatar joshuamanns commented on May 20, 2024

@otroboe That's convenient! I guess in my habit of being explicit with Docker, that nuance got lost on me.

from typeorm.

otroboe avatar otroboe commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.