README.md 8.58 KB
Newer Older
Danjela Shehi's avatar
Danjela Shehi committed
1
2
# NCBI Project

3
4
[![MIT license](https://img.shields.io/badge/license-MIT-e51879.svg)](https://gitlab.coko.foundation/PubSweet/PubSweet/raw/master/LICENSE)
[![mattermost](https://img.shields.io/badge/mattermost_chat-coko%2FPubSweet-blue.svg)](https://mattermost.coko.foundation/coko/channels/PubSweet)
Danjela Shehi's avatar
Danjela Shehi committed
5
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
Danjela Shehi's avatar
Danjela Shehi committed
6
7
8

# Overview

Danjela Shehi's avatar
Danjela Shehi committed
9
This is the repository for the submission web application for NCBI.
Danjela Shehi's avatar
Danjela Shehi committed
10

11
The project is being developed by the [Coko Foundation](https://coko.foundation/) using [PubSweet](https://gitlab.coko.foundation/PubSweet/PubSweet).
Danjela Shehi's avatar
Danjela Shehi committed
12

Giannis Kopanas's avatar
Giannis Kopanas committed
13
# Dependencies
Giannis Kopanas's avatar
Giannis Kopanas committed
14
15
16

The main requirements for the project are `node` and `yarn`.

Giannis Kopanas's avatar
Giannis Kopanas committed
17
18
If you don't have yarn installed you can make use of NCBI script to install the recommended yarn version locally.

Giannis Kopanas's avatar
Giannis Kopanas committed
19
If you opt to use the `Postgres` docker container for the database, you should also have `docker` and `docker-compose` installed.
Danjela Shehi's avatar
Danjela Shehi committed
20

Giannis Kopanas's avatar
Giannis Kopanas committed
21
The current release (`v0.0.1`) has been developed with `node v12.14.1`, `yarn v1.22.4`, `docker v1.13.1` and `docker-compose v1.22.0`.
Giannis Kopanas's avatar
Giannis Kopanas committed
22
23

You can try newer versions of these dependencies (or use `npm` instead of `yarn`), but the above setup is the one supported by the development team, as well as the one assumed for these instructions.
Danjela Shehi's avatar
Danjela Shehi committed
24

Giannis Kopanas's avatar
Giannis Kopanas committed
25
# Installation / Start Application
Giannis Kopanas's avatar
Giannis Kopanas committed
26

Giannis Kopanas's avatar
Giannis Kopanas committed
27
### 1. Cloning the repository
28
29
30

---

Giannis Kopanas's avatar
Giannis Kopanas committed
31
32
33
34
First, you'll need to clone the repository:

```sh
git clone https://gitlab.coko.foundation/ncbi/ncbi.git ncbi
Danjela Shehi's avatar
Danjela Shehi committed
35
```
Giannis Kopanas's avatar
Giannis Kopanas committed
36

Giannis Kopanas's avatar
Giannis Kopanas committed
37
### 2. Running installation script
Giannis Kopanas's avatar
Giannis Kopanas committed
38

39
40
41
---

Installation script is located under `/scripts` folder.
Giannis Kopanas's avatar
Giannis Kopanas committed
42
Main job of this script is:
43
44
45
46
47

- install yarn locally if you don't have it already.
- install all npm package you need for the application
- configure your database (see configuration section)
- start your application fro the first time (see configuration section)
Giannis Kopanas's avatar
Giannis Kopanas committed
48

Giannis Kopanas's avatar
Giannis Kopanas committed
49
50
51
52
- if you have `yarn` already installed at your system, just make use of scripts at package.json file which will execute the installation script.

```sh
yarn install:ncbi
Danjela Shehi's avatar
Danjela Shehi committed
53
```
Giannis Kopanas's avatar
Giannis Kopanas committed
54
55
56
57

- if you don't have yarn installed. you can first install it locally using the script and then install the app

```sh
58
$ ./scripts/ncbi --install-yarn
Giannis Kopanas's avatar
Giannis Kopanas committed
59
60
$ source ~/.bashrc
$ yarn install:ncbi
Giannis Kopanas's avatar
Giannis Kopanas committed
61
```
Danjela Shehi's avatar
Danjela Shehi committed
62

63
or you can just leave it to script take care of installing automatically both application dependencies and yarn if cannot find it.
Danjela Shehi's avatar
Danjela Shehi committed
64

Giannis Kopanas's avatar
Giannis Kopanas committed
65
```sh
66
$ ./scripts/ncbi --install
Giannis Kopanas's avatar
Giannis Kopanas committed
67
$ source ~/.bashrc
Giannis Kopanas's avatar
Giannis Kopanas committed
68
```
Giannis Kopanas's avatar
Giannis Kopanas committed
69
70
71
72

In case you need to specify certain yarn version to install, you can specify it to configuration. see more below on configuration section

### 3. Start Application
73
74

---
Giannis Kopanas's avatar
Giannis Kopanas committed
75
76
77
78
79

Now we are ready to start the application.

```sh
$  yarn start
Giannis Kopanas's avatar
Giannis Kopanas committed
80
81
```

Giannis Kopanas's avatar
Giannis Kopanas committed
82
83
# Application Configuration

84
85
In the main folder there is a sample environmental variable file .env.example. By default application will make use of that file, unless finds
an .env file
Giannis Kopanas's avatar
Giannis Kopanas committed
86
87
88

Below you can see the variables currently exist table explaining and a short explanation.

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
| Variable              | Default Value                                         |                                                                                                                  Description |
| --------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------: |
| PUBSWEET_SECRET       | dev_secret                                            |                                                                                 unique key of the pubsweet. Security reasons |
| POSTGRES_USER         | dev                                                   |                           postgres user to be used during installation of postgres either with docker or installation script |
| POSTGRES_PASSWORD     | secretpassword                                        |               postgres password of user to be used during installation of postgres either with docker or installation script |
| POSTGRES_HOST         | localhost                                             |                           postgres host to be used during installation of postgres either with docker or installation script |
| POSTGRES_DB           | ncbi_dev                                              |                       postgres database to be used during installation of postgres either with docker or installation script |
| POSTGRES_PORT         | 5432                                                  |                           postgres port to be used during installation of postgres either with docker or installation script |
| DATABASE_URL          | postgres://dev:secretpassword@localhost:5432/ncbi_dev |                                                                           postgres connection string to be used from the app |
| WAIT_POSTGRES_PORT    | localhost:5432                                        |                                                needed from installation script and app to check the availability of database |
| WAIT_POSTGRES_TIMEOUT | 300                                                   |                                                            how long to wait before throwing error if database is not running |
| http_proxy=           | null                                                  |                                          by default this is null. you can specify this variable in order to be used by yarn. |
| DEV_SERVER_HOST       | localhost                                             |                                       if NODE_ENV is set to `development` specifies in which host the application is running |
| DEV_SERVER_PORT       | 3020                                                  |                                       if NODE_ENV is set to `development` specifies in which port the application is running |
| NODE_ENV              | development                                           | specifies the running mode of the app. other options are: `production`, `test` needs especially for webpack to build the app |
| ADMIN_USERNAME        | admin                                                 |                                                                              the first username of the app in order to login |
| ADMIN_EMAIL           | admin@example.com                                     |                                                                                                  the email fo the first user |
| ADMIN_PASSWORD        | password                                              |                                                                              the first password of the app in order to login |
| YARN_VERSION          | 1.22.4                                                |                            the version of yarn to be installed by installation script in order yarn is missing of the system |
Giannis Kopanas's avatar
Giannis Kopanas committed
108
109

# Local development with Docker
Giannis Kopanas's avatar
Giannis Kopanas committed
110

Danjela Shehi's avatar
Danjela Shehi committed
111
You can run and develop application using just docker and vsCode (Remote Containers). This is very helpful cause enables us
112
to run the app without think different version of yarn, node, Postgres and of course eliminates the possible bugs because of
Danjela Shehi's avatar
Danjela Shehi committed
113
different working station environment between developers. Also Windows users are able to run the app quickly just by having
Giannis Kopanas's avatar
Giannis Kopanas committed
114
115
116
117
118
docker installed at their systems.

Docker compose configuration files are available for now is only for development.

Run:
Danjela Shehi's avatar
Danjela Shehi committed
119

Giannis Kopanas's avatar
Giannis Kopanas committed
120
121
122
```
docker-compose up app
```
Danjela Shehi's avatar
Danjela Shehi committed
123

124
the above command will build the image where the dependencies of the app are installed( npm install ) and then run the app which includes running migration scripts, seeds scripts, bring PubSweet server up and running.
Giannis Kopanas's avatar
Giannis Kopanas committed
125

126
if you need to reinstall the dependencies you can re-build the image by `docker-compose build --no-cache app`
Giannis Kopanas's avatar
Giannis Kopanas committed
127
128
129

**Attention:**

Danjela Shehi's avatar
Danjela Shehi committed
130
131
132
133
1. Since application's dependencies are installed inside the container at your folder you can see an empty node_modules folder
2. Any changing happens to your local files will take affect and inside the container since we share volumes between docker container and host.
3. Since node_modules isn't available from the host . you are going to miss helpful executable features like eslint or prettier which are placed inside node_modules. One workaround is to access them through Remote Container plugins of your favorite editor. For
   VsCode you can use Remote Containers plugin (https://code.visualstudio.com/docs/remote/containers)
Giannis Kopanas's avatar
Giannis Kopanas committed
134

Giannis Kopanas's avatar
Giannis Kopanas committed
135
# FAQ
Danjela Shehi's avatar
Danjela Shehi committed
136
137
138
139
140

In case you have problems with installation , try restarting and rebuilding application with docker <br />
Try following commands : <br />

```
141
142

docker ps # then kill the docker process that is running for the ncbi
143

Danjela Shehi's avatar
Danjela Shehi committed
144
docker-compose down
145
sudo rm -rf data
146

147
docker-compose build --no-cache
Danjela Shehi's avatar
Danjela Shehi committed
148
149
150
docker-compose up app

```