Skip to content
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

Improve devx #158

Merged
merged 3 commits into from
Nov 6, 2024
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/datastore
/downloads
/env
/envs/dev
*.dump

53 changes: 31 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,15 @@ The third main component of the system **[nomad-spect-client](https://github.com
The repository contains all necessary configuration files to get you started in **[Docker](https://www.docker.com/)** environment.
You will need to install both docker engine and docker compose. The easiest way to achieve that is to install Docker Desktop available for all operating systems.

Clone both **nomad-server** and **nomad-spect-client** repositories
Clone **nomad-server** repository

```bash
git clone https://github.com/nomad-nmr/nomad-server.git
git clone https://github.com/nomad-nmr/nomad-spect-client.git
```

You can skip the latter if you want to leave the client out and work only with the server code. In that case, you need to comment out the client block in nomad-server/docker-compose.yaml file.

Before you start, the environmental variables needs to be set up in env folder. You can create the folder and copy content of env-example folder in it.

```bash
cd nomad-server
mkdir env
cp env-example/* env/
```

The system shall start without editing environmental variables. To achieve full functionality, following entries in backend.env file need to be edited.
To setup SMTP client for sending e-mails, following entries in /envs/dev/backend.env file need to be edited.

```env
#Password for automatically generated admin user
ADMIN_PASSWORD=''

#Secret word for generating JWT
JWT_SECRET=''

EMAIL_SUFFIX=''

#SMTP configuration
Expand All @@ -58,26 +41,52 @@ SMTP_PASS=''
SMTP_SENDER=''
```

To connect the spectrometer client, you need to login using admin username and the backdoor password that was set up in environmental variables and add an instrument into database. More information can be found on [documentation website](https://www.nomad-nmr.uk/docs/getting-started/NOMAD-config). Then you need to enter instrument ID in client.env file and restart the Docker containers.
You can possibly change the password for automatically generated admin user by editing the following entry.

```env
ADMIN_PASSWORD='foo'
```

To start NOMAD you need to navigate to nomad-server folder and run

```bash
docker-compose up -d
```

To start after updating dependencies in any package.json file you have to build new Docker images by using command
To start after updating dependencies in any package.json file you have to build new Docker images by using command

```bash
docker-compose up -d --build
```

To stop use command

```console
```bash
docker-compose down
```

### Connecting spectrometer client in development environment

Clone **nomad-spect-client** repository in the same folder next to **nomad-server** repository.

```bash
git clone https://github.com/nomad-nmr/nomad-spect-client.git
```

To connect the spectrometer client, you need to login using admin username and the backdoor password that was set up in environmental variables and add an instrument into database. More information can be found on [documentation website](https://www.nomad-nmr.uk/docs/getting-started/NOMAD-config). Then you need rewrite INSTRUMENT_ID entry in /envs/dev/client.env file using actual instrument ID.

To start NOMAD together with the client, you need to navigate to nomad-server folder and run

```bash
docker-compose --profile client up -d
```

after updating dependencies you need to use

```bash
docker-compose --profile client up -d --build
```

### Database dumps

**To dump database**
Expand Down
8 changes: 5 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
backend:
build: ./nomad-rest-api
env_file:
- ./env/backend.env
- ./envs/dev/backend.env
ports:
- '8080:8080'
volumes:
Expand All @@ -23,7 +23,7 @@ services:
frontend:
build: ./nomad-front-end
env_file:
- ./env/frontend.env
- ./envs/dev/frontend.env
ports:
- '3003:3003'
volumes:
Expand All @@ -34,6 +34,8 @@ services:
- backend

client:
profiles:
- client
build: ../nomad-spect-client
volumes:
- ../nomad-spect-client/src:/app/src
Expand All @@ -42,7 +44,7 @@ services:
- /mnt/c/Users/tl12/nomad-data-test/clientData/auto:/app/nmr-data/auto
- /mnt/c/Users/tl12/nomad-data-test/clientData/manual:/app/nmr-data/manual
env_file:
- ./env/client.env
- ./envs/dev/client.env

depends_on:
- backend
Expand Down
34 changes: 34 additions & 0 deletions envs/dev/backend-test.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
PORT=8080
MONGODB_URL='mongodb://mongodb:27017/nomad'
HOST='0.0.0.0'
#Frontend host url
FRONT_HOST_URL='http://localhost:3003'

#Password for automatically generated admin user
ADMIN_PASSWORD='foo'

#JWT expiration time in seconds. Set to 10h for development
JWT_EXPIRATION=36000

#Secret word for generating JWT
JWT_SECRET='bar'

EMAIL_SUFFIX=''

#SMTP configuration
SMTP_HOST=''
SMTP_PORT=587
SMTP_SECURE=false
SMTP_REQUIRE_TLS=true
SMTP_USER=''
SMTP_PASS=''
SMTP_SENDER=''

#Set true if NOMAD submission is used
SUBMIT_ON=true

#Set true if NOMAD datastore is used
DATASTORE_ON=true,
DATASTORE_PATH='/app/datastore'
#timeout for upload data route connection
DATA_UPLOAD_TIMEOUT=30000
35 changes: 35 additions & 0 deletions envs/dev/backend.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
NODE_ENV='dev'
PORT=8080
MONGODB_URL='mongodb://mongodb:27017/nomad'
HOST='0.0.0.0'
#Frontend host url
FRONT_HOST_URL='http://localhost:3003'

#Password for automatically generated admin user
ADMIN_PASSWORD='foo'

#JWT expiration time in seconds. Set to 10h for development
JWT_EXPIRATION=36000

#Secret word for generating JWT
JWT_SECRET='bar'

EMAIL_SUFFIX=''

#SMTP configuration
SMTP_HOST=''
SMTP_PORT=587
SMTP_SECURE=false
SMTP_REQUIRE_TLS=true
SMTP_USER=''
SMTP_PASS=''
SMTP_SENDER=''

#Set true if NOMAD submission is used
SUBMIT_ON=true

#Set true if NOMAD datastore is used
DATASTORE_ON=true,
DATASTORE_PATH='/app/datastore'
#timeout for upload data route connection
DATA_UPLOAD_TIMEOUT=30000
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions envs/example/client.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
INSTRUMENT_ID=60361c01a94fe37cd04dd7c3
STATUS_PATH= /app/status_files/status.html
HISTORY_PATH=/app/status_files/status.html
SERVER_URL=http://backend:8080
SUBMIT_PATH=/app/submit_files/
UPLOAD_DELAY=10000
7 changes: 7 additions & 0 deletions envs/example/frontend.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
VITE_API_URL=http://localhost:8080
VITE_NMRIUM_URL=http://localhost:3000

#Set true if corresponding NOMAD modules are used
VITE_SUBMIT_ON=true
VITE_BATCH_SUBMIT_ON=true
VITE_DATASTORE_ON=true
4 changes: 1 addition & 3 deletions nomad-rest-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ COPY package.json /app/

RUN npm install

COPY . .

EXPOSE 8080

CMD ["npm", "run" , "dev-docker"]
CMD ["npm", "run", "dev-docker"]
10 changes: 5 additions & 5 deletions nomad-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"main": "server.js",
"type": "module",
"scripts": {
"test-once": "env-cmd -f ../env/backend-test.env vitest --run",
"test-once": "env-cmd -f ../envs/dev/backend-test.env vitest --run",
"test-action": "vitest --run",
"test": "env-cmd -f ../env/backend-test.env vitest --reporter verbose",
"coverage": "env-cmd -f ../env/backend-test.env vitest run --coverage",
"start": "env-cmd -f ../env/api-no-docker.env node server.js",
"dev": "env-cmd -f ../env/api-no-docker.env nodemon server.js",
"test": "env-cmd -f ../envs/dev/backend-test.env vitest --reporter verbose",
"coverage": "env-cmd -f ../envs/dev/backend-test.env vitest run --coverage",
"start": "env-cmd -f ../envs/dev/api-no-docker.env node server.js",
"dev": "env-cmd -f ../envs/dev/api-no-docker.env nodemon server.js",
"dev-docker": "nodemon server.js"
},
"keywords": [],
Expand Down