Skip to content

Commit d543105

Browse files
nathansgithubtcaddy
authored andcommitted
Changed Postgres to run in a Docker container
1 parent 15c819e commit d543105

File tree

5 files changed

+24
-40
lines changed

5 files changed

+24
-40
lines changed

.github/CONTRIBUTING.md

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,7 @@ To stop the project run `docker-compose stop`
5959

6060
- Mac/Linux use [Node Version Manager](https://github.com/creationix/nvm)
6161
- Windows see [here](https://nodejs.org/en/download/)
62-
63-
1. Install Postgresql
64-
65-
- Postgresql is a database system. This app uses Postgesql to store voter data. When running the app using Node, you have to have a local Postgresql database that will get loaded with the voter data.
66-
- MAC: the easist way to install Postgresql is with homebrew using the command below. It can also be downloaded from <https://www.postgresql.org/download/,> however, you will need to change your PATH.
67-
68-
```sh
69-
brew install postgresql
70-
```
71-
72-
- Windows: Postgresql downloads can be found here: https://www.postgresql.org/download/
73-
- use the "Interactive Installer by Enterprise DB" after selecting your OS
74-
- Note that the default user "postgres" and database "postgres" is assumed for this project. If you provided a password for postgres during the installation, you need to provide the password in DB_PASS in the next step. If you are comfortable with postgresql and want to create your out database/user/table, feel free to do so, just be sure the make the appropriate changes in the net step.
75-
62+
7663
1. Create a file called `.env` in the root of the project. The file should contain the following:
7764

7865
```sh
@@ -83,24 +70,22 @@ To stop the project run `docker-compose stop`
8370

8471
1. Open a terminal session at the root of your project and perform the following to initialize and start the application:
8572

86-
1. Start the postgresql database and load voter data to it:
87-
88-
Windows
73+
1. Update your application with all the required node modules. Normally, this only needs to be one time.
8974

9075
```sh
91-
npm run loadDataWin
76+
npm install
9277
```
9378

94-
Mac
79+
1. Start the postgresql database and load voter data to it:
9580

9681
```sh
97-
npm run loadDataMac
82+
npm run load-data
9883
```
9984

100-
1. Update your application with all the required node modules. Normally, this only needs to be one time.
85+
If your data is already loaded and you just want to run the database, run the command:
10186

10287
```sh
103-
npm install
88+
npm run db
10489
```
10590

10691
1. Start the application
@@ -117,18 +102,10 @@ To stop the project run `docker-compose stop`
117102
Ctrl+c
118103
```
119104

120-
1. To stop the database server, from a terminal session at the root of the project
121-
122-
Windows
123-
124-
```sh
125-
pg_ctl -D "C:\Program Files\PostgreSQL\11\data" stop
126-
```
127-
128-
Mac
105+
1. To stop the database server, from a terminal session at the root of the project:
129106

130107
```sh
131-
pg_ctl -D /usr/local/var/postgres stop
108+
docker-compose stop db
132109
```
133110

134111
### Project Details
@@ -179,8 +156,8 @@ Follow the [Issue template](./ISSUE_TEMPLATE.md) and be sure to include as much
179156
## Deploying your code
180157
Our code is deployed to Heroku to be served to the public. This happens in three stages:
181158
1. **build**&mdash;Heroku will automatically run `npm install` and cache the project's depedencies. Next, Heroku looks for a `build` task in the root `package.json` file. We use this step to build our React project, which optimizes our React code to be served statically.
182-
2. **run**&mdash;Heroku runs the `web` task in the `Procfile`, which simply starts our thin Express server to handle incoming requests and serve our compiled React app.
183-
3. **release**&mdash;Heroku runs the `release` task in the Procfile after deploying the application. Note that this task runs in a separate dyno (Heroku's term for a compute instance), so it will not have access to files from other parts of the build process. In our case, we ensure the database has the correct tables and the data is properly loaded.
159+
1. **run**&mdash;Heroku runs the `web` task in the `Procfile`, which simply starts our thin Express server to handle incoming requests and serve our compiled React app.
160+
1. **release**&mdash;Heroku runs the `release` task in the Procfile after deploying the application. Note that this task runs in a separate dyno (Heroku's term for a compute instance), so it will not have access to files from other parts of the build process. In our case, we ensure the database has the correct tables and the data is properly loaded.
184161
185162
When you merge your PR, it will be merged into the project's `dev` branch which will automatically kick off a deploy to our [staging server](https://dev-govote-api.herokuapp.com/). After you have merged your code, please test your changes and other basic flows (including finding your polling place and someone's voter registration) on the staging server.
186163

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ yarn-debug.log*
66
yarn-error.log*
77

88
bin/tmp/*
9+
server/bin/tmp/*
910

1011
# Runtime data
1112
postgres-data/*
@@ -67,7 +68,7 @@ typings/
6768
# IDEs/Editors
6869
*.swp
6970
*.swo
70-
.idea/
71+
.idea
7172

7273
# Elastic Beanstalk Files
7374
.elasticbeanstalk/*

docker-compose.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3'
22
services:
33
db:
4-
image: postgres:10.3
4+
image: postgres
55
environment:
66
- "POSTGRES_USER=${DB_USER}"
77
- "POSTGRES_PASSWORD=${DB_PASS}"
@@ -10,6 +10,8 @@ services:
1010
- 9001:5432
1111
expose:
1212
- "5432"
13+
volumes:
14+
- postgres-data:/var/lib/postgresql/data
1315
govote-server:
1416
build: './server'
1517
container_name: govote-server
@@ -37,4 +39,7 @@ services:
3739
- '/usr/src/app/node_modules'
3840
environment:
3941
- API_PROXY=http://govote-server:3001
40-
env_file: ./.env
42+
env_file: ./.env
43+
44+
volumes:
45+
postgres-data:

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "govote",
33
"version": "0.0.1",
44
"engines": {
5-
"node": "13.13.x"
5+
"node": "16.x.x"
66
},
77
"private": true,
88
"dependencies": {
@@ -18,8 +18,8 @@
1818
"build": "cd client && npm install && react-scripts build",
1919
"docker:create-tables": "docker-compose exec govote-server node ./bin/create-tables.js",
2020
"docker:etl": "docker-compose exec govote-server node ./bin/etl.js",
21-
"loadDataMac": "pg_ctl -D /usr/local/var/postgres stop ; pg_ctl -D /usr/local/var/postgres start && node ./server/bin/create-tables.js manual && node ./server/bin/etl.js manual",
22-
"loadDataWin": "(pg_ctl -D \"C:/Program Files/PostgreSQL/11/data/\" stop || true ) && pg_ctl -D \"C:/Program Files/PostgreSQL/11/data\" start && node ./server/bin/create-tables.js manual && node ./server/bin/etl.js manual"
21+
"db": "docker-compose up -d db",
22+
"load-data": "npm run db && node ./server/bin/create-tables.js manual && node ./server/bin/etl.js manual"
2323
},
2424
"devDependencies": {
2525
"concurrently": "^5.3.0"

sample.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ DB_PASS=govotepassword
77
DB_PORT=5432
88
VOTER_URL=https://dl.ncsbe.gov/data/ncvoter41.zip
99
POLLING_PLACE_URL=https://s3.amazonaws.com/dl.ncsbe.gov/ENRS/2020_03_03/polling_place_20200303.csv
10+
REACT_APP_GOOGLEMAPAPIKEY=

0 commit comments

Comments
 (0)