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

Extract a base microservice layer to reuse for all our services #1666

Closed
humphd opened this issue Feb 6, 2021 · 6 comments
Closed

Extract a base microservice layer to reuse for all our services #1666

humphd opened this issue Feb 6, 2021 · 6 comments
Labels
Milestone

Comments

@humphd
Copy link
Contributor

humphd commented Feb 6, 2021

In #1636 @raygervais and I have been iterating on our first microservice, a simple image service. As we start to work on other services (#1627) we're going to have to solve the same problems over and over again:

  • env handling
  • setup express app
  • security (helmet, csrf, cors, etc)
  • various base middleware
  • logging
  • error handling
  • start a server on a predefined port
  • graceful shutdown (probably crash on error so docker-compose can restart)
  • healthcheck route

I'm sure there's more, and added to this we'll have to maintain versions of all the dependencies.

Let's find a way to write this code once and then use it as a base for all of our apps. I'm imagining something like this:

src/
    api/
         _microservice/  <-- our base microservice app
         service-1/  <-- a service using _miroservice (e.g., image service)
         service-2/  <-- a second service using _microservice (e.g., auth service)
         ...

In service-1 you'd do something like this:

// Pull in the _microservice base to get our pre-configured app
const { app } = require('../path/to/_microservice');

app.get('/', (req, res) => res.json({hello: 'world'}));

What I'm not sure about is the implications for dockerizing the code when we do this. Probably @raygervais knows how, and can guide us.

I'd love for each service to as simple as possible, and focused on the endpoint requirements alone.

We can probably start this by making the image service in #1636 work this way, then use it in the next services.

@humphd humphd added type: enhancement New feature or request area: back-end labels Feb 6, 2021
@raygervais
Copy link
Contributor

@humphd, did you plan on updating the image service first with this architecture?

@humphd
Copy link
Contributor Author

humphd commented Feb 6, 2021

It might be smart, what do you think? Then others can focus on their service features vs. solving these problems.

@raygervais
Copy link
Contributor

Agreed, plus we can add a base Dockerfile into _microservice for reference as well (adding to your list).
The ports we are going to have to juggle, so my idea: keep a .env file in the root directory of telescope (or config folder) which gets copied on build by Docker into the various containers. This way, we can define ports / configurations in a single place.

Logging means getting Kibana configured and in the mix, perhaps exploring https://medium.com/the-sysadmin/visualize-traefik-logs-in-kibana-c53fb2aac070 would be beneficial. I can do that today perhaps so we work in parallel and I submit PRs against your POC again?

@humphd
Copy link
Contributor Author

humphd commented Feb 6, 2021

OK, great. I like your idea of always copying the root .env into each, so we can continue to configure the entire app like we do now, and specify port numbers for services in there.

Yeah, I really want to get Kibana/Elastic/??? tied in with all these services and Traefik so we have visibility into what's happening. #1348 is related.

@raygervais
Copy link
Contributor

I'll start on #1348, based on the work we are doing here

@humphd
Copy link
Contributor Author

humphd commented Feb 13, 2021

Finished with https://github.com/Seneca-CDOT/satellite and used in the new image service, see src/api/image.

@humphd humphd closed this as completed Feb 13, 2021
@humphd humphd added this to the 1.7 Release milestone Feb 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants