Skip to content

Commit 36e88ae

Browse files
committed
add tutorial on how to run test db
1 parent 8160c43 commit 36e88ae

1 file changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
title: "How to set up local instance of BETY test database using Docker"
3+
author: "Kimberly Huynh"
4+
date: "4/19/2019"
5+
output: html_document
6+
---
7+
8+
# Overview
9+
10+
The purpose of this tutorial is to demonstrate how to set up a local instance of the BETY test database.
11+
12+
You will want to set up this test database when preparing to upload data to the master database.
13+
14+
You should make sure that your data can be succesfully uploaded to the test database before trying to upload to master.
15+
16+
# Requirements:
17+
18+
To run a local instance of the BETY test database, you will need to have the following installed on your computer:
19+
20+
* Docker
21+
22+
* PostgreSQL
23+
24+
## Install Docker
25+
26+
The BETY database will be run using Docker. You will be able to access the database by running docker `containers`.
27+
28+
Visit [https://www.docker.com/products/docker-desktop](https://www.docker.com/products/docker-desktop) to download Docker for MAC or Windows. You will need to create a docker account.
29+
30+
## Install PostgreSQL
31+
32+
After you have BETY running, you can connect to the database using the psql command line. You can run queries against the database using this tool.
33+
34+
Visit [https://www.postgresql.org/download/](https://www.postgresql.org/download/) to download PostgreSQL.
35+
36+
# How to set up and run BETY using docker
37+
38+
Note: You only need to run steps 1 (clone repo), 2 (create docker-compose.override.yml), and 3 (initialize BETY database) the first time you set up BETY.
39+
40+
After initial set up, you will only need to run step 4 to restart the database.
41+
42+
## Step 1: Clone bety repository
43+
44+
In a directory of your chioce, clone the bety repository from github and cd to the bety folder:
45+
46+
```sh
47+
git clone https://github.com/PecanProject/bety.git
48+
cd bety
49+
```
50+
51+
## Step 2: Create a `docker-compose.override.yml`
52+
53+
You will need to mount the postgres container to port 5433. This can be done by creating a `docker-compose.override.yml` file in the bety folder.
54+
55+
Copy and paste the following chunk into the file:
56+
57+
```sh
58+
version: "3"
59+
services:
60+
postgres:
61+
ports:
62+
- 5433:5432
63+
```
64+
65+
## Step 3: Initialize BETY database
66+
67+
Once you have set up the docker-compose.override.yml file, you should follow these next steps to initialize the database:
68+
69+
```sh
70+
# Start postgres
71+
docker-compose -p bety up -d postgres
72+
# Initialize BETY database
73+
docker run -ti --rm --network bety_bety -e BETY_INITIALIZE_URL='-w https://terraref.ncsa.illinois.edu/bety/dump/bety0/bety.tar.gz' pecan/bety:terra initialize
74+
# Sync with server 6 only
75+
docker run -ti --rm --network bety_bety -e REMOTE_SERVERS='6' pecan/bety:terra sync
76+
```
77+
78+
## Step 4: Bring up all containers
79+
80+
```sh
81+
# Bring up full stack
82+
docker-compose up
83+
```
84+
85+
You should see something like the following chunk with a cursor blinking on next line:
86+
87+
```sh
88+
Creating network "bety_bety" with the default driver
89+
Creating bety_postgres_1 ... done
90+
Creating bety_bety_1 ... done
91+
Attaching to bety_postgres_1, bety_bety_1
92+
postgres_1 | LOG: database system was interrupted; last known up at 2019-04-19 19:24:36 UTC
93+
bety_1 | Start running BETY (unicorn)
94+
postgres_1 | LOG: database system was not properly shut down; automatic recovery in progress
95+
postgres_1 | LOG: invalid record length at 9/261ACFF0
96+
postgres_1 | LOG: redo is not required
97+
postgres_1 | LOG: MultiXact member wraparound protections are now enabled
98+
postgres_1 | LOG: database system is ready to accept connections
99+
postgres_1 | LOG: autovacuum launcher started
100+
bety_1 | I, [2019-04-19T21:58:45.786271 #1] INFO -- : Refreshing Gem list
101+
bety_1 | I, [2019-04-19T21:58:51.121928 #1] INFO -- : listening on addr=0.0.0.0:8000 fd=8
102+
bety_1 | I, [2019-04-19T21:58:51.147507 #1] INFO -- : master process ready
103+
bety_1 | I, [2019-04-19T21:58:51.149629 #7] INFO -- : worker=0 ready
104+
```
105+
## Step 5: Connect to test database using psql command line
106+
Open a new tab in the terminal and connect to the test database using:
107+
```sh
108+
psql -h localhost -p 5433 -U bety
109+
```
110+
You should see the following prompt if you have succesfully logged into the test database:
111+
```sh
112+
psql (11.2, server 9.5.16)
113+
Type "help" for help.
114+
bety=>
115+
```
116+
## Step 6: Exit from psql command line and stop containers
117+
Once you are done working with the test database, exit the psql command line by typing `exit` following the `bety=>` prompt.
118+
```sh
119+
bety=> exit
120+
```
121+
To bring down all containers run:
122+
```sh
123+
docker-compose down
124+
```
125+
You should see the following output after running docker-compose down
126+
```sh
127+
Stopping bety_bety_1 ... done
128+
Stopping bety_postgres_1 ... done
129+
Removing bety_bety_1 ... done
130+
Removing bety_postgres_1 ... done
131+
Removing network bety_bety
132+
```

0 commit comments

Comments
 (0)