Skip to content

Commit

Permalink
chore: add docker-compose instructions for local postgres (#1599)
Browse files Browse the repository at this point in the history
* ci(docker-compose): pin postgres version and expose port to host
  • Loading branch information
lediur authored Sep 12, 2023
1 parent d8428e3 commit fdc0793
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 27 deletions.
87 changes: 70 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ Runtimes and package managers:
External services:

- Postgres (>= 11)
- [Install](https://postgresql.org/download) and [start](https://www.postgresql.org/docs/current/server-start.html) documentation

Recommended:

- Docker, for running Postgres as a container
- [install documentation](https://docs.docker.com/engine/install/)

### Setting up a development environment

Install Node and Yarn. We recommend using the [asdf version manager](https://github.com/asdf-vm/asdf).
#### Install Node and Yarn

We recommend using the [asdf version manager](https://github.com/asdf-vm/asdf).

```sh
# Example using `asdf` (https://github.com/asdf-vm/asdf)
Expand All @@ -42,21 +48,66 @@ You can also install the prereqs manually:
- [Node install documentation](https://nodejs.dev/learn/how-to-install-nodejs)
- [Yarn install documentation](https://classic.yarnpkg.com/en/docs/install)

Clone the repo:
#### Install and run a Postgres server

If you have Docker installed, we recommend using Postgres as a container.

Spoke Rewired comes with a `postgres` container in `docker-compose.yml`, which you can start with the following command:

```sh
# Run in the foreground, so you can watch logs and stop with Ctrl-C
docker compose up postgres

# Run in the background so you can use the terminal for other things
docker compose up postgres -d

# (if you have an older version of Docker installed, you may have to run
# "docker-compose" with a hyphen instead of "docker compose" with a space)
```

The `postgres` container will automatically start up a server with the following configuration:

- connection string (for `DATABASE_URL`): `postgres://spoke:spoke@localhost:15432/spokedev`
- port: 15432
- default database: `spokedev`
- user: `spoke`
- password: `spoke`

To stop all containers, including Postgres, run:

```sh
docker compose down
```

To delete all container data, including the Postgres database, and stop all containers, run:

```sh
docker compose down -v
```

After the database container is taken down, you can run the `up` commands above to restart it. For more information, see [the Docker Compose reference documentation](https://docs.docker.com/compose/reference/).

You can also install and run a Postgres server manually without Docker:

- Postgres [Install](https://postgresql.org/download) and [start](https://www.postgresql.org/docs/current/server-start.html) documentation

#### Clone the repo

```sh
git clone [email protected]:politics-rewired/Spoke.git
cd Spoke
git config --local blame.ignoreRevsFile .git-blame-ignore-revs
```

Install Node dependencies:
#### Install Node dependencies

```sh
yarn install
```

Copy the example environment. You will need to update the database connection
#### Copy the example environment

You will need to update the database connection
string: it should contain the correct host, port, and username/password
credentials to your development Postgres server.

Expand All @@ -68,39 +119,31 @@ vi .env
# DATABASE_URL=postgres://spoke:spoke@localhost:5432/spokedev
```

Create the `spokedev` database (if it doesn't yet exist)
#### Create the `spokedev` database (if it doesn't yet exist)

```sh
psql -c "create database spokedev;"
```

Run the migrations:
#### Run the migrations

```sh
yarn migrate:worker
yarn knex migrate:latest
```

Run codegen:
#### Run codegen

```sh
yarn codegen
```

Run in development mode:
#### Start the Spoke application in develpoment mode

```sh
yarn dev
```

If you plan to build container images locally for use in production you may want to set the default architecture by adding the following to your shell config (e.g. `~/.bash_profile`):

```sh
export DOCKER_DEFAULT_PLATFORM=linux/amd64
```

or pass `--platform=linux/amd64` to all `docker buildx` commands.

### SMS

For development, you can set `DEFAULT_SERVICE=fakeservice` to skip using an SMS provider (Assemble Switchboard or Twilio) and insert the message directly into the database. This is set by default in `.env`.
Expand Down Expand Up @@ -174,6 +217,16 @@ yarn release --prerelease
yarn release --prerelease alpha
```

## Building container images locally

If you plan to build container images locally for use in production you may want to set the default architecture by adding the following to your shell config (e.g. `~/.bash_profile`):

```sh
export DOCKER_DEFAULT_PLATFORM=linux/amd64
```

or pass `--platform=linux/amd64` to all `docker buildx` commands.

## Deploying

Spoke can be deployed in a variety of different ways. We use Kubernetes internally and are only currently maintaining the Docker image. See the [developer documentation](./docs) for more information about other deployment methods.
Expand Down
13 changes: 3 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
version: '3'
services:
postgres:
image: postgres
image: postgres:15
restart: always
environment:
POSTGRES_DB: spokedev
POSTGRES_PASSWORD: spoke
POSTGRES_USER: spoke
volumes:
- postgres:/var/lib/postgresql/data
redis:
image: redis
restart: always
volumes:
- redis:/data
ports:
- 15432:5432
app:
build:
context: .
args:
SPOKE_VERSION: 1.4.1
depends_on:
- postgres
- redis
env_file:
- ./.env
environment:
DATABASE_URL: postgres://spoke:spoke@postgres:5432/spokedev
REDIS_URL: redis://redis:6379
image: spoke
ports:
- 3000:3000
Expand All @@ -35,5 +30,3 @@ services:
volumes:
postgres:
external: false
redis:
external: false

0 comments on commit fdc0793

Please sign in to comment.