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

Docker local dev #233

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
Dockerfile
dev.Dockerfile
docker-compose.yml
prod.docker-compose.yml

15 changes: 13 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# BACKEND

## DATABASE
POSTGRES_USER=docker
POSTGRES_PASSWORD=docker
POSTGRES_DATABASE=datatlas
POSTGRES_HOST=localhost
POSTGRES_HOST=postgres
POSTGRES_PORT=5432

## SALT
PASSWORD_SALT=put_long_string_here

## SEEDING USERS (1 admin and 1 editor)
[email protected]
ADMIN_PASSWORD=admin
[email protected]
DUMMY_EDITOR_PASSWORD=editor

# FRONTEND
REACT_APP_MAPBOX_ACCESS_TOKEN="defaultMapboxToken"
REACT_APP_DEFAULT_LOCALE='fr'
REACT_APP_API_BASE_URL=http://localhost:3333/api

# DEV USER ID
UID=1000
GID=1000
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,32 @@ cp .env.example .env
```
cp .env.example .env
docker compose up
nx run-many --target=serve
```

> **Note**: you must manually configure `pgadmin` :
>
> 1. Right-click _Servers > Register > Server..._
> 2. Under **Connection**:
>
> - **Host** `datatlas-db`
> - **Port**: `5432`
> - **Username**: `docker`
> - **Password**: `docker`
>
> https://towardsdatascience.com/how-to-run-postgresql-and-pgadmin-using-docker-3a6a8ae918b5

**Setup app `.env` :**

> See **app** [./apps/frontend/README.md](./apps/frontend/README.md).

## Development

### Ue docker for development

```
cp .env.example .env

docker-compose build
docker rm dev-datatlas-node-modules
docker run --name dev-datatlas-node-modules -d --env-file .env dev-datatlas tail -f /dev/null
docker cp dev-datatlas-node-modules:/datatlas/node_modules .
docker stop dev-datatlas-node-modules && docker rm dev-datatlas-node-modules
docker-compose up
```
No need to rerun all the command above for a second time, just run `docker-compose up` and it will start the containers.


**About .env file**
to get your user uid and gid run `id` in your terminal

### Code quality

Run `prettier` on whole repository:
Expand Down Expand Up @@ -121,3 +126,10 @@ Run `nx graph` to see a diagram of the dependencies of the projects.
### Further help

Visit the [Nx Documentation](https://nx.dev) to learn more.

### Troubleshooting

#### pgpass on my local machine does not automaticly connect to datatlas postgres database

The mounted pgpass file should have 0600 permissions. If not, pgpass will ignore it.
`chmod 0600 docker/pgadmin/pgpass`
2 changes: 1 addition & 1 deletion apps/backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
POSTGRES_USER=docker
POSTGRES_PASSWORD=docker
POSTGRES_DATABASE=datatlas
POSTGRES_HOST=datatlas-db
POSTGRES_HOST=postgres
POSTGRES_PORT=5432

# SALT
Expand Down
42 changes: 39 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: '3.1'
version: '3.9'

services:
postgres:
container_name: datatlas-db
container_name: dev-datatlas-db
image: kartoza/postgis:15-3.3
restart: unless-stopped
environment:
Expand All @@ -14,11 +14,47 @@ services:
- '5432:${POSTGRES_PORT}'

pgadmin:
container_name: pgadmin4_container
container_name: dev-datatlas-pgadmin
image: dpage/pgadmin4
restart: unless-stopped
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: root
ports:
- '5431:80'
volumes:
- ./pgadmin/servers.json:/pgadmin4/servers.json
- ./pgadmin/pgpass:/pgpass

backend:
container_name: dev-datatlas-backend
image: dev-datatlas
build:
dockerfile: docker/dev.Dockerfile
context: .
command: npx nx serve backend
depends_on:
- postgres
env_file:
- .env
volumes:
- ./apps/backend:/datatlas/apps/backend
- ./node_modules:/datatlas/node_modules
ports:
- 3333:3333
frontend:
container_name: dev-datatlas-frontend
image: dev-datatlas
build:
dockerfile: docker/dev.Dockerfile
context: .
command: npx nx serve frontend
env_file:
- .env
volumes:
- ./apps/frontend:/datatlas/apps/frontend
- ./node_modules:/datatlas/node_modules
ports:
- 3000:3000


File renamed without changes.
16 changes: 16 additions & 0 deletions docker/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:lts

# Create app directory
WORKDIR /datatlas

# Install app dependencies
COPY ./ /datatlas/

RUN npm install --force

# Install app dependencies
RUN npm install @nrwl/cli -g

CMD ["tail", "-f", "/dev/null"]


1 change: 1 addition & 0 deletions docker/pgadmin/pgpass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
postgres:5432:postgres:docker:docker
14 changes: 14 additions & 0 deletions docker/pgadmin/servers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Servers": {
"1": {
"Name": "datatlas",
"Group": "Servers",
"Host": "postgres",
"Port": 5432,
"MaintenanceDB": "postgres",
"Username": "docker",
"PassFile": "/pgpass",
"SSLMode": "prefer"
}
}
}
4 changes: 2 additions & 2 deletions prod.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
backend:
container_name: datatlas-backend
build:
dockerfile: Dockerfile
dockerfile: docker/Dockerfile
context: .
target: backend
args:
Expand All @@ -29,7 +29,7 @@ services:
frontend:
container_name: datatlas-frontend
build:
dockerfile: Dockerfile
dockerfile: docker/Dockerfile
context: .
target: frontend
args:
Expand Down