Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerise #194

Draft
wants to merge 54 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
adff3d3
Add docker container
Feb 25, 2021
dba6f65
move config to use environments
Mar 1, 2021
8bcb5b8
removed wait for script
Mar 1, 2021
5fe85a8
Create test.yml
upendra243 Mar 2, 2021
a09bd35
added docker command
upendra243 Mar 2, 2021
238cd1c
Merge pull request #1 from upendra243/dockerize
upendra243 Mar 2, 2021
0e52447
Create .env
upendra243 Mar 2, 2021
1eb89ca
added a test service in docker compose
Mar 2, 2021
7e436c5
Update test.yml
upendra243 Mar 2, 2021
3e7cb9a
Merge pull request #2 from upendra243/dockerize
upendra243 Mar 2, 2021
b363f66
Update .env
upendra243 Mar 3, 2021
35ca0d7
updated docker to use ubuntu
Mar 3, 2021
e7978ed
Create config.json
upendra243 Mar 3, 2021
812193c
Update test.yml
upendra243 Mar 3, 2021
9347383
add new compose file for test
Mar 3, 2021
8378dbb
Merge branch 'master' of github.com:upendra243/hackdash
Mar 3, 2021
aa1334e
Update test.yml
upendra243 Mar 3, 2021
7825688
Update .github/workflows/test.yml
jbothma Mar 4, 2021
3770470
Update .github/workflows/test.yml
jbothma Mar 4, 2021
ca69d40
Merge pull request #1 from upendra243/master
jbothma Mar 4, 2021
c4b6df7
Clean up test run by using dev docker-compose.yml and explicit command
jbothma Mar 4, 2021
a9f5117
Merge pull request #2 from OpenUpSA/clean-up-test-rn
jbothma Mar 4, 2021
c2da9fa
Merge pull request #3 from OpenUpSA/master
upendra243 Mar 4, 2021
ba17a8a
Update test.yml
upendra243 Mar 5, 2021
b772af8
Update test.yml
upendra243 Mar 5, 2021
4dea6c5
removed make file
Mar 5, 2021
5310334
resolved pull messages
Mar 5, 2021
c6b9157
Updated ReadMe
Mar 5, 2021
25b2514
typo
Mar 5, 2021
a134f40
Merge pull request #3 from upendra243/master
jbothma Mar 5, 2021
08116ee
Switch to passport-github2 to handle github API updates
jbothma May 27, 2021
ceeb8ea
Don't run as root
jbothma May 27, 2021
dc1d775
Add support for localhost hostname (fix assumption of dots in hostname)
jbothma May 27, 2021
709f873
Run metrics in docker-compose because login needs it
jbothma May 27, 2021
7cd8a5c
clean up .env file
jbothma May 27, 2021
aca8545
Fix test
jbothma May 27, 2021
6f2915d
Remove dependency on .env file
jbothma May 27, 2021
8cf91eb
Bump node to 14
jbothma Apr 7, 2022
8110c53
Add fake fallback github client id for something that assumed it'd be…
jbothma Apr 7, 2022
4a9b726
Install test dev deps incl testing tools in CI
jbothma Apr 7, 2022
8eef635
Small improvements
jbothma Apr 7, 2022
e893ad4
Merge pull request #4 from OpenUpSA/node-14
jbothma Apr 7, 2022
ed8c6af
Don't set cookie domain when there's just one component
jbothma Apr 7, 2022
10519fb
don't use nodemon in prod
jbothma Jun 16, 2022
43e5072
Add project code to image
jbothma Jun 16, 2022
808c406
Fix path
jbothma Jun 16, 2022
45fb309
Add Profile for metrics run command
jbothma Jun 17, 2022
4fce5c0
Intro dev and deployment with docker
jbothma Jun 17, 2022
25c8c0d
Document environment variables more clearly
jbothma Jun 17, 2022
5cef1b5
Docs fixes
jbothma Jun 17, 2022
905cf69
document auth options
jbothma Jun 17, 2022
abbaa35
Merge pull request #13 from OpenUpSA/docs
jbothma Jun 17, 2022
513ecc1
Remove console log statements
jbothma Jun 17, 2022
6f67264
Merge branch 'impronunciable:master' into master
jbothma Jun 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gitignore
.env
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Test

on:
push:
pull_request:

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install test dependencies
run: docker-compose run --rm app npm install --also=dev

- name: Run tests
run: docker-compose run --rm app npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ npm-debug.log
public/styles/app.css
public/styles/embed.css
public/styles/landing.css
.env
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM ubuntu:latest

ENV NODE_PATH=.
ENV NODE_ENV production

RUN apt-get update; \
apt-get -y install curl gnupg; \
curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get -y install nodejs

COPY . /app
WORKDIR /app

RUN set -ex; \
npm install -g; \
cd metrics; \
npm install -g

ARG USER_ID=1001
ARG GROUP_ID=1001

RUN set -ex; \
addgroup --gid $GROUP_ID --system containeruser; \
adduser --system --uid $USER_ID --gid $GROUP_ID containeruser; \
chown -R containeruser:containeruser /app

USER containeruser

CMD node index.js
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: node index.js
metrics: ./start_metrics.sh
79 changes: 59 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,69 @@ Organize hackaton ideas into a dashboard
Install
===========

I wrote a [blog post](http://zajdband.com/installing-hackdash) explaining the installation process. Also check the [wiki](https://github.com/danzajdband/hackdash/wiki) for more info and docs
Hackdash can now be run in a docker container - see an example [dokku app configuration using ansible](https://github.com/OpenUpSA/ansible-config/tree/master/apps/hackdash).

Alternatively, see a [blog post](http://zajdband.com/installing-hackdash) explaining the installation process to run it natively. Also check the [wiki](https://github.com/danzajdband/hackdash/wiki) for more info and docs

Development enviroment
----------------------

The quickest way to set up a local development environment is using docker-compose to manage the environment by running

docker-compose up

If you prefer to run it natively, refer to the blog post above, the config documentation below, and then run

yarn start

Once the images have been pulled/built and started, you should be able to visit it at http://localhost:3000 and see the prompt to create a new dashboard. Once you click in the dashboard name input, it will try and fail to prompt you to login.

To be able to login, create a `.env` file in the project root with the following config:

GITHUB_CLIENT_ID=
GITHUB_SECRET_KEY=
GITHUB_CALLBACK_URL=http://localhost:3000/auth/github/callback

For the values of CLIENT_ID and SECRET_KEY, [create a Github OAuth app](https://docs.github.com/en/developers/apps/building-oauth-apps/creating-an-oauth-app) with the above callback URL, and enter the ID and key values in the .ev file.

To apply the new environment variables to the running docker containers, stop them all and run `docker-compose up` again, or while they're running, run `docker-compose up -d` in another terminal.

You should now be able to login using your own github account via OAuth, and get redirected back to your local hackdash instance with a logged-in session. You can now create a dashboard and a project.


Config
======

In your `config.json`:

* `db`:
+ `url`: Overrides other db config. Full MongoDB URL.
+ `host`
+ `port`
* `host`: Your instance host (i.e. yourdomain.com)
* `port`: Your port (i.e. 3000)
* `session`: Your session key (it must be a secret string)
* `title`: Instance title used in the html title tag and other headings.
* `live`: Boolean (true, false) that enable/disable the live feed feature in yourdomain.com/live.
* `mailer`: SMTP mail info to enable email notifications using nodemailer. Check out the [options](https://github.com/andris9/Nodemailer#setting-up-smtp)
* `team`: An array of `user`.`_id` to be shown as Team on Landing Page.
* `maxQueryLimit`: a Number for the max amount of results at the landing page searchs.
* `googleAnalytics`: the UA-XXXXXXXX-X code from Google Analytics. if not specified wont set the script.
* `facebookAppId`: the Facebook App Id for share buttons. It will take first from keys.json, if not will use this one. Don't set it to not show FB share buttons.
* `prerender`:
+ `enabled`: Boolean (true, false). Where the website would use the SEO Prerender
+ `db`: The Mongo URI of Cached Pages.
Configure by setting environment variables, setting values in a `.env` file, or by modifying `config.js`.

| Environment variable or .env key | config.js key | Required | Default | Description |
|----------------------------------|---------------|----------|---------|-------------|
| `DATABASE_URL` | `db.url` | Yes | | Overrides other db config. Full MongoDB URL. |
| `DB_HOST` | `db.host` | If DATABASE_URL not provided | | |
| `DB_PORT` | `db.port` | If DATABASE_URL not provided | | |
| `HOST` | `host` | Yes | | Your instance host (i.e. yourdomain.com) |
| `PORT` | `port` | No | $PORT or 3000 | Your port (i.e. 3000) |
| `SESSION` | `session` | Yes | | Your session key (it must be a secret string) |
| `TITLE` | `title`: Instance title used in the html title tag and other headings. |
| `LIVE` | `live` | No | true | Boolean (true, false) that enable/disable the live feed feature in yourdomain.com/live.
| `MAILER` | `mailer` | No | `null` | SMTP mail info to enable email notifications using nodemailer. Check out the [options](https://github.com/andris9/Nodemailer#setting-up-smtp) |
| | `team` | No | ? | An array of `user`.`_id` to be shown as Team on Landing Page. |
| `MAX_QUERY_LIMIT` | `maxQueryLimit` | No | 30 | a Number for the max amount of results at the landing page searchs. |
| `GOOGLE_ANALYTICS` | `googleAnalytics` | No | `UA-XXXXXXXX-X` | the UA-XXXXXXXX-X code from Google Analytics. if not specified wont set the script. |
| `FACEBOOK_APP_ID` | `facebookAppId` | No | `YYYYYYYYYYYY` | the Facebook App Id for share buttons. It will take first from keys.json, if not will use this one. Don't set it to not show FB share buttons. |
| `PRERENDER_ENABLE` | `prerender.enabled` | No | `false` | Boolean (true, false). Where the website would use the SEO Prerender.|
| `PRERENDER_DB` | `presender.db` | No | `"mongodb://localhost/prerender"` | The Mongo URI of Cached Pages. |

Authentication providers are configured using environment variables, .env file keys, or modifying `keys.js`.

| Environment variable or .env key | config.js key | Required | Default | Description |
|----------------------------------|---------------|----------|---------|-------------|
| `GITHUB_CLIENT_ID` | `github.clientID` | No | | [create a Github OAuth app](https://docs.github.com/en/developers/apps/building-oauth-apps/creating-an-oauth-app) |
| `GITHUB_SECRET_KEY` | `github.clientSecret` | No | | |
| `GITHUB_CALLBACK_URL` | `github.callbackURL` | No | `"fake"` | e.g. `http://localhost:3000/auth/github/callback` |

See code for more authentication options.


Running instances
=================
Expand Down
32 changes: 32 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require('dotenv').config();

module.exports = {
"db": {
"name": process.env.DB_NAME,
"host": process.env.DB_HOST,
"url": process.env.DATABASE_URL,
},
"host": process.env.HOST,
"port": parseInt(process.env.PORT) || 3000,
"session": process.env.SESSION,
"discourseUrl": process.env.DISCOURSE_URL || null,
"disqus_shortname": process.env.DISQUS_SHORTNAME || null,
"title": process.env.TITLE || "hackdash",
"live": process.env.LIVE || true,
"mailer": process.env.MAILER || null,
"prerender": {
"enabled": process.env.PRERENDER_ENABLE || false,
"db": process.env.PRERENDER_DB || "mongodb://localhost/prerender"
},
"team": [
"516d1997b2951b02280000e1",
"516d1997b2951b02280000e2",
"516d1997b2951b02280000e3",
"516d1997b2951b02280000e4",
"516d1997b2951b02280000e5",
"516d1997b2951b02280000e6"
],
"maxQueryLimit": process.env.MAX_QUERY_LIMIT || 30,
"googleAnalytics": process.env.GOOGLE_ANALYTICS || "UA-XXXXXXXX-X",
"facebookAppId": process.env.FACEBOOK_APP_ID || "YYYYYYYYYYYY"
};
30 changes: 0 additions & 30 deletions config/config.json.sample

This file was deleted.

31 changes: 31 additions & 0 deletions config/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require('dotenv').config()
module.exports = {
"db": {
"name": process.env.DB_NAME,
"host": process.env.DB_HOST,
"url": process.env.DATABASE_URL,
},
"host": process.env.HOST,
"port": parseInt(process.env.PORT) || 3000,
"session": process.env.SESSION,
"discourseUrl": process.env.DISCOURSE_URL || null,
"disqus_shortname": process.env.DISQUS_SHORTNAME || null,
"title": process.env.TITLE || "hackdash",
"live": process.env.LIVE || true,
"mailer": process.env.MAILER || null,
"prerender": {
"enabled": process.env.PREPENDER_ENABLE || false,
"db": process.env.PREPENDER_DB || "mongodb://localhost/prerender"
},
"team": [
"516d1997b2951b02280000e1",
"516d1997b2951b02280000e2",
"516d1997b2951b02280000e3",
"516d1997b2951b02280000e4",
"516d1997b2951b02280000e5",
"516d1997b2951b02280000e6"
],
"maxQueryLimit": process.env.MAX_QUERY_LIMIT || 30,
"googleAnalytics": process.env.GOOGLE_ANALYTICS || "UA-XXXXXXXX-X",
"facebookAppId": process.env.FCAEBOOK_APP_ID || "YYYYYYYYYYYY"
}
6 changes: 3 additions & 3 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Expose the configuration. Uses the test config if NODE_ENV env setting
* is set as 'test'. Otherwise it uses the default config file
*/

import config from './config.json';
import testConfig from './config.test.json';
require('dotenv').config()
import config from './config.js';
import testConfig from './config.test.js';

export default process.env.NODE_ENV === 'test' ? testConfig : config;
42 changes: 42 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3'

services:
db:
image: mongo:4.1.8-xenial
volumes:
- dbdata:/data/db

app:
build:
context: .
args:
USER_ID: ${USER_ID:-1001}
GROUP_ID: ${GROUP_ID:-1001}
environment:
- HOST=${HOST:-localhost}
- DATABASE_URL=mongodb://db:27017
- SESSION=not-so-secret-in-dev
ports:
- "3000:3000"
volumes:
- .:/home/app
depends_on:
- db

metrics:
build:
context: .
args:
USER_ID: ${USER_ID:-1001}
GROUP_ID: ${GROUP_ID:-1001}
environment:
- DATABASE_URL=mongodb://db:27017
volumes:
- .:/home/app
depends_on:
- db
command: "./start_metrics.sh"

volumes:
dbdata:
node_modules:
9 changes: 9 additions & 0 deletions keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require('dotenv').config();
module.exports = {

"github": {
"clientID": process.env.GITHUB_CLIENT_ID || "fake",
"clientSecret": process.env.GITHUB_SECRET_KEY,
"callbackURL": process.env.GITHUB_CALLBACK_URL,
}
};
23 changes: 0 additions & 23 deletions keys.json.sample

This file was deleted.

2 changes: 1 addition & 1 deletion lib/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import {Router} from 'express';
import passport from 'passport';
import passportHttp from 'passport-http';
import keys from 'keys.json';
import keys from 'keys.js';
import {User} from 'lib/models';
import gravatar from 'gravatar';

Expand Down
2 changes: 1 addition & 1 deletion lib/routes/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Module dependencies
*/

import providers from 'keys.json';
import providers from 'keys.js';

/*
* Render templates
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/site/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import statuses from 'lib/models/statuses';
import {check} from 'lib/utils/metas';
import {setViewVar, loadProviders, render} from 'lib/routes/helpers';
import {port, host, live, discourseUrl, disqus_shortname, googleAnalytics, facebookAppId} from 'config';
import keys from 'keys.json';
import keys from 'keys.js';

/**
* Module scope constants
Expand Down
12 changes: 10 additions & 2 deletions lib/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,19 @@ if (config.prerender && config.prerender.enabled) {
*/

const MongoStore = connectMongo(session);
app.set('subdomain offset', config.host.match(/\./g).length + 1)
const hostDots = config.host.match(/\./g);
const subdomainOffset = (hostDots ? hostDots.length : 0) + 1;
app.set('subdomain offset', subdomainOffset);

const cookie = { maxAge: sessionMaxAge, path: '/' };
// https://stackoverflow.com/a/1188145
if (subdomainOffset > 1)
cookie["domain"] = '.' + config.host;

app.use(session({
secret: config.session,
store: new MongoStore({db: config.db.name, url: config.db.url}),
cookie: { maxAge: sessionMaxAge, path: '/', domain: '.' + config.host },
cookie: cookie,
resave: false,
saveUninitialized: false
}));
Expand Down
5 changes: 5 additions & 0 deletions metrics/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cronTime": "00 00 11 * * 1-5",
"filename": "metrics.json",
"code": ""
}
Loading