Skip to content

Commit d988653

Browse files
authored
move developer manual here from source code repo (#9)
1 parent a3382ab commit d988653

File tree

1 file changed

+100
-15
lines changed

1 file changed

+100
-15
lines changed

docs/4-developer/README.md

Lines changed: 100 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
# Developer Manual
22

3-
The development repository is https://github.com/codepod-io/codepod
3+
First clone CodePod:
44

5-
The docker compose files are in `compose/dev` folder. The `dev` stack mounts the
5+
```bash
6+
git clone https://github.com/codepod-io/codepod.git
7+
```
8+
9+
We use the variable `CODEPOD_ROOT` to refer to the root folder of the CodePod.
10+
If you just ran the command above, then `CODEPOD_ROOT` is the folder you just cloned.
11+
12+
Now enter the `CODEPOD_ROOT/compose` folder:
13+
14+
```bash
15+
cd codepod/compose
16+
```
17+
18+
The docker compose files are in `CODEPOD_ROOT/compose/dev` folder. The `dev` stack mounts the
619
`src` folder, so that you can edit the files on your local computer, and let the
720
node.js process inside the container do the compiling and hot-reloading.
821

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

1124
## .env file
1225

13-
First, create a `dev/.env` file with the following content (leave as is or change the value to
26+
Now enter the `CODEPOD_ROOT/compose/dev` folder
27+
28+
```bash
29+
cd dev
30+
```
31+
32+
and create a `.env` file with the following content (leave as is or change the value to
1433
whatever you want).
1534

1635
```properties
36+
# Mandatory settings
1737
POSTGRES_USER=myusername
1838
POSTGRES_PASSWORD=mypassword
1939
POSTGRES_DB=mydbname
2040
JWT_SECRET=mysupersecretjwttoken
2141

42+
# optional settings
2243
GOOGLE_CLIENT_ID=<google oauth client id>
2344

2445
EXPORT_AWS_S3_REGION=us-west-1
@@ -32,36 +53,61 @@ Optional:
3253
- Leave the `GOOGLE_CLIENT_ID` empty if you do not need the OAuth provided by Google.
3354
- `EXPORT_AWS_S3_XXX` are used for file export. You could leave it empty if you don't use it.
3455

35-
## Start the stack
56+
## Starting the stack
57+
58+
From the `CODEPOD_ROOT/compose/dev` folder, run:
3659

3760
```bash
38-
cd dev
3961
docker compose up -d
4062
```
4163

42-
You need to initialized the database first before starting the stack. See below.
64+
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).
4365

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

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

50-
## Initialize the database
72+
### Initializing database tables
5173

52-
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:
74+
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):
5375

5476
```bash
55-
npx prisma migrate dev
77+
docker exec -it dev-api-1 /bin/bash
5678
```
5779

58-
This command is also needed after the database schema is changed. The protocol is:
80+
and then **from the shell of the API container** run:
81+
82+
> Known issues: if you get the error below during the migration,
83+
>
84+
> ```bash
85+
> EACCES: permission denied, unlink '/app/node_modules/.prisma/client/index.js'
86+
> EACCES: permission denied, unlink '/app/node_modules/.prisma/client/index.js'
87+
> ```
88+
>
89+
> then please change the ownership of the folder `node_modules` (**from the shell of the API container**):
90+
>
91+
> ```bash
92+
> chown node:node node_modules/ -R
93+
> ```
94+
>
95+
> Afterwards, re-run
96+
>
97+
> ```bash
98+
> npx prisma migrate dev
99+
> ```
100+
101+
### Preparing for database migration
102+
103+
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
104+
105+
```bash
106+
npx prisma migrate dev --name add_a_new_field
107+
```
59108
60-
- One developer changed the schema `./api/prisma/schema.prisma`. He will run
61-
`npx prisma migrate dev --name add_a_new_field`. This will generate a
62-
migration.
63-
The schema change along with this migration need to be checked in to git.
64-
- Another developer pulls the change, then running the `npx prisma migrate dev` (in the api container's shell) to apply the schema change.
109+
to generate a migration, like [this](./api/prisma/migrations/20221206194247_add_google_login/migration.sql).
110+
The schema change along with this migration need to be checked in (add, commit, and push) to git.
65111

66112
## Auto-completion & Linting
67113

@@ -74,3 +120,42 @@ cd ./api/
74120
# Run 'npm install' instead if you are using npm
75121
yarn
76122
```
123+
124+
## Starting two stacks simultaneously
125+
126+
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.
127+
128+
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.
129+
130+
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:
131+
132+
```yaml
133+
listen 80;
134+
listen [::]:80;
135+
```
136+
137+
and the following section in the `CODEPOD_ROOT/compose/dev/compose.yml` file of the new stack:
138+
139+
```
140+
nginx:
141+
image: nginx:alpine
142+
ports:
143+
- 80:80
144+
volumes:
145+
- ./nginx.conf:/etc/nginx/conf.d/default.conf
146+
```
147+
148+
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.
149+
150+
Also, comment out the port section of the `ui` container in `CODEPOD_ROOT/compose/dev/compose.yml` as:
151+
152+
```
153+
ui:
154+
image: node:18
155+
working_dir: /app
156+
# ports:
157+
# For react hot-reloading in development.
158+
# - 3000:3000
159+
```
160+
161+
Then, you can access the new stack at `http://localhost:8080`.

0 commit comments

Comments
 (0)