Skip to content

Commit e3eebe7

Browse files
authored
Merge pull request #334 from forrestbao/main
revise README
2 parents 0471799 + 470e15c commit e3eebe7

File tree

1 file changed

+120
-33
lines changed

1 file changed

+120
-33
lines changed

README.md

Lines changed: 120 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,6 @@ plugin](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vsco
2424
to format your code before checking in.
2525
Last but not least, give us a star on Github!
2626

27-
# Citation
28-
29-
https://arxiv.org/abs/2301.02410
30-
31-
```
32-
@misc{https://doi.org/10.48550/arxiv.2301.02410,
33-
doi = {10.48550/ARXIV.2301.02410},
34-
url = {https://arxiv.org/abs/2301.02410},
35-
author = {Li, Hebi and Bao, Forrest Sheng and Xiao, Qi and Tian, Jin},
36-
title = {Codepod: A Namespace-Aware, Hierarchical Jupyter for Interactive Development at Scale},
37-
publisher = {arXiv},
38-
year = {2023},
39-
copyright = {Creative Commons Attribution 4.0 International}
40-
}
41-
```
42-
4327
# Gallery
4428

4529
Thanks to our community, we now have CodePod showcases ranging from analytical geometry to bioinformatics.
@@ -50,23 +34,47 @@ Thanks to our community, we now have CodePod showcases ranging from analytical g
5034

5135
# Developing CodePod using docker-compose
5236

53-
The docker compose files are in `compose/dev` folder. The `dev` stack mounts the
37+
First clone CodePod:
38+
39+
```bash
40+
git clone https://github.com/codepod-io/codepod.git
41+
```
42+
43+
We use the variable `CODEPOD_ROOT` to refer to the root folder of the CodePod.
44+
If you just ran the command above, then `CODEPOD_ROOT` is the folder you just cloned.
45+
46+
Now enter the `CODEPOD_ROOT/compose` folder:
47+
48+
```bash
49+
cd codepod/compose
50+
```
51+
52+
The docker compose files are in `CODEPOD_ROOT/compose/dev` folder. The `dev` stack mounts the
5453
`src` folder, so that you can edit the files on your local computer, and let the
5554
node.js process inside the container do the compiling and hot-reloading.
5655

5756
To install docker-compose, follow the official [Docker documentation](https://docs.docker.com/compose/install/linux/).
5857

5958
## .env file
6059

61-
First, create a `dev/.env` file with the following content (leave as is or change the value to
60+
Now enter the `CODEPOD_ROOT/compose/dev` folder
61+
62+
63+
```bash
64+
cd dev
65+
```
66+
67+
and create a `.env` file with the following content (leave as is or change the value to
6268
whatever you want).
6369

6470
```properties
71+
# Mandatory settings
6572
POSTGRES_USER=myusername
6673
POSTGRES_PASSWORD=mypassword
6774
POSTGRES_DB=mydbname
6875
JWT_SECRET=mysupersecretjwttoken
6976

77+
# optional settings
7078
GOOGLE_CLIENT_ID=<google oauth client id>
7179

7280
EXPORT_AWS_S3_REGION=us-west-1
@@ -80,37 +88,59 @@ Optional:
8088
- Leave the `GOOGLE_CLIENT_ID` empty if you do not need the OAuth provided by Google.
8189
- `EXPORT_AWS_S3_XXX` are used for file export. You could leave it empty if you don't use it.
8290

83-
## Start the stack
91+
## Starting the stack
92+
93+
From the `CODEPOD_ROOT/compose/dev` folder, run:
8494

8595
```bash
86-
cd dev
8796
docker compose up -d
8897
```
8998

90-
You need to initialized the database first before starting the stack. See below.
99+
If you this is your first time setting up CodePod, or the database schema has been updated (which you can tell from errors), you will also need to [initalize database tables](#initializing-the-database).
91100

92101
Wait a few minutes for the package installation and compilation. Once the `ui` and
93102
`api` containers are ready, go to `http://localhost:80` to see the app.
94103

95104
- `http://localhost:80/graphql`: Apollo GraphQL explorer for the backend APIs
96105
- `http://prisma.127.0.0.1.sslip.io`: Prisma Studio for viewing and debugging the database.
97106

98-
## Initialize the database
107+
### Initializing database tables
108+
109+
To initialize or update the database schema, open a shell into the API container (by default called `dev-api-1` but please use `docker ps` to confirm):
110+
111+
```bash
112+
docker exec -it dev-api-1 /bin/bash
113+
```
114+
115+
and then **from the shell of the API container** run:
99116

100-
If this is your first time running it, you would need to initialize the database as it's empty. To do that, open a shell into the API container and run:
101117

102-
```bash
103-
npx prisma migrate dev
104-
```
105118

106-
This command is also needed after the database schema is changed. The protocol is:
119+
> Known issues: if you get the error below during the migration,
120+
>
121+
> ```bash
122+
> EACCES: permission denied, unlink '/app/node_modules/.prisma/client/index.js'
123+
> EACCES: permission denied, unlink '/app/node_modules/.prisma/client/index.js'
124+
> ```
125+
> then please change the ownership of the folder `node_modules` (**from the shell of the API container**):
126+
> ```bash
127+
> chown node:node node_modules/ -R
128+
> ```
129+
> Afterwards, re-run
130+
> ```bash
131+
> npx prisma migrate dev
132+
> ```
107133
108-
- One developer changed [the schema](./api/prisma/schema.prisma). He will run
109-
`npx prisma migrate dev --name add_a_new_field`. This will generate a
110-
migration, e.g. [this
111-
migration](./api/prisma/migrations/20221206194247_add_google_login/migration.sql).
112-
The schema change along with this migration need to be checked in to git.
113-
- Another developer pulls the change, then running the `npx prisma migrate dev` (in the api container's shell) to apply the schema change.
134+
### Preparing for database migration
135+
136+
If you are a developer who wants to change the database schema for adding a feature, you can update the schema file `CODEPOD_ROOT/api/prisma/schema.prisma` and then run
137+
138+
```bash
139+
npx prisma migrate dev --name add_a_new_field
140+
```
141+
142+
to generate a migration, like [this](./api/prisma/migrations/20221206194247_add_google_login/migration.sql).
143+
The schema change along with this migration need to be checked in (add, commit, and push) to git.
114144

115145
## Auto-completion & Linting
116146

@@ -123,3 +153,60 @@ cd ./api/
123153
# Run 'npm install' instead if you are using npm
124154
yarn
125155
```
156+
157+
## Starting two stacks simultaneously
158+
159+
It might be necessary to create two Docker stacks for two verions of CodePod, respectively. For example, you might want to test the new version of CodePod while keeping the old version running.
160+
161+
Because Docker uses the folder name as the default suffix in container names, these two stacks may conflict with each other. To avoid this, you can use the `COMPOSE_PROJECT_NAME` environment variable to set a prefix for the container names. For example, you can set `COMPOSE_PROJECT_NAME=codepod-v2` in the `CODEPOD_ROOT/compose/dev/.env` file of the new stack, and then [start](#starting-the-stack) the new stack.
162+
163+
The two stacks also may share the same network ports due to the same configuration files used. To set the ports, search for the following lines in `CODEPOD_ROOT/compose/dev/nginx.conf` (two occurences of the two lines in the file) file of the new stack:
164+
165+
```yaml
166+
listen 80;
167+
listen [::]:80;
168+
```
169+
170+
and the following section in the `CODEPOD_ROOT/compose/dev/compose.yml` file of the new stack:
171+
172+
```
173+
nginx:
174+
image: nginx:alpine
175+
ports:
176+
- 80:80
177+
volumes:
178+
- ./nginx.conf:/etc/nginx/conf.d/default.conf
179+
```
180+
181+
and replace the default port number 80 to a new port number. For example, you can set the port number to 8080 for all occurences of 80.
182+
183+
Also, comment out the port section of the `ui` container in `CODEPOD_ROOT/compose/dev/compose.yml` as:
184+
185+
```
186+
ui:
187+
image: node:18
188+
working_dir: /app
189+
# ports:
190+
# For react hot-reloading in development.
191+
# - 3000:3000
192+
```
193+
194+
195+
Then, you can access the new stack at `http://localhost:8080`.
196+
197+
198+
# Citation
199+
200+
https://arxiv.org/abs/2301.02410
201+
202+
```
203+
@misc{https://doi.org/10.48550/arxiv.2301.02410,
204+
doi = {10.48550/ARXIV.2301.02410},
205+
url = {https://arxiv.org/abs/2301.02410},
206+
author = {Li, Hebi and Bao, Forrest Sheng and Xiao, Qi and Tian, Jin},
207+
title = {Codepod: A Namespace-Aware, Hierarchical Jupyter for Interactive Development at Scale},
208+
publisher = {arXiv},
209+
year = {2023},
210+
copyright = {Creative Commons Attribution 4.0 International}
211+
}
212+
```

0 commit comments

Comments
 (0)