Skip to content

Commit

Permalink
Revert "refine: change the way different environments are handled"
Browse files Browse the repository at this point in the history
This reverts commit fb768af.
  • Loading branch information
Elbarae1921 committed Oct 7, 2021
1 parent 4693451 commit c290bb8
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
!src
!public
# and files
!.env
!.env.prod
!*.json
!yarn.lock
20 changes: 10 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# env file for when running the app inside inside docker
# env file for when running the app outside of docker

POSTGRES_HOST = localhost
POSTGRES_PORT = database port
Expand All @@ -12,12 +12,12 @@ JWT_SECRET = secret
BCRYPT_ROUNDS = number of rounds

TYPEORM_CONNECTION = postgres
TYPEORM_HOST = db
TYPEORM_PORT = database port (same as POSTGRES_PORT)
TYPEORM_USERNAME = user (same as POSTGRES_USER)
TYPEORM_PASSWORD = password (same as POSTGRES_PASSWORD)
TYPEORM_DATABASE = database (same as POSTGRES_DB)
TYPEORM_ENTITIES = dist/**/**.entity.js
TYPEORM_MIGRATIONS = dist/migrations/*.js
TYPEORM_ENTITIES_DIR = dist/entities
TYPEORM_MIGRATIONS_DIR = dist/migrations
TYPEORM_HOST = localhost
TYPEORM_PORT = database port (same as DB_PORT)
TYPEORM_USERNAME = user (same as DB_USER)
TYPEORM_PASSWORD = password (same as DB_PASSWORD)
TYPEORM_DATABASE = database (same as DB_DATABASE)
TYPEORM_ENTITIES = src/entities/*.ts
TYPEORM_MIGRATIONS = src/migrations/*.ts
TYPEORM_ENTITIES_DIR = src/entities
TYPEORM_MIGRATIONS_DIR = src/migrations
23 changes: 0 additions & 23 deletions .env.local.example

This file was deleted.

23 changes: 23 additions & 0 deletions .env.prod.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# env file for when running the app inside inside docker

POSTGRES_HOST = localhost
POSTGRES_PORT = database port
POSTGRES_USER = user
POSTGRES_PASSWORD = password
POSTGRES_DB = database

PORT = 5000

JWT_SECRET = secret
BCRYPT_ROUNDS = number of rounds

TYPEORM_CONNECTION = postgres
TYPEORM_HOST = db
TYPEORM_PORT = database port (same as POSTGRES_PORT)
TYPEORM_USERNAME = user (same as POSTGRES_USER)
TYPEORM_PASSWORD = password (same as POSTGRES_PASSWORD)
TYPEORM_DATABASE = database (same as POSTGRES_DB)
TYPEORM_ENTITIES = dist/**/**.entity.js
TYPEORM_MIGRATIONS = dist/migrations/*.js
TYPEORM_ENTITIES_DIR = dist/entities
TYPEORM_MIGRATIONS_DIR = dist/migrations
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ temp/
.env.prod
!public/profile_pictures
public/profile_pictures/*
!public/profile_pictures/default.png
.env.local
!public/profile_pictures/default.png
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ COPY package.json ./
COPY yarn.lock ./
RUN yarn --prod
COPY --from=build /usr/dist ./dist/
EXPOSE ${PORT}
EXPOSE 5000
CMD [ "yarn", "start:prod"]
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Inspired by [mwanago's express-typescript](https://github.com/mwanago/express-ty

## Setup

Create a `.env.local` for local development (outisde docker) from the `.env.local.example` file.
Create a `.env` (for running the app outside of docker- development) and `.env.prod` (for running the app inside docker- production) file from the `.env.example` and `.env.prod.example` respectively, and assign the variables their corresponding values.

## Development
```bash
Expand All @@ -24,9 +24,6 @@ $ yarn start:dev
```

### Production

Create a `.env` for production from the `.env.example` file.

```bash
$ # start up the containers
$ yarn docker:compose
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ services:
volumes:
- pgdata:/var/lib/postgresql/data:delegated
ports:
- ${POSTGRES_PORT}:${POSTGRES_PORT}
env_file: .env
- ${POSTGRES_PORT}:5432
env_file: .env.prod
networks:
- app_net

app:
container_name: app
restart: always
build: .
env_file: .env
env_file: .env.prod
ports:
- ${PORT}:${PORT}
external_links:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"typeorm": "0.2.25"
},
"scripts": {
"start": "DOTENV_CONFIG_PATH=.env.local ts-node src/server.ts",
"start:dev": "DOTENV_CONFIG_PATH=.env.local nodemon src/server.ts",
"start": "ts-node src/server.ts",
"start:dev": "nodemon src/server.ts",
"build": "tsc",
"start:prod": "node dist/server.js",
"migration:generate": "ts-node ./node_modules/typeorm/cli.js migration:generate -n",
Expand Down

0 comments on commit c290bb8

Please sign in to comment.