Skip to content

Commit 3bd10b7

Browse files
committed
Move all documentation to wiki folder
1 parent 8e4f6bd commit 3bd10b7

File tree

5 files changed

+229
-219
lines changed

5 files changed

+229
-219
lines changed

README.md

+5-219
Original file line numberDiff line numberDiff line change
@@ -10,232 +10,18 @@ It is hosted on:
1010

1111
- [api.interflux.com](https://api.interflux.com)
1212

13-
Build status:
14-
15-
| `master` | `production` |
16-
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17-
| [![Build status](https://badge.buildkite.com/feec3c1bb9d5fa10832931944a2af6a98fa4d2225c3b002045.svg?branch=master)](https://buildkite.com/nabu/api-dot-interflux-dot-com) | [![Build status](https://badge.buildkite.com/feec3c1bb9d5fa10832931944a2af6a98fa4d2225c3b002045.svg?branch=production)](https://buildkite.com/nabu/api-dot-interflux-dot-com) |
18-
1913
## Development
2014

21-
Setup on Mac:
22-
23-
```
24-
brew update
25-
brew install rbenv ruby-build
26-
```
27-
28-
Someone suggest to then add `rbenv` to path, but no need...
29-
30-
```
31-
set --universal fish_user_paths $fish_user_paths ~/.rbenv/shims
32-
```
33-
34-
Instead:
35-
36-
```
37-
rbenv init
38-
```
39-
40-
Suggest to add the following to Fish config:
41-
42-
```
43-
atom ~/.config/fish/config.fish
44-
status --is-interactive; and source (rbenv init -|psub)
45-
```
46-
```
47-
brew install postgresql
48-
brew services start postgresql
49-
```
50-
```
51-
git clone [email protected]:janwerkhoven/api.interflux.com.git
52-
cd api.interflux.com
53-
rbenv install -s
54-
rbenv rehash
55-
gem install bundler
56-
gem install rails
57-
bin/bundle install
58-
bin/rails db:drop;
59-
bin/rails db:create
60-
bin/rails db:migrate
61-
bin/rails db:environment:set RAILS_ENV=development;
62-
bin/rails db:create;
63-
bin/rails db:migrate;
64-
bin/rails db:fixtures:load;
65-
```
66-
67-
Fire up Rails:
68-
69-
```
70-
bin/rails s
71-
```
72-
73-
Access console:
74-
75-
```
76-
bin/rails c
77-
```
78-
79-
Seed database with fixtures:
80-
81-
```
82-
bin/rails db:fixtures:load FIXTURES=articles
83-
```
84-
85-
Generate custom scaffold for new resource:
86-
87-
```
88-
bin/rails generate custom_scaffold related_things --version=v1 --scope=admin
89-
```
90-
91-
Drop database and start over:
92-
93-
```
94-
bin/rails db:environment:set RAILS_ENV=development;
95-
bin/rails db:drop;
96-
bin/rails db:create;
97-
bin/rails db:migrate;
98-
bin/rails db:seed
99-
```
100-
101-
Create user:
102-
103-
```
104-
bin/rails c
105-
p = Person.create(first_name:'Jan', last_name:'Werkhoven')
106-
User.create(email:'[email protected]', password: '12345678', person_id: p.id)
107-
```
108-
109-
Test login:
110-
111-
```
112-
curl \
113-
-X POST \
114-
-H "Content-Type: application/vnd.api+json" \
115-
-d '{ "email": "[email protected]", "password": 12345678 }' \
116-
http://localhost:3000/v1/admin/auth/login
117-
118-
set token TOKEN
119-
120-
curl \
121-
-X GET \
122-
-H "Content-Type: application/vnd.api+json" \
123-
-H "Authorization: $token" \
124-
http://localhost:3000/v1/admin/leads
125-
```
126-
127-
Roll back a migration:
128-
129-
```
130-
bin/rails db:rollback STEP=1
131-
```
132-
133-
Sanity check:
134-
135-
```
136-
curl \
137-
-X GET \
138-
-H "Content-Type: application/vnd.api+json" \
139-
http://localhost:3000/sanity-check
140-
```
15+
Refer to `wiki/development.sh`.
14116

14217
## Production
14318

144-
Manual deploy to production (from local):
145-
146-
```
147-
./deploy.sh
148-
```
149-
150-
Control Puma:
151-
152-
```
153-
bin/pumactl -F config/puma/production.rb -T '12345' start
154-
bin/pumactl -F config/puma/production.rb -T '12345' stop
155-
bin/pumactl -F config/puma/production.rb -T '12345' phased-restart
156-
```
157-
158-
Access production console:
159-
160-
```
161-
bin/rails console production
162-
```
163-
164-
Seed production database with fixtures:
165-
166-
```
167-
export RAILS_ENV=production
168-
bin/rails db:seed
169-
```
170-
171-
Backup and drop production database:
172-
173-
```
174-
env RAILS_ENV=production rake db:data:dump
175-
[email protected]:/var/www/api.interflux.com/builds/feature/authentication/cd977ad/db/data.yml .
176-
```
177-
178-
```
179-
bin/rails db:data:dump
180-
bin/pumactl -F config/puma/production.rb -T '12345' stop
181-
export RAILS_ENV=production;
182-
export DISABLE_DATABASE_ENVIRONMENT_CHECK=1;
183-
bin/rails db:drop
184-
```
185-
186-
Health check:
187-
188-
```
189-
curl https://api.interflux.com/status
190-
```
191-
192-
This should return you a 200 with JSON payload. The API is down if it doesn't!
19+
Refer to `wiki/production.sh`.
19320

19421
## Testing
19522

196-
Test all:
197-
198-
```
199-
bin/rails t
200-
bin/rails test
201-
bin/rails test --verbose
202-
```
203-
204-
Test specific folder:
205-
206-
```
207-
bin/rails test test/integration/v1/public/*
208-
```
209-
210-
Test specific file:
211-
212-
```
213-
bin/rails test test/integration/v1/public/products_integration_test.rb
214-
```
215-
216-
Test specific test (add line number):
217-
218-
```
219-
bin/rails test test/integration/v1/public/products_integration_test.rb:22
220-
```
221-
222-
## Trouble shooting
223-
224-
`PG::ConnectionBad`
225-
226-
Check if Postgress is running.
227-
228-
`EADDRINUSE`
229-
230-
Port 3000 is already taken by another process. This is most likely a rogue Puma
231-
process that wasn't stopped properly. Find the process ID (pid) by running:
232-
233-
```
234-
sudo lsof -iTCP -sTCP:LISTEN -P
235-
```
23+
Refer to `wiki/testing.sh`.
23624

237-
Then kill the one listening to port 3000:
25+
## Postgress
23826

239-
```
240-
kill -9 [pid]
241-
```
27+
Refer to `wiki/postgres.sh`.

wiki/development.sh

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# ---------
2+
3+
# SETUP LOCAL (MAC)
4+
5+
brew update
6+
brew install rbenv ruby-build
7+
8+
# Someone suggest to then add `rbenv` to path, but no need...
9+
10+
set --universal fish_user_paths $fish_user_paths ~/.rbenv/shims
11+
12+
# Instead:
13+
14+
rbenv init
15+
16+
# Suggest to add the following to Fish config:
17+
18+
atom ~/.config/fish/config.fish
19+
status --is-interactive; and source (rbenv init -|psub)
20+
21+
# Install and start Postgres
22+
23+
brew install postgresql
24+
brew services start postgresql
25+
26+
# Clone repo
27+
28+
git clone [email protected]:janwerkhoven/api.interflux.com.git
29+
cd api.interflux.com
30+
31+
# Install Ruby and all gems
32+
33+
rbenv install -s
34+
rbenv rehash
35+
gem install bundler
36+
gem install rails
37+
bin/bundle install
38+
39+
# Fire up local database
40+
41+
bin/rails db:drop;
42+
bin/rails db:create
43+
bin/rails db:migrate
44+
bin/rails db:environment:set RAILS_ENV=development;
45+
bin/rails db:create;
46+
bin/rails db:migrate;
47+
48+
# Serve Rails
49+
50+
bin/rails s
51+
52+
# ---------
53+
54+
# COMMON COMMANDS
55+
56+
# Open Rails console
57+
58+
bin/rails c
59+
60+
# Generate common route-controller-model-serialiser-test scaffold
61+
62+
bin/rails generate custom_scaffold products --version=v1 --scope=public
63+
bin/rails generate custom_scaffold product_documents --version=v1 --scope=admin
64+
65+
# Seed database
66+
67+
bin/rails db:seed
68+
bin/rails db:seed:documents
69+
bin/rails db:seed:products
70+
71+
# Seed database with fixtures (outdated)
72+
73+
bin/rails db:fixtures:load FIXTURES=articles
74+
75+
# Drop database and start over
76+
77+
bin/rails db:environment:set RAILS_ENV=development;
78+
bin/rails db:drop;
79+
bin/rails db:create;
80+
bin/rails db:migrate;
81+
bin/rails db:seed
82+
83+
# Roll back a migration:
84+
85+
bin/rails db:rollback STEP=1
86+
87+
# Create authenticated user
88+
89+
bin/rails c
90+
p = Person.create(first_name:'Jan', last_name:'Werkhoven')
91+
User.create(email:'[email protected]', password: '12345678', person_id: p.id)
92+
93+
# Test user login
94+
95+
curl \
96+
-X POST \
97+
-H "Content-Type: application/vnd.api+json" \
98+
-d '{ "email": "[email protected]", "password": 12345678 }' \
99+
http://localhost:3000/v1/admin/auth/login
100+
101+
# Add auth token
102+
103+
curl \
104+
-X GET \
105+
-H "Content-Type: application/vnd.api+json" \
106+
-H "Authorization: $token" \
107+
http://localhost:3000/v1/admin/leads
108+
109+
# Sanity check:
110+
111+
curl \
112+
-X GET \
113+
-H "Content-Type: application/vnd.api+json" \
114+
http://localhost:3000/sanity-check
115+
116+
# ---------

wiki/postgres.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# ---------
2+
3+
# MAC
4+
5+
# Install
6+
brew install postgresql
7+
8+
# Manage
9+
brew services start postgresql
10+
brew services restart postgresql
11+
brew services stop postgresql
12+
13+
# List all brew services
14+
brew services list
15+
16+
# List all databases on your device
17+
psql --list
18+
19+
# ---------
20+
21+
# DEBIAN
22+
23+
# TODO
24+
25+
# ---------
26+
27+
# TROUBLE SHOOTING
28+
29+
# PG::ConnectionBad`
30+
# EADDRINUSE
31+
32+
# Check if Postgres is running.
33+
# Port 3000 is already taken by another process. This is most likely a rogue Puma
34+
# process that wasn't stopped properly. Find the process ID (pid) by running:
35+
36+
sudo lsof -iTCP -sTCP:LISTEN -P
37+
38+
# Then kill the one listening to port 3000
39+
40+
kill -9 [pid]
41+
42+
# ---------

0 commit comments

Comments
 (0)