You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
6
19
`src` folder, so that you can edit the files on your local computer, and let the
7
20
node.js process inside the container do the compiling and hot-reloading.
8
21
9
22
To install docker-compose, follow the official [Docker documentation](https://docs.docker.com/compose/install/linux/).
10
23
11
24
## .env file
12
25
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
14
33
whatever you want).
15
34
16
35
```properties
36
+
# Mandatory settings
17
37
POSTGRES_USER=myusername
18
38
POSTGRES_PASSWORD=mypassword
19
39
POSTGRES_DB=mydbname
20
40
JWT_SECRET=mysupersecretjwttoken
21
41
42
+
# optional settings
22
43
GOOGLE_CLIENT_ID=<google oauth client id>
23
44
24
45
EXPORT_AWS_S3_REGION=us-west-1
@@ -32,36 +53,61 @@ Optional:
32
53
- Leave the `GOOGLE_CLIENT_ID` empty if you do not need the OAuth provided by Google.
33
54
-`EXPORT_AWS_S3_XXX` are used for file export. You could leave it empty if you don't use it.
34
55
35
-
## Start the stack
56
+
## Starting the stack
57
+
58
+
From the `CODEPOD_ROOT/compose/dev` folder, run:
36
59
37
60
```bash
38
-
cd dev
39
61
docker compose up -d
40
62
```
41
63
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).
43
65
44
66
Wait a few minutes for the package installation and compilation. Once the `ui` and
45
67
`api` containers are ready, go to `http://localhost:80` to see the app.
46
68
47
69
-`http://localhost:80/graphql`: Apollo GraphQL explorer for the backend APIs
48
70
-`http://prisma.127.0.0.1.sslip.io`: Prisma Studio for viewing and debugging the database.
49
71
50
-
##Initialize the database
72
+
### Initializing database tables
51
73
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):
53
75
54
76
```bash
55
-
npx prisma migrate dev
77
+
docker exec -it dev-api-1 /bin/bash
56
78
```
57
79
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,
>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
+
```
59
108
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.
65
111
66
112
## Auto-completion & Linting
67
113
@@ -74,3 +120,42 @@ cd ./api/
74
120
# Run 'npm install' instead if you are using npm
75
121
yarn
76
122
```
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