Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dudash committed Aug 30, 2019
2 parents 1155679 + 3ac3312 commit 3ae1a81
Show file tree
Hide file tree
Showing 28 changed files with 2,794 additions and 131 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ This repo is an example microservices based application. It's core functionality
First off, you need access to an OpenShift cluster. Don't have an OpenShift cluster? That's OK, download the CDK (or minishift) for free here: https://developers.redhat.com/products/cdk/overview/. You will need a fairly beefy machine to run *everything* on the same machine via CDK, so I'd recommend you expose extra CPUs and Mem to the CDK when you start your cluster.

You will also need to install/configure the additional dependencies you plan to leverage. We assume you want to run these in the cluster, so you might need to tweak the install scripts to move things outside or to use already existing shared services in different namespaces.
- [Istio](./deployment/install/istio)
- [3Scale](./deployment/install/3scale) - COMING SOON
- [Kafka](./deployment/install/kafka) - COMING SOON
- Istio
- 3Scale - COMING SOON
- Kafka - COMING SOON
- Caching - COMING SOON

To install the microservices demo, you can choose to do that from source or from pre-built container images.
- [The script to install for is located here](./deployment/install/microservices)
- You will need to tweak if you want to install from source [read this](./deployment/install/)
To install everything:
- [Follow instructions here](./deployment/install/)

Once you have the basic app up and running, how about trying out [some demos](./deployment/demos)

Expand All @@ -71,11 +71,19 @@ The parts in action here are:


## References, useful links, good videos to check out
### Microservices
* [Microservices at Spotify Talk](https://www.youtube.com/watch?v=7LGPeBgNFuU)
* [Microservices at Uber Talk](https://www.youtube.com/watch?v=kb-m2fasdDY)
* [Mastering Chaos Netflix Talk](https://youtu.be/CZ3wIuvmHeM)
* [Red Hat Developer's Learning - Microservices](https://developers.redhat.com/learn/microservices/)
### Istio Service Mesh
* [What is Istio?](https://istio.io/docs/concepts/what-is-istio/)
* [Red Hat Developer's Istio Free Book](https://developers.redhat.com/books/introducing-istio-service-mesh-microservices/)
* [Free Hands-on with Istio](https://learn.openshift.com/servicemesh)
### Single Sign On
* [Keycloak SSO](https://www.keycloak.org/)


## Contributing
[See guidelines here](./CONTRIBUTING.md). But in general I would love for help with 2 things.
1. Use this repo and [report issues][1], even fix them if you can.
Expand Down
11 changes: 10 additions & 1 deletion code/app-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ This microservice provides the main user interface into the application.

### Env Vars
- PORT, port to run the service (defaults to 8080 in PROD, 3000 in DEV)
-
- HTTP_PROTOCOL, default='http://'
- SERVICE_NAME, default='app-ui'
- BOARDS_SVC_HOST, default='boards'
- BOARDS_SVC_PORT, default='8080'
- PROFILE_SVC_HOST, default='profile'
- PROFILE_SVC_PORT, default='8080'
- SSO_SVC_HOST, default='auth-sso73-x509'
- SSO_SVC_PORT, default='8443'
- SESSION_SECRET, default='pleasechangeme'

### Local Installation / Run / Test
```bash
$ npm install
Expand Down
33 changes: 33 additions & 0 deletions code/app-ui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,34 @@ var path = require('path')
var cookieParser = require('cookie-parser')
var cors = require('cors')
var debug = require('debug')('app')
var session = require('express-session') //Using cookie-parser may result in issues if the secret is not the same between this module and cookie-parser.
var SSO = require('keycloak-connect') // https://www.keycloak.org/docs/latest/securing_apps/index.html#_javascript_adapter

const HTTP_PROTOCOL = process.env.HTTP_PROTOCOL || 'http://'
const SERVICE_NAME = process.env.SERVICE_NAME || 'app-ui'
const BOARDS_SVC_HOST = process.env.BOARDS_SVC_HOST || 'boards'
const BOARDS_SVC_PORT = process.env.BOARDS_SVC_PORT || '8080'
const PROFILE_SVC_HOST = process.env.PROFILE_SVC_HOST || 'profile'
const PROFILE_SVC_PORT = process.env.PROFILE_SVC_PORT || '8080'
const SSO_SVC_HOST = process.env.SSO_SVC_HOST || 'auth-sso73-x509'
const SSO_SVC_PORT = process.env.SSO_SVC_PORT || '8443'
const SESSION_SECRET = process.env.SESSION_SECRET || 'pleasechangeme'

var app = express()
app.use(cors())

// Create a session-store for keycloak middleware.
// Warning! MemoryStore, is purposely not designed for a production environment.
// It will leak memory under most conditions, does not scale past a single
// process, and is meant for debugging and developing.
var memoryStore = new session.MemoryStore();
app.use(session({
secret: SESSION_SECRET, // This is the secret used to sign the session ID cookie
resave: false,
saveUninitialized: true,
store: memoryStore
}));

// view engine setup
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'pug')
Expand All @@ -30,22 +46,39 @@ app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(express.static(path.join(__dirname, 'public')))
var auth = new SSO({store: memoryStore});
app.use(auth.middleware({logout: '/logout'}));

app.use(function(req,res,next) {
req.SERVICE_NAME = SERVICE_NAME
req.debug = debug // pass along debugger for service
req.HTTP_PROTOCOL = HTTP_PROTOCOL
req.BOARDS_SVC_HOST = BOARDS_SVC_HOST
req.BOARDS_SVC_PORT = BOARDS_SVC_PORT
req.PROFILE_SVC_HOST = PROFILE_SVC_HOST
req.PROFILE_SVC_PORT = PROFILE_SVC_PORT
res.locals.ua = req.get('user-agent') // put user agent info into the response data for client side logic
next()
})

// TODO: we need to do real auth
app.use(function (req, res, next) {
res.locals.user = 'anonymous'
res.locals.authenticated = false
next()
})

var indexRouter = require('./routes/index')
var profileRouter = require('./routes/profile')
var sharedRouter = require('./routes/shared')
var boardRouter = require('./routes/board')
app.use('/', indexRouter)
app.use('/profile', profileRouter)
app.use('/shared', sharedRouter)
app.use('/:user/board', boardRouter)
//app.use('/:user/dashboard', auth.protect('realm:user'), dashboardRouter)
//app.use('/:user/board', auth.protect('realm:user'), boardRouter) // must be logged in and have 'user' role in the realm. TODO: switch to this when SSO is ready

app.use(function(req, res, next) {
next(createError(404)) // catch 404 and forward to error handler
})
Expand Down
121 changes: 121 additions & 0 deletions code/app-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions code/app-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
"cors": "~2.8.5",
"debug": "^2.6.9",
"express": "~4.16.4",
"express-session": "^1.16.1",
"http-errors": "~1.6.3",
"kafka-node": "^4.0.0",
"keycloak-connect": "^6.0.1",
"moment": "~2.24.0",
"pug": "^2.0.3",
"request": "^2.88.0",
Expand Down
33 changes: 30 additions & 3 deletions code/app-ui/public/javascripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,34 @@ $('#newBoardModal').on('show.bs.modal', function (event) {
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this)
//modal.find('.modal-title').text('REPLACED TITLE')
//modal.find('.modal-body input').val('New Board')
//modal.find('.modal-body textarea').val('New Board Description')

// setup a validator
$('#newboardSubmitButton').prop('disabled', true);
$('.modal-body input').off('keyup');
$('.modal-body input').on('keyup', validate);

// clear out prior input values
modal.find('.modal-body input').val('')
modal.find('.modal-body textarea').val('')
modal.find('.modal-body input:checkbox').prop("checked", false)
})

function validate() {
if ($('#newboardName').val()) {
$('#newboardSubmitButton').prop('disabled', false);
} else {
$('#newboardSubmitButton').prop('disabled', true);
}
}

// $('#newBoardForm').click(function(e){
// e.preventDefault();
// alert($('#newboardName').val());
//
// $.post('http://path/to/post',
// $('#newBoardForm').serialize(),
// function(data, status, xhr){
// // do something here with response;
// });
//
// })
2 changes: 1 addition & 1 deletion code/app-ui/public/stylesheets/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@

footer p {
margin-bottom: .25rem;
}
}
Loading

0 comments on commit 3ae1a81

Please sign in to comment.