Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit d657e2b

Browse files
authored
Merge pull request #1 from mlh-henry/glitch
🙄📺 Updated with Glitch, fixed extracting problem
2 parents 58e8e73 + 5478151 commit d657e2b

File tree

13 files changed

+669
-59
lines changed

13 files changed

+669
-59
lines changed

.bash_profile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

.cockroachsql_history

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
_HiStOrY_V2_
2+
SET\040sql_safe_updates\040=\040false;
3+
UPDATE\040startrek.quotes\040SET\040characters\040=\040'your_name_here';
4+
\134q

.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.glitch-assets

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{"name":"drag-in-files.svg","date":"2016-10-22T16:17:49.954Z","url":"https://cdn.hyperdev.com/drag-in-files.svg","type":"image/svg","size":7646,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/drag-in-files.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(102, 153, 205)","uuid":"adSBq97hhhpFNUna"}
2+
{"name":"click-me.svg","date":"2016-10-23T16:17:49.954Z","url":"https://cdn.hyperdev.com/click-me.svg","type":"image/svg","size":7116,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/click-me.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(243, 185, 186)","uuid":"adSBq97hhhpFNUnb"}
3+
{"name":"paste-me.svg","date":"2016-10-24T16:17:49.954Z","url":"https://cdn.hyperdev.com/paste-me.svg","type":"image/svg","size":7242,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/paste-me.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(42, 179, 185)","uuid":"adSBq97hhhpFNUnc"}
4+
{"uuid":"adSBq97hhhpFNUna","deleted":true}
5+
{"uuid":"adSBq97hhhpFNUnb","deleted":true}
6+
{"uuid":"adSBq97hhhpFNUnc","deleted":true}

README.md

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,64 @@
1-
# MLH Localhost: Building Scalable Apps w/ CockroachDB
1+
Startrek Quotes with CockroachDB
2+
================================
23

3-
This repositiory contains the sample code from the [MLH Localhost: Hacking
4-
with CockroachDB][3] workshop.
4+
Quotes are queried from CockroachDB and displayed every few seconds.
5+
![preview](https://i.imgur.com/TiGjKH8.png)
56

6-
## Sample Code / Downloads
7+
Project on Glitch
8+
=================
79

8-
- Star Trek App - [Demo][4] / [Source][1] / [Download][2]
10+
Project can be found on Glitch at [https://checker-aries.glitch.me/](https://checker-aries.glitch.me)
911

10-
## License
12+
Troubleshooting
13+
===============
1114

12-
Unless otherwise stated, the code in this repo is released under the MIT
13-
License.
15+
**Note:** if you open a Glitch console and `cockroach` is installed, the `cockroach` command will still not be found until you run `alias cockroach="~/.data/cockroach"`
16+
17+
### Troubleshooting `BRB! Connecting to CockroachDB`
18+
19+
This happens occassionally when the project has been running for a while. It may go to sleep. Simply reload the page and wait a few minutes while the project wakes up and restarts the DB process.
20+
21+
If the app is really unresponsive, you may also go into the Glitch Console and type `sh cockroach.sh` to run the cockroachDB process manually. Hit `enter` to execute the DB process. You should see a bunch of output on the Glitch console.
22+
23+
### App is still not responding and `EADDRINUSE :::3000` appears in the Glitch Log
24+
25+
You have no choice but to kill the server.js process in the Glitch Console.
26+
![error](https://i.imgur.com/nzQsauv.png)
27+
28+
* Go to the Glitch Console
29+
* Type `ps -ax` to see a list of all running processes.
30+
* Find the process `node server.js` and note the PID.
31+
* Finally, kill that process by running `kill [PID]`
32+
33+
![kill](https://i.imgur.com/0u8U6qS.png)
34+
35+
Don't worry about restarting the node server.js as Glitch will do this automatically. You may return to your project on Glitch IDE and check the log to ensure you have no issues.
36+
37+
### Error: `bash: cockroach: command not found`
38+
39+
If you attempt to enter one of the commands beginning with `cockroach` and get the error above, enter this in your terminal:
40+
41+
`alias cockroach="~/.data/cockroach"` then
42+
43+
`cockroach version`. If you see this:
1444

1545
```
16-
Copyright (c) 2017 Major League Hacking, Inc.
17-
18-
Permission is hereby granted, free of charge, to any person obtaining a copy
19-
of this software and associated documentation files (the "Software"), to deal
20-
in the Software without restriction, including without limitation the rights
21-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22-
copies of the Software, and to permit persons to whom the Software is
23-
furnished to do so, subject to the following conditions:
24-
25-
The above copyright notice and this permission notice shall be included in all
26-
copies or substantial portions of the Software.
27-
28-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34-
SOFTWARE
46+
Build Tag: v2.0.3
47+
Build Time: 2018/06/18 16:11:33
48+
Distribution: CCL
49+
Platform: linux amd64 (x86_64-unknown-linux-gnu)
50+
Go Version: go1.10
51+
C Compiler: gcc 6.3.0
52+
Build SHA-1: 91715a9a95edbe716912173204fa4c0fc6724457
53+
Build Type: release
3554
```
36-
[1]: https://github.com/MLH/mlh-localhost-cockroachdb
37-
[2]: https://github.com/MLH/mlh-localhost-cockroachdb/archive/master.zip
38-
[3]: https://localhost.mlh.io/activities/intro-to-cockroachdb/
39-
[4]: http://mlhlocal.host/cockroachdb-demo
55+
56+
you have fixed the error.
57+
58+
### See CockroachDB information instead of the app
59+
60+
If someone sees information about `cockroachdb` instead of the quotes interface, they probably started the database incorrectly somehow. Quit the database using `cockroach quit --insecure --port=26257` (or whatever port number is required) and start it again.
61+
62+
### Running out of space
63+
64+
This only occured once during testing, but sometimes CockroachDB can run out of space on Glitch. In this case, remove the files `cockroach-data`, `mlh-node1` and `mlh-node2`. Then restart and refill the databases.

db.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Connect to the startrek Database on a node in our CockroachDB cluster
22
var pg = require('pg');
3-
var config = { user: 'root', database: 'startrek', port: 26257 };
3+
var config = { user: 'root', database: 'startrek', port: 26257 }; //26257
44
var db = new pg.Pool(config);
55

66
// Log when we connect to the CockroachDB node

install_cockroachdb.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
### These lines implement the basic cockraochdb install
3+
### https://www.cockroachlabs.com/docs/build-a-nodejs-app-with-cockroachdb.html
4+
cd ~/.data
5+
6+
# Download and extract the latest binary
7+
if [ ! -f ~/.data/cockroach ]; then
8+
echo "Installing CockroachDB"
9+
wget -N https://binaries.cockroachdb.com/cockroach-latest.linux-amd64.tgz
10+
tar xvf cockroach-latest.linux-amd64.tgz --transform 's!^[^/]\+\($\|/\)!cockroach-latest.linux-amd64\1!'
11+
mv ~/.data/cockroach-latest.linux-amd64/cockroach ~/.data
12+
rm cockroach-latest.linux-amd64.tgz
13+
rm -rf ./cockroach-latest.linux-amd64
14+
rm -rf .wget-hsts
15+
16+
# Instead of following instrutions and copying cockroach to /usr/bin,
17+
# Let's set up an alias. This avoids needing to escalation permissions.
18+
echo 'alias cockroach="~/.data/cockroach"' >> ~/.bash_profile
19+
source ~/.bash_profile
20+
else
21+
echo "CockroachDB is already installed"
22+
fi

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "mlh-localhost-cockroach",
33
"version": "0.0.1",
44
"description": "The sample app to accompany the MLH Localhost: Building Scalable Apps with CockroachDB Workshop.",
5-
"main": "server.js",
65
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
6+
"test": "echo \"Error: no test specified\" && exit 1",
7+
"start": "node server.js"
88
},
99
"repository": {
1010
"type": "git",
@@ -23,7 +23,7 @@
2323
},
2424
"homepage": "https://github.com/MLH/mlh-localhost-cockroachdb#readme",
2525
"dependencies": {
26-
"express": "^4.15.3",
27-
"pg": "^6.2.2"
26+
"express": "^4.16.3",
27+
"pg": "^7.4.3"
2828
}
29-
}
29+
}

public/js/jquery.min.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

run_cockroach.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
### This file handles the cockroachdb provisioning and configuration.
2+
### We'll rerun it continuously, so try to keep its items idempotent and speedy-enough.
3+
4+
5+
sh ~/install_cockroachdb.sh
6+
7+
# setup an alias for easy command execution
8+
alias cockroach="~/.data/cockroach"
9+
10+
# remove the preexisting environment so that we run fresh.
11+
# (this deletes all the DB data, so we can repeat our assorted creation scripts.)
12+
cockroach quit --insecure
13+
rm -rf hello*
14+
15+
### Now, onward to start up the cluster!
16+
### https://www.cockroachlabs.com/docs/build-a-nodejs-app-with-cockroachdb.html
17+
18+
19+
# Start node 1:
20+
cockroach start --insecure \
21+
--store=hello-1 \
22+
--host=localhost \
23+
--background
24+
25+
# Start node 2:
26+
cockroach start --insecure \
27+
--store=mlh-node2 \
28+
--host=localhost \
29+
--port=26258 \
30+
--http-port=8081 \
31+
--join=localhost:26257 \
32+
--background
33+
34+
# # Start node 3:
35+
# cockroach start --insecure \
36+
# --store=mlh-node3 \
37+
# --host=localhost \
38+
# --port=26259 \
39+
# --http-port=8082 \
40+
# --join=localhost:26257 \
41+
# --background
42+
43+
44+
# Create a user (optional for this exercise)
45+
# cockroach user set maxroach --insecure
46+
47+
# Create DB and priviledges
48+
cockroach gen example-data startrek | cockroach sql --insecure
49+
50+
# Check on the nodes
51+
cockroach node ls --insecure
52+
53+
# Glitch will run this script in a loop,
54+
# so sleep for a bit to stablize the refresh rate of the site.
55+
# This could be upgraded by monitoring the cockroach processes instead.
56+
sleep 1m

0 commit comments

Comments
 (0)