Skip to content

Commit 18a778b

Browse files
authored
Use .env file for local setup (#505)
* feat: use .env file for "npm run start:dev" * docs: use .env file for docker and "start:dev" * chore: reduce chance for committing Auth0 values
1 parent 1bdb224 commit 18a778b

File tree

3 files changed

+49
-40
lines changed

3 files changed

+49
-40
lines changed

README.md

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,39 @@ Local setup should work good on **Linux** and **macOS**. But **Windows** is not
3636
npm install
3737
```
3838

39+
2. Local config
40+
41+
1. In the `tc-project-service` root directory create `.env` file with the environment variables _(values should be shared with you on the forum)_:<br>
42+
```
43+
AUTH0_CLIENT_ID=...
44+
AUTH0_CLIENT_SECRET=...
45+
AUTH0_URL=...
46+
AUTH0_AUDIENCE=...
47+
AUTH0_PROXY_SERVER_URL=...
48+
```
49+
Values from this file would be automatically used by `docker-compose` and command `npm run start:dev` below.
50+
51+
2. Copy config file `config/m2m.local.js` into `config/local.js`:
52+
```bash
53+
cp config/m2m.local.js config/local.js
54+
```
55+
56+
3. Set `dockerhost` to point the IP address of Docker. Docker IP address depends on your system. For example if docker is run on IP `127.0.0.1` add a the next line to your `/etc/hosts` file:
57+
```
58+
127.0.0.1 dockerhost
59+
```
60+
61+
Alternatively, you may update `config/local.js` and replace `dockerhost` with your docker IP address.
62+
3963
3. Start **ONE** of the docker-compose files with dependant services which are required for Project Service to work
4064
4165
1. **Minimal** `./local/docker-compose.yml`:
4266
4367
*Use this docker-compose if you only want to test and modify code of Project Service and you don't need Elasticsearch (ES) to work.*
4468
45-
Run, inside folder `./local`:
69+
Run, in the project root folder:
4670
```bash
47-
docker-compose up
71+
docker-compose -f local/docker-compose.yml up
4872
```
4973
5074
<details><summary>Click to see details</summary>
@@ -64,17 +88,16 @@ Local setup should work good on **Linux** and **macOS**. But **Windows** is not
6488
6589
*Use this docker-compose if you want to test and modify code of Project Service together with one of the next relative services: [tc-bus-api](https://github.com/topcoder-platform/tc-bus-api), [project-processor-es](https://github.com/topcoder-platform/project-processor-es), [tc-notifications](https://github.com/topcoder-platform/tc-notifications) or you need Elasticsearch (ES) to work.*
6690
67-
1. Set environment variables `AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`, `AUTH0_URL`, `AUTH0_AUDIENCE`, `AUTH0_PROXY_SERVER_URL`
68-
2. Run, inside folder `./local/full`
91+
1. Run, in the project root folder:
6992
7093
```bash
71-
docker-compose up -d
94+
docker-compose -f local/full/docker-compose.yml up -d
7295
```
7396
74-
3. Wait until all containers are fully started. As a good indicator, wait until `project-processor-es` successfully started by viewing its logs:
97+
2. Wait until all containers are fully started. As a good indicator, wait until `project-processor-es` successfully started by viewing its logs:
7598
7699
```bash
77-
docker-compose logs -f project-processor-es
100+
docker-compose -f local/full/docker-compose.yml logs -f project-processor-es
78101
```
79102
80103
<details><summary>Click to see example logs</summary>
@@ -95,7 +118,7 @@ Local setup should work good on **Linux** and **macOS**. But **Windows** is not
95118
```
96119
</details>
97120
98-
4. If you want to modify the code of any of the services which are run inside this docker-compose file, you can stop such service inside docker-compose by command `docker-compose stop -f <SERVICE_NAME>` and run the service separately, following its README file.
121+
3. If you want to modify the code of any of the services which are run inside this docker-compose file, you can stop such service inside docker-compose by command `docker-compose -f local/full/docker-compose.yml stop -f <SERVICE_NAME>` and run the service separately, following its README file.
99122
100123
<details><summary>Click to see details</summary>
101124
<br>
@@ -121,56 +144,37 @@ Local setup should work good on **Linux** and **macOS**. But **Windows** is not
121144
- To view the logs from any container inside docker-compose use the following command, replacing `SERVICE_NAME` with the corresponding value under the **Name** column in the above table:
122145
123146
```bash
124-
cd local/full
125-
docker-compose logs -f SERVICE_NAME
147+
docker-compose -f local/full/docker-compose.yml logs -f SERVICE_NAME
126148
```
127149
128150
</details>
129151
130152
*NOTE: In production these dependencies / services are hosted & managed outside Project Service.*
131153
132-
4. Local config
133-
134-
1. Copy config file `config/m2m.local.js` into `config/local.js`:
135-
```bash
136-
cp config/m2m.local.js config/local.js
137-
```
138-
139-
2. Set `dockerhost` to point the IP address of Docker. Docker IP address depends on your system. For example if docker is run on IP `127.0.0.1` add a the next line to your `/etc/hosts` file:
140-
```
141-
127.0.0.1 dockerhost
142-
```
143-
144-
Alternatively, you may update `config/local.js` and replace `dockerhost` with your docker IP address.
145-
146-
5. Create tables in DB
154+
4. Create tables in DB
147155
```bash
148156
NODE_ENV=development npm run sync:db
149157
```
150158
151159
*NOTE: this will drop tables if they already exist.*
152160
153-
6. Create ES (Elasticsearch) indexes
161+
5. Create ES (Elasticsearch) indexes
154162
```bash
155163
NODE_ENV=development npm run sync:es
156164
```
157165
158166
*NOTE: This will first clear all the indices and than recreate them. So use with caution.*
159167
160-
7. Start Project Service
161-
162-
1. Set environment variables `AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`, `AUTH0_URL`, `AUTH0_AUDIENCE`, `AUTH0_PROXY_SERVER_URL`
168+
6. Start Project Service
163169
164-
2. Run
165-
166-
```bash
167-
npm run start:dev
168-
```
170+
```bash
171+
npm run start:dev
172+
```
169173

170-
Runs the Project Service using nodemon, so it would be restarted after any of the files is updated.
171-
The project service will be served on `http://localhost:8001`.
174+
Runs the Project Service using nodemon, so it would be restarted after any of the files is updated.
175+
The project service will be served on `http://localhost:8001`.
172176

173-
8. *(Optional)* Start Project Service Kafka Consumer
177+
7. *(Optional)* Start Project Service Kafka Consumer
174178

175179
*Run this only if you want to test or modify logic of `lastActivityAt` or `lastActivityBy`.*
176180

@@ -275,5 +279,4 @@ docker exec -it tc-projects-kafka /opt/kafka/bin/kafka-console-producer.sh --bro
275279

276280
## References
277281

278-
- [Projects Service Architecture](./docs/guides/architercture/architecture.md)
279-
- [Projects Service Architecture](./docs/guides/architercture/architecture.md)
282+
- [Projects Service Architecture](./docs/guides/architercture/architecture.md)

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"migrate:bookmarks:revert": "./node_modules/.bin/babel-node migrations/bookmarks/migrateLinksToBookmarks.js",
2020
"prestart": "npm run -s build",
2121
"start": "node dist",
22-
"start:dev": "NODE_ENV=development PORT=8001 nodemon -w src --exec \"babel-node src --presets es2015\" | ./node_modules/.bin/bunyan",
22+
"start:dev": "NODE_ENV=development PORT=8001 nodemon -w src --exec \"node --require dotenv/config --require babel-core/register src\" | ./node_modules/.bin/bunyan",
2323
"startKafkaConsumers": "npm run -s build && node dist/index-kafka.js",
2424
"startKafkaConsumers:dev": "NODE_ENV=development nodemon -w src --exec \"babel-node src/index-kafka.js --presets es2015\" | ./node_modules/.bin/bunyan",
2525
"test": "NODE_ENV=test npm run lint && NODE_ENV=test npm run sync:es && NODE_ENV=test npm run sync:db && NODE_ENV=test ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- --timeout 10000 --require babel-core/register $(find src -path '*spec.js*') --exit",
@@ -51,6 +51,7 @@
5151
"config": "^1.20.1",
5252
"continuation-local-storage": "^3.1.7",
5353
"cors": "^2.8.4",
54+
"dotenv": "^8.2.0",
5455
"elasticsearch": "^16.1.1",
5556
"express": "^4.13.4",
5657
"express-list-routes": "^0.1.4",

0 commit comments

Comments
 (0)