-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add docker-compose instructions for local postgres (#1599)
* ci(docker-compose): pin postgres version and expose port to host
- Loading branch information
Showing
2 changed files
with
73 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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. | ||
|
||
|
@@ -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`. | ||
|
@@ -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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters