nx-plugins icon indicating copy to clipboard operation
nx-plugins copied to clipboard

Deploying arbitrary services

Open micmania1 opened this issue 4 years ago • 3 comments

Is your feature request related to a problem? Please describe. This isn't specifically a feature request... more a discussion as to how best to do things.

Alongside my static app and API I might want to deploy other services (database, auth, etc.). These don't necessarily belong to a specific API or static app so I was wondering if you have any advice on how to go about adding these?

So far I've altered an API to include cognito + dynamodb to deploy with pulumi but ideally I'd have these elsewhere in their own applications/services as they won't change very often.

Describe the solution you'd like Locally I've created a dynamodb app within nx. This is made up of a docker-compose file to run the database locally with a serve command and nothing else. My thinking is that I would be able to run deploy-it to generate a dynamodb pulumi app in the same way I can with an express app.

Describe alternatives you've considered

1. Base Infrastructure

I've considered is that this plugin can create its own application with some base/blueprint infrastructure where the user can add things that span multiple apps or won't change often. This could include things like a VPC, Database etc. but would be completely up to the user to build this out.

2. Pulumi wrapper

Another alternative is to create my own wrapper around pulumi, but that feels like duplicating the work you've already achieved here.

3. Pulumi directly

I could also add a pulumi file to the monorepo core somewhere and use pulumi directly.

Check which provider is affected: [x] Azure [x] AWS [x] Google Cloud Platform

I've talked about AWS services in my examples since that's what I'm using but this could apply to any provider.

Additional context I think I've covered this above. If you want more info let me know.

micmania1 avatar Oct 29 '20 06:10 micmania1

Yeah, I was thinking about this kind of idea already. I received messages where people asked for custom templates -> So what I can imagine is to be able to provide a custom template path (URL to the template) that would be used.

With this feature we would enable an ecosystem where everyone could provide nice templates for any kind of solution. And they don't need to contribute directly to the plugin?

Imagine it as a plugin system in the plugin :D :D

What do you think?

MitkoTschimev avatar Oct 29 '20 06:10 MitkoTschimev

Could that already work within the NX paradigms?

Let say for example this plugin provides a generate command to create an empty shell:

nx g @dev-thought/deploy-it-empty:app <my-app>

That would create the infrastructure folder within the specific app (or potentially create the entire app itself), add necessary files (Pulumi.yaml) and add the deploy/destroy commands to the application. All the user would need to do then is write the pulumi typescript file and add any configuration.

If you wanted to extend this to create templates, you could potentially do something similar to this:

import { chain, externalSchematic, Rule } from '@angular-devkit/schematics';

function applyCustomFiles() {
  console.log('Do custom stuff here');
}

function addCustomCommands() {
  console.log('Add custom commands like "serve" to run the service locally');
}

export default function (schema: any): Rule {
  return chain([
    externalSchematic('@dev-thought/deploy-it-empty', 'app', {
      name: schema.name,
    }),
    applyCustomFiles(),
    addCustomCommands(),
  ]);
}

Disclaimer: I'm new to NX/Pulumi and angular workspace schematics so apologies if I make some wrong assumptions. Please feel free to correct me if I get anything wrong.

micmania1 avatar Oct 29 '20 09:10 micmania1

Yes, kind of this way it would be possible. I would skip the whole command line support for it. Because I expect that the person who wants to use a special template, knows which one he chose and with which application/library it is compatible.

MitkoTschimev avatar Nov 04 '20 18:11 MitkoTschimev