Skip to content

Commit

Permalink
feat: Add docker-compose.yml to the Bison template. (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
cullylarson committed Apr 10, 2023
1 parent 19d2e63 commit 5f732e0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
33 changes: 20 additions & 13 deletions docs/postgres.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# Run Postgres with Bison
# Run Postgres with Bison

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

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

Need help setting up Postgres locally?

#### Install Postgres on Mac
Mac: https://postgresapp.com/
## Install Postgres on Mac

#### Install Postgres on Windows
Windows: https://www.postgresql.org/download/windows/
Mac: <https://postgresapp.com/>

## Install Postgres on Windows

Windows: <https://www.postgresql.org/download/windows/>

## Run Postgres with Docker

Expand All @@ -40,41 +42,46 @@ services:
POSTGRES_PASSWORD: dev
POSTGRES_DB: dev
```

A different schema is created for your testing data.

Please note the ports to adjust your environment variables. See below for an example.
Please note the ports to adjust your environment variables. See below for an example.

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

#### Edit your environment variables:
### Edit your environment variables

Change the database URL in `.env.local`:
```

```bash
DATABASE_URL="postgres://dev:dev@postgres:5433/dev?schema=public"
```

and

`.env.test`
```

```bash
DATABASE_URL="postgres://dev:dev@postgres:5433/dev?schema=testing"
```

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

Run the following command in your terminal:
`docker-compose up -d`
`docker-compose up -d`

To shut it down:
`docker-compose down`

## Optional - Package.json

Add the following to your `package.json`

```json
"scripts": {
"docker:up": "docker-compose up -d",
"docker:down" "docker-compose down"
"docker:down": "docker-compose down"
}
```

Expand Down
6 changes: 6 additions & 0 deletions packages/create-bison-app/tasks/copyFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ async function copyFiles({ variables, targetFolder }) {
variables
),

copyWithTemplate(
fromPath("docker-compose.yml.ejs"),
toPath("docker-compose.yml"),
variables
),

copyDirectoryWithTemplate(
fromPath(".github"),
toPath(".github"),
Expand Down
5 changes: 4 additions & 1 deletion packages/create-bison-app/template/_.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ yarn-error.log*
/tests/e2e/temp/*.json
/test-results/
/playwright-report/
/playwright/.cache/
/playwright/.cache/

# data
/.data
17 changes: 17 additions & 0 deletions packages/create-bison-app/template/docker-compose.yml.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3'
services:
db:
container_name: <%= name %>-db
image: 'postgres:14'
volumes:
- './.data/db:/var/lib/postgresql/data'
restart: 'always'
ports:
- <%= db.dev.port %>:5432
environment:
POSTGRES_USER: <%= db.dev.user %>
POSTGRES_DB: <%= db.dev.name %>
<% if (db.dev.password) { -%>
POSTGRES_PASSWORD: <%= db.dev.password %>
<% } -%>
TZ: 'Etc/UTC'
2 changes: 2 additions & 0 deletions packages/create-bison-app/template/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"db:setup": "yarn db:reset",
"dev": "next dev",
"dev:typecheck": "tsc --noEmit",
"docker:up": "docker-compose up -d",
"docker:down": "docker-compose down",
"g:cell": "hygen cell new --name",
"g:component": "hygen component new --name",
"g:trpc": "hygen trpc new --name",
Expand Down

0 comments on commit 5f732e0

Please sign in to comment.