Skip to content

Commit 5f732e0

Browse files
authored
feat: Add docker-compose.yml to the Bison template. (#310)
1 parent 19d2e63 commit 5f732e0

File tree

5 files changed

+49
-14
lines changed

5 files changed

+49
-14
lines changed

docs/postgres.md

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
# Run Postgres with Bison
1+
# Run Postgres with Bison
22

33
1. Setup a database locally ([Postgres](https://postgresapp.com/downloads.html) is the only type fully supported right now)
44
1. Make sure your database user has permission to create schemas and databases. We recommend using a superuser account locally to keep things easy.
55
1. Setup your local database with `yarn db:setup`. You'll be prompted to create it if it doesn't already exist:1. Setup a database locally ([Postgres](https://postgresapp.com/downloads.html) is the only type fully supported right now)
66
1. Make sure your database user has permission to create schemas and databases. We recommend using a superuser account locally to keep things easy.
77
1. Setup your local database with `yarn db:setup`. You'll be prompted to create it if it doesn't already exist:
8-
When creating a bison app, you are prompted with questions to set up your app along with Postgres.
8+
When creating a bison app, you are prompted with questions to set up your app along with Postgres.
99

1010
![Prisma DB Create Prompt](https://user-images.githubusercontent.com/14339/88480536-7e1fb180-cf24-11ea-85c9-9bed43c9dfe4.png)
1111

1212
Need help setting up Postgres locally?
1313

14-
#### Install Postgres on Mac
15-
Mac: https://postgresapp.com/
14+
## Install Postgres on Mac
1615

17-
#### Install Postgres on Windows
18-
Windows: https://www.postgresql.org/download/windows/
16+
Mac: <https://postgresapp.com/>
17+
18+
## Install Postgres on Windows
19+
20+
Windows: <https://www.postgresql.org/download/windows/>
1921

2022
## Run Postgres with Docker
2123

@@ -40,41 +42,46 @@ services:
4042
POSTGRES_PASSWORD: dev
4143
POSTGRES_DB: dev
4244
```
45+
4346
A different schema is created for your testing data.
4447

45-
Please note the ports to adjust your environment variables. See below for an example.
48+
Please note the ports to adjust your environment variables. See below for an example.
4649

4750
Add `.data/` to your `.gitignore`
4851

49-
#### Edit your environment variables:
52+
### Edit your environment variables
53+
5054
Change the database URL in `.env.local`:
51-
```
55+
56+
```bash
5257
DATABASE_URL="postgres://dev:dev@postgres:5433/dev?schema=public"
5358
```
5459

5560
and
5661

5762
`.env.test`
58-
```
63+
64+
```bash
5965
DATABASE_URL="postgres://dev:dev@postgres:5433/dev?schema=testing"
6066
```
6167

6268
**Note**: When creating a bison app, if you answered something else rather than `dev` when prompted, "What is the local test database
63-
name?" You will have to set the variable `testDabaseName` to `dev` in `test/jest.setup.js` file.
69+
name?" You will have to set the variable `testDatabaseName` to `dev` in `test/jest.setup.js` file.
6470

6571
Run the following command in your terminal:
66-
`docker-compose up -d`
72+
`docker-compose up -d`
6773

6874
To shut it down:
6975
`docker-compose down`
7076

7177
## Optional - Package.json
78+
7279
Add the following to your `package.json`
7380

7481
```json
7582
"scripts": {
7683
"docker:up": "docker-compose up -d",
77-
"docker:down" "docker-compose down"
84+
"docker:down": "docker-compose down"
7885
}
7986
```
8087

packages/create-bison-app/tasks/copyFiles.js

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ async function copyFiles({ variables, targetFolder }) {
7171
variables
7272
),
7373

74+
copyWithTemplate(
75+
fromPath("docker-compose.yml.ejs"),
76+
toPath("docker-compose.yml"),
77+
variables
78+
),
79+
7480
copyDirectoryWithTemplate(
7581
fromPath(".github"),
7682
toPath(".github"),

packages/create-bison-app/template/_.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,7 @@ yarn-error.log*
3838
/tests/e2e/temp/*.json
3939
/test-results/
4040
/playwright-report/
41-
/playwright/.cache/
41+
/playwright/.cache/
42+
43+
# data
44+
/.data
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3'
2+
services:
3+
db:
4+
container_name: <%= name %>-db
5+
image: 'postgres:14'
6+
volumes:
7+
- './.data/db:/var/lib/postgresql/data'
8+
restart: 'always'
9+
ports:
10+
- <%= db.dev.port %>:5432
11+
environment:
12+
POSTGRES_USER: <%= db.dev.user %>
13+
POSTGRES_DB: <%= db.dev.name %>
14+
<% if (db.dev.password) { -%>
15+
POSTGRES_PASSWORD: <%= db.dev.password %>
16+
<% } -%>
17+
TZ: 'Etc/UTC'

packages/create-bison-app/template/package.json.ejs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"db:setup": "yarn db:reset",
2020
"dev": "next dev",
2121
"dev:typecheck": "tsc --noEmit",
22+
"docker:up": "docker-compose up -d",
23+
"docker:down": "docker-compose down",
2224
"g:cell": "hygen cell new --name",
2325
"g:component": "hygen component new --name",
2426
"g:trpc": "hygen trpc new --name",

0 commit comments

Comments
 (0)