Skip to content

Commit

Permalink
Add local deployment instructions
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Mar 14, 2019
1 parent 0cb1e89 commit 7181c0f
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 69 deletions.
117 changes: 48 additions & 69 deletions README.md
Expand Up @@ -35,75 +35,54 @@ Renders the leaderboard itself as a Vue.js app by Ken Fukuyama

## Schema

```sql
drop table activity cascade;
drop table users;

CREATE TABLE users (
user_id integer PRIMARY KEY NOT NULL,
user_login text NOT NULL,
track BOOLEAN NOT NULL,
created_at timestamp not null
);
insert into users (user_id,user_login,track, created_at) values (653013,'alexellisuk',true,now());
insert into users (user_id,user_login,track, created_at) values (103022,'rgee0',true,now());

CREATE TABLE activity (
id INT GENERATED ALWAYS AS IDENTITY,
user_id integer NOT NULL references users(user_id),
activity_type text NOT NULL,
activity_date timestamp NOT NULL,
owner text NOT NULL,
repo text NOT NULL
);

insert into activity (id,user_id,activity_type,activity_date,owner,repo) values (DEFAULT,653013,'issue_created','2019-02-13 07:44:00','openfaas','org-tester');
insert into activity (id,user_id,activity_type,activity_date,owner,repo) values (DEFAULT,653013,'issue_comment','2019-02-13 07:44:05','openfaas','org-tester');
insert into activity (id,user_id,activity_type,activity_date,owner,repo) values (DEFAULT,653013,'issue_comment','2019-02-12 07:44:05','openfaas','org-tester');
insert into activity (id,user_id,activity_type,activity_date,owner,repo) values (DEFAULT,103022,'issue_comment','2019-02-12 07:44:05','openfaas','org-tester');

select * from activity order by activity_date asc;

select a.user_id, a.activity_type, count(a.id) from activity as a
where a.activity_date <= now()
group by (a.user_id, a.activity_type) ;

drop function get_leaderboard;

CREATE or REPLACE FUNCTION get_leaderboard()
RETURNS TABLE(user_id integer, user_login text, issue_comments bigint, issues_created bigint)
AS
$$
BEGIN
RETURN QUERY select
a.user_id,
u.user_login,
count(ic.activity_type) as issue_comments,
count(cm.activity_type) as issues_created
from activity as a
inner join users u
on a.user_id = u.user_id
left outer join activity as ic
on a.user_id= ic.user_id
and a.activity_type = ic.activity_type
and a.activity_date = ic.activity_date
and a.owner = ic.owner
and a.repo = ic.repo
and ic.activity_type = 'issue_comment'
left outer join activity as cm
on a.user_id= cm.user_id
and a.activity_type = cm.activity_type
and a.activity_date = cm.activity_date
and a.owner = cm.owner
and a.repo = cm.repo
and cm.activity_type = 'issue_created'
where u.track = true
group by a.user_id, u.user_login
order by issue_comments desc, issues_created desc;
END
$$ LANGUAGE 'plpgsql' VOLATILE;

select * from get_leaderboard();
* [schema-1.0.sql](sql/schema-1.0.sql)

## Running locally

* Deploy OpenFaaS

* Grab the node8-express template

```
faas-cli template store pull node8-express
```

* Create the required secrets

```
export PASS=""
export USER=""
export HOST=""
export WEBHOOK="" # As set on the webhook page on GitHub
faas-cli secret create leaderboard-app-secrets \
--literal password="$PASS" \
--literal username="$USER" \
--literal host="$HOST" \
--literal webhook-secret="$WEBHOOK"
```

* Deploy the stack.yml file with a prefix

Either edit the stack.yml and add the prefix for each function or run:

```
leaderboard => alexellis-leaderboard
github-sub => alexellis-github-sub
leaderboard-page => alexellis-leaderboard-page
```

* Deploy `of-router`:

Do this with auth turned off

https://github.com/openfaas/openfaas-cloud/tree/master/router

* Create entries in: `/etc/hosts`

```
alexellis.local-o6s.io 127.0.0.1
```

## Contributing & license
Expand Down
69 changes: 69 additions & 0 deletions sql/schema-1.0.sql
@@ -0,0 +1,69 @@

drop table activity cascade;
drop table users;

CREATE TABLE users (
user_id integer PRIMARY KEY NOT NULL,
user_login text NOT NULL,
track BOOLEAN NOT NULL,
created_at timestamp not null
);
insert into users (user_id,user_login,track, created_at) values (653013,'alexellisuk',true,now());
insert into users (user_id,user_login,track, created_at) values (103022,'rgee0',true,now());

CREATE TABLE activity (
id INT GENERATED ALWAYS AS IDENTITY,
user_id integer NOT NULL references users(user_id),
activity_type text NOT NULL,
activity_date timestamp NOT NULL,
owner text NOT NULL,
repo text NOT NULL
);

insert into activity (id,user_id,activity_type,activity_date,owner,repo) values (DEFAULT,653013,'issue_created','2019-02-13 07:44:00','openfaas','org-tester');
insert into activity (id,user_id,activity_type,activity_date,owner,repo) values (DEFAULT,653013,'issue_comment','2019-02-13 07:44:05','openfaas','org-tester');
insert into activity (id,user_id,activity_type,activity_date,owner,repo) values (DEFAULT,653013,'issue_comment','2019-02-12 07:44:05','openfaas','org-tester');
insert into activity (id,user_id,activity_type,activity_date,owner,repo) values (DEFAULT,103022,'issue_comment','2019-02-12 07:44:05','openfaas','org-tester');

select * from activity order by activity_date asc;

select a.user_id, a.activity_type, count(a.id) from activity as a
where a.activity_date <= now()
group by (a.user_id, a.activity_type) ;

drop function get_leaderboard;

CREATE or REPLACE FUNCTION get_leaderboard()
RETURNS TABLE(user_id integer, user_login text, issue_comments bigint, issues_created bigint)
AS
$$
BEGIN
RETURN QUERY select
a.user_id,
u.user_login,
count(ic.activity_type) as issue_comments,
count(cm.activity_type) as issues_created
from activity as a
inner join users u
on a.user_id = u.user_id
left outer join activity as ic
on a.user_id= ic.user_id
and a.activity_type = ic.activity_type
and a.activity_date = ic.activity_date
and a.owner = ic.owner
and a.repo = ic.repo
and ic.activity_type = 'issue_comment'
left outer join activity as cm
on a.user_id= cm.user_id
and a.activity_type = cm.activity_type
and a.activity_date = cm.activity_date
and a.owner = cm.owner
and a.repo = cm.repo
and cm.activity_type = 'issue_created'
where u.track = true
group by a.user_id, u.user_login
order by issue_comments desc, issues_created desc;
END
$$ LANGUAGE 'plpgsql' VOLATILE;

select * from get_leaderboard();

0 comments on commit 7181c0f

Please sign in to comment.