Skip to content

Use .env file for local setup #505

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

Merged
merged 7 commits into from
Apr 13, 2020
Merged
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
81 changes: 42 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,39 @@ Local setup should work good on **Linux** and **macOS**. But **Windows** is not
npm install
```

2. Local config

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>
```
AUTH0_CLIENT_ID=...
AUTH0_CLIENT_SECRET=...
AUTH0_URL=...
AUTH0_AUDIENCE=...
AUTH0_PROXY_SERVER_URL=...
```
Values from this file would be automatically used by `docker-compose` and command `npm run start:dev` below.

2. Copy config file `config/m2m.local.js` into `config/local.js`:
```bash
cp config/m2m.local.js config/local.js
```

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:
```
127.0.0.1 dockerhost
```

Alternatively, you may update `config/local.js` and replace `dockerhost` with your docker IP address.

3. Start **ONE** of the docker-compose files with dependant services which are required for Project Service to work

1. **Minimal** `./local/docker-compose.yml`:

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

Run, inside folder `./local`:
Run, in the project root folder:
```bash
docker-compose up
docker-compose -f local/docker-compose.yml up
```

<details><summary>Click to see details</summary>
Expand All @@ -64,17 +88,16 @@ Local setup should work good on **Linux** and **macOS**. But **Windows** is not

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

1. Set environment variables `AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`, `AUTH0_URL`, `AUTH0_AUDIENCE`, `AUTH0_PROXY_SERVER_URL`
2. Run, inside folder `./local/full`
1. Run, in the project root folder:

```bash
docker-compose up -d
docker-compose -f local/full/docker-compose.yml up -d
```

3. Wait until all containers are fully started. As a good indicator, wait until `project-processor-es` successfully started by viewing its logs:
2. Wait until all containers are fully started. As a good indicator, wait until `project-processor-es` successfully started by viewing its logs:

```bash
docker-compose logs -f project-processor-es
docker-compose -f local/full/docker-compose.yml logs -f project-processor-es
```

<details><summary>Click to see example logs</summary>
Expand All @@ -95,7 +118,7 @@ Local setup should work good on **Linux** and **macOS**. But **Windows** is not
```
</details>

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

<details><summary>Click to see details</summary>
<br>
Expand All @@ -121,56 +144,37 @@ Local setup should work good on **Linux** and **macOS**. But **Windows** is not
- 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:

```bash
cd local/full
docker-compose logs -f SERVICE_NAME
docker-compose -f local/full/docker-compose.yml logs -f SERVICE_NAME
```

</details>

*NOTE: In production these dependencies / services are hosted & managed outside Project Service.*

4. Local config

1. Copy config file `config/m2m.local.js` into `config/local.js`:
```bash
cp config/m2m.local.js config/local.js
```

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:
```
127.0.0.1 dockerhost
```

Alternatively, you may update `config/local.js` and replace `dockerhost` with your docker IP address.

5. Create tables in DB
4. Create tables in DB
```bash
NODE_ENV=development npm run sync:db
```

*NOTE: this will drop tables if they already exist.*

6. Create ES (Elasticsearch) indexes
5. Create ES (Elasticsearch) indexes
```bash
NODE_ENV=development npm run sync:es
```

*NOTE: This will first clear all the indices and than recreate them. So use with caution.*

7. Start Project Service

1. Set environment variables `AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`, `AUTH0_URL`, `AUTH0_AUDIENCE`, `AUTH0_PROXY_SERVER_URL`
6. Start Project Service

2. Run

```bash
npm run start:dev
```
```bash
npm run start:dev
```

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

8. *(Optional)* Start Project Service Kafka Consumer
7. *(Optional)* Start Project Service Kafka Consumer

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

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

## References

- [Projects Service Architecture](./docs/guides/architercture/architecture.md)
- [Projects Service Architecture](./docs/guides/architercture/architecture.md)
- [Projects Service Architecture](./docs/guides/architercture/architecture.md)
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"migrate:bookmarks:revert": "./node_modules/.bin/babel-node migrations/bookmarks/migrateLinksToBookmarks.js",
"prestart": "npm run -s build",
"start": "node dist",
"start:dev": "NODE_ENV=development PORT=8001 nodemon -w src --exec \"babel-node src --presets es2015\" | ./node_modules/.bin/bunyan",
"start:dev": "NODE_ENV=development PORT=8001 nodemon -w src --exec \"node --require dotenv/config --require babel-core/register src\" | ./node_modules/.bin/bunyan",
"startKafkaConsumers": "npm run -s build && node dist/index-kafka.js",
"startKafkaConsumers:dev": "NODE_ENV=development nodemon -w src --exec \"babel-node src/index-kafka.js --presets es2015\" | ./node_modules/.bin/bunyan",
"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",
Expand Down Expand Up @@ -51,6 +51,7 @@
"config": "^1.20.1",
"continuation-local-storage": "^3.1.7",
"cors": "^2.8.4",
"dotenv": "^8.2.0",
"elasticsearch": "^16.1.1",
"express": "^4.13.4",
"express-list-routes": "^0.1.4",
Expand Down