Skip to content
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
84 changes: 45 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,73 @@

![screenshot](./screenshot.png)

# Development
# Developing CodePod using docker-compose

The development environment is managed in docker compose file, because we have many components talking to each other. The up-to-date compose file is `./compose/dev2/compose.yml`.
The docker compose files are in `compose/` folder. There are two stacks:

First, create a file `./compose/dev2/.env` to setup DB credentials with your choice of values:
- The `dev` stack mounts the `src` folder, so that you can edit the files on
your local computer, and let the node.js process inside the container do the
compiling and hot-reloading.
- The `prod` stack builds the images instead of mounting `src` folders, for the
purpose of testing image builds.

```shell
POSTGRES_USER=<YOUR_USERNAME>
POSTGRES_PASSWORD=<YOUR_PASSWORD>
POSTGRES_DB=<YOUR_DBNAME>
JWT_SECRET=<YOUR_SUPER_SECRET_KEY>
```
## Prerequisite

Make sure you have the runtime containers images pulled.

Then, we need to run `docker compose up -d` to start the stack. But before that,
we need to install the node packages for the ui/api/proxy containers. To do
that, modify the command and tty like this:
- TODO automatically pull the images?
- TODO use a more generic image tag here, e.g. latest

```
api:
# ...
command: yarn
tty: true
ui:
# ...
command: yarn
tty: true
proxy:
# ...
command: yarn
tty: true
docker pull lihebi/codepod-kernel-python:v0.4.3-alpha.3
docker pull lihebi/codepod-runtime:v0.4.3-alpha.3
```

Then run:
Or you can build the images:

```
docker compose up -d
docker build -t lihebi/codepod-kernel-python:v0.4.3-alpha.3 ./runtime/kernel
docker build -t lihebi/codepod-runtime:v0.4.3-alpha.3 ./runtime
```

Now the node_modules are installed for the containers. Then **revert** those modifications, and run again:
## Usage

First, create a `dev/.env` file with the following content (change the value to
whatever you want):

```
docker compose up -d
POSTGRES_USER=myusername
POSTGRES_PASSWORD=mypassword
POSTGRES_DB=mydbname
JWT_SECRET=mysupersecretjwttoken
```

One last thing: initialize the DB: Attach a terminal to the `api` container and run:
Then, modify the nginx.conf and change the `server_name` field to your choices.
For example, if you are running on localhost, you can use:

```
npx prisma migrate dev --name init
server_name web.127.0.0.1.sslip.io;
server_name prisma.127.0.0.1.sslip.io;
```

Now you are all set. Go to

- http://localhost:3000: the UI of the web app
- http://localhost:4000/graphql: the app API server
- http://localhost:5555: the prisma DB viewer
Then, start the stack:

# Runtime spawners
```
cd dev
docker compose up -d
```

The API server needs to spawn runtime containers. There are two images (configured in the docker-compose file):
If this is your first time running it, the database is empty, and you need to
initialize the database. To do that, shell into the API container and run

```
docker build -t lihebi/codepod_kernel_python:v0.1.0 ./runtime/kernel
docker build -t lihebi/codepod_runtime:v0.0.1 ./runtime
npx prisma migrate dev --name init
```

Wait a few minutes for packages installation and compilation. Once `ui` and
`api` containers are ready listening on http ports, go to the DNS name you set
above, e.g. `http://web.127.0.0.1.sslip.io`, and you should see the web app UI.
Additional tools:

- `http://web.127.0.0.1.sslip.io/graphql`: Apollo GraphQL explorer for the backend APIs
- `http://prisma.127.0.0.1.sslip.io`: Prisma Studio for viewing and debugging the database.
Empty file added compose/README.md
Empty file.
159 changes: 0 additions & 159 deletions compose/dev/README.md

This file was deleted.

13 changes: 6 additions & 7 deletions compose/dev2/compose.yml → compose/dev/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ services:
prisma:
image: node:18
restart: always
command: yarn run prisma studio
command: npx prisma studio
working_dir: /app
volumes:
- ../../api:/app
- api-node-modules:/app/node_modules
environment:
DATABASE_URL: "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?schema=public"

Expand All @@ -30,30 +29,30 @@ services:
- ../../api:/app
- api-node-modules:/app/node_modules
- /var/run/docker.sock:/var/run/docker.sock
command: yarn dev # Run yarn for the first time.
command: sh -c "yarn && yarn dev"
environment:
DATABASE_URL: "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?schema=public"
JWT_SECRET: ${JWT_SECRET}
KERNEL_NETWORK: "codepod"
PROXY_API_URL: "http://proxy:4011/graphql"
ZMQ_KERNEL_IMAGE: "lihebi/codepod_kernel_python:v0.4.3-alpha.1"
WS_RUNTIME_IMAGE: "lihebi/codepod_runtime:v0.4.3-alpha.1"
ZMQ_KERNEL_IMAGE: "lihebi/codepod-kernel-python:v0.4.3-alpha.3"
WS_RUNTIME_IMAGE: "lihebi/codepod-runtime:v0.4.3-alpha.3"

ui:
image: node:18
working_dir: /app
volumes:
- ../../ui:/app
- ui-node-modules:/app/node_modules
command: yarn dev # Run yarn for the first time.
command: sh -c "yarn && yarn dev"

proxy:
image: node:18
working_dir: /app
volumes:
- ../../proxy:/app
- proxy-node-modules:/app/node_modules
command: yarn dev # Run yarn for the first time.
command: sh -c "yarn && yarn dev"

nginx:
image: nginx:alpine
Expand Down
Loading