Coder Social home page Coder Social logo

plantuml-serverless's Introduction

Render PlantUML diagrams with AWS Lambda

A serverless UI + API to render PlantUML diagrams.

Drop in replacement for official PlantUML server

This can be used as a drop in replacement for scenarios where http://www.plantuml.com/plantuml is used as a rendering endpoint. You can avoid sending the diagram source to a server outside your control and use an encrypted HTTPS endpoint for the diagram traffic.

This doesn't support everything the official PlantUML server does but should be good for most intents and purposes (PNG, SVG and TXT rendering).

For example, to have Visual Studio Code PlantUML plugin render using your own serverless deployment, set the following properties in vscode for the plugin:

    "plantuml.render": "PlantUMLServer",
    "plantuml.server": "https://your-endpoint-here"

Use "plantuml.server": "https://plantuml.nitorio.us" if you'd like to try before you deploy your own.

Demo

PNG Diagram

Rendered PNG diagram should be here

SVG Diagram

Rendered SVG diagram should be here

TXT Diagram

https://plantuml.nitorio.us/txt/Kt8goYylJYrIKj2rKr1o3F1KS4yiIIrFh5IoKWZ8ALOeIirBIIrIACd8B5Oeo4dCAodDpU52KGVMw9EOcvIIgE1McfTSafcVfwI0JpU6Of09C6czhCGYlDgnwBVHrSKq80YiEJL58IKpCRqeCHVDrM0zM9oDgGqUGc0jg464hXe0

Build

  • npm ci
  • mvn clean package

Deploy

You can deploy with Serverless framework or AWS SAM.

This used to be available on the AWS Serverless Application Repository, but currently that's not possible because it doesn't appear to support lambda functions packaged as container images.

Serverless framework:

  • Edit serverless.yml to replace custom.domains.dev and custom.domains.prod with your own domain names.
    • If you don't want a custom domain name, remove or comment out the serverless-domain-manager plugin from the plugins list and skip the sls create-cert and sls create_domain commands.
  • Run sls create-cert to create an ACM certificate for your domain as configured in custom.customCertificate.
  • Run sls create_domain to create an API Gateway custom domain as configured in custom.customDomain.
  • Run sls deploy.

The above steps deploy the default dev stage. To deploy the prod stage, add --stage prod to each command.

AWS SAM

  • Run sam-deploy.sh

The SAM deployment doesn't include custom domains currently.

plantuml-serverless's People

Contributors

adamcin avatar cagataygurturk avatar d4gg4d avatar dependabot[bot] avatar m-mohamedin avatar mmajis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

plantuml-serverless's Issues

Setup instructions and example calling the service?

Hi!

I've deployed the service, but whenever I attempt to generate a diagram I get gibberish as a response. For example:

https://XXX.execute-api.us-east-1.amazonaws.com/dev/txt/%40startuml%0ABob%20-%3E%20Alice%20%3A%20hello%0A%40enduml

Returns:

eyJpc0Vycm9yIjp0cnVlLCJlcnJvcnMiOlsiQ291bGQgbm90IGRlY29kZSBVTUwgZnJvbSByZXF1ZXN0IHBhdGg6ICU0MHN0YXJ0dW1sJTBBQm9iJTIwLSUzRSUyMEFsaWNlJTIwJTNBJTIwaGVsbG8lMEElNDBlbmR1bWwiXSwiZGlhZ3JhbVR5cGUiOiJVTktOT1dOIiwiZXJyb3JMb2NhdGlvbiI6IjAiLCJzdWdnZXN0aW9ucyI6W119

Which, when decoded, reads:

{"isError":true,"errors":["Could not decode UML from request path: %40startuml%0ABob%20-%3E%20Alice%20%3A%20hello%0A%40enduml"],"diagramType":"UNKNOWN","errorLocation":"0","suggestions":[]}

I also tried a bas64 encoded string:

https://XXX.execute-api.us-east-1.amazonaws.com/dev/txt/QHN0YXJ0dW1sDQpCb2IgLT4gQWxpY2UgOiBoZWxsbw0KQGVuZHVtbA==

Which returns:

QHN0YXJ0dW1sICAgICAgICAgICAgICAgIAonIHVuYWJsZSB0byBkZWNvZGUgc3RyaW5nCl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl4KIEVtcHR5IGRlc2NyaXB0aW9uICAgICAgIAogU3ludGF4IEVycm9yPyAgICAgICAgICAgCg==

Which decodes to:

@startuml                
' unable to decode string
^^^^^^^^^^^^^^^^^^^^^^^^^
 Empty description       
 Syntax Error?           

So I'm not sure how to call the service via a URL.

If I try to run the service from the command line, I get an error:

$ sls invoke -f txt -d "%40startuml%0ABob%20-%3E%20Alice%20%3A%20hello%0A%40enduml"
{
    "errorMessage": "Could not parse parameters",
    "errorType": "java.lang.IllegalArgumentException",
    "stackTrace": [
        "com.nitor.plantuml.lambda.LambdaBase.handleInputError(LambdaBase.java:125)",
        "com.nitor.plantuml.lambda.LambdaBase.getEncodedUml(LambdaBase.java:119)",
        "com.nitor.plantuml.lambda.TxtHandler.handleRequest(TxtHandler.java:21)"
    ],
    "cause": {
        "errorMessage": "java.lang.String cannot be cast to org.json.simple.JSONObject",
        "errorType": "java.lang.ClassCastException",
        "stackTrace": [
            "com.nitor.plantuml.lambda.LambdaBase.getEncodedUml(LambdaBase.java:106)",
            "com.nitor.plantuml.lambda.TxtHandler.handleRequest(TxtHandler.java:21)"
        ]
    }
}

  Error --------------------------------------------------

  Invoked function failed

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                     win32
     Node Version:           8.2.1
     Serverless Version:     1.24.1

And again, with base64 encoded argument which gave the same error.

Finally, I noted in the README that:

Serverless does not support specifying binary response MIME types for API Gateway. So this has to be done manually after serverless deployment.

However, I'm not sure what this is referring to or where to set it up.

Any help you can provide would be appreciated.

Thanks,

-James

How to use plantuml API

After deploying the serverless code, I know it's useful for vscode plugin. But can I use serverless plantuml api to render graph in my own app?

Cache-Control Header Missing

If the service is used from a browser, the diagram images could be cached. But there is no Cache-Control header in the response. So, the caching is very short or disabled, even if the diagram can not be different as before, right?

Java 11 Blocker: Fonts not present in lambda runtime

Fonts are not included in the Amazon Corretto Java 11 runtime environment.

This happens:

java.lang.InternalError: java.lang.reflect.InvocationTargetException
at java.desktop/sun.font.FontManagerFactory$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.FontManagerFactory.getInstance(Unknown Source)
at java.desktop/sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(Unknown Source)
at java.desktop/sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(Unknown Source)
at java.desktop/sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(Unknown Source)
at java.desktop/sun.java2d.HeadlessGraphicsEnvironment.getAvailableFontFamilyNames(Unknown Source)
at net.sourceforge.plantuml.ugraphic.UFont.<clinit>(UFont.java:60)
at net.sourceforge.plantuml.SkinParam.getFont(SkinParam.java:464)
at net.sourceforge.plantuml.SkinParamDelegator.getFont(SkinParamDelegator.java:83)
at net.sourceforge.plantuml.skin.rose.Rose.createComponent(Rose.java:95)
at net.sourceforge.plantuml.sequencediagram.graphic.DrawableSetInitializer.prepareParticipant(DrawableSetInitializer.java:626)
at net.sourceforge.plantuml.sequencediagram.graphic.DrawableSetInitializer.createDrawableSet(DrawableSetInitializer.java:140)
at net.sourceforge.plantuml.sequencediagram.graphic.SequenceDiagramFileMakerPuma2.<init>(SequenceDiagramFileMakerPuma2.java:116)
at net.sourceforge.plantuml.sequencediagram.SequenceDiagram.getSequenceDiagramPngMaker(SequenceDiagram.java:241)
at net.sourceforge.plantuml.sequencediagram.SequenceDiagram.getNbImages(SequenceDiagram.java:416)
at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:155)
at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:130)
at net.sourceforge.plantuml.SourceStringReader.generateImage(SourceStringReader.java:126)
at com.nitor.plantuml.PlantUmlUtil.renderDiagram(PlantUmlUtil.java:32)
at com.nitor.plantuml.lambda.PngHandler.handleRequest(PngHandler.java:35)
at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:897)
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:228)
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:162)
at lambdainternal.AWSLambda.main(AWSLambda.java:157)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
... 25 more
Caused by: java.lang.NullPointerException
at java.desktop/sun.awt.FontConfiguration.getVersion(Unknown Source)
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(Unknown Source)
at java.desktop/sun.awt.FontConfiguration.init(Unknown Source)
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(Unknown Source)
at java.desktop/sun.font.SunFontManager$2.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.SunFontManager.<init>(Unknown Source)
at java.desktop/sun.awt.FcFontManager.<init>(Unknown Source)
at java.desktop/sun.awt.X11FontManager.<init>(Unknown Source)
... 29 more
Could not initialize class net.sourceforge.plantuml.ugraphic.UFont: java.lang.NoClassDefFoundError java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.plantuml.ugraphic.UFont at net.sourceforge.plantuml.SkinParam.getFont(SkinParam.java:464) at net.sourceforge.plantuml.SkinParamDelegator.getFont(SkinParamDelegator.java:83) at net.sourceforge.plantuml.skin.rose.Rose.createC

Need to figure out how to add fonts as a lambda layer:

  • fontconfig.properties file
  • actual font files as referenced in the properties file

AdoptOpenJDK issue: https://github.com/AdoptOpenJDK/openjdk-build/issues/682
Related openjdk bug report: https://bugs.openjdk.java.net/browse/JDK-8204688s

PlantUML server version update

The included version of the PlantUML server appears unable to render C4 diagrams with the following error:

Unknown variable $tagStereo

According to this issue, it is related to the PlantUML server version:

plantuml-stdlib/C4-PlantUML#138

Screen Shot 2022-11-07 at 10 28 05 AM

Sample:

@startuml test_c4

!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4.puml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml

Container(idContainer, "Sample Container", "Go", "Sample C4 container")

@enduml

Screen Shot 2022-11-07 at 10 30 38 AM

The same UML renders ok in VSCode with a later PlantUML server version:

Screen Shot 2022-11-07 at 10 35 41 AM

Screen Shot 2022-11-07 at 10 34 02 AM

awslib version

the plantUml standard lib includes an old version of awslib. This package had an even older version. It is possible to get it up to date?

Problem with deploying on AWS

Hello,

I have problems with deploying the lambdas in my AWS. I did following steps:

  1. Install aws cli
  2. Install serverless cli
  3. Install docker
  4. Set AWS credentials on profile "core" in file ~/.aws/credentials
  5. Run npm install
  6. Run mvn clean package
  7. Create a public API with AWS API Gateway
  8. Run sls deploy --stage plantuml

Seems to work fine until this error appears:

Serverless: Invoke aws:package:finalize
Serverless: Invoke aws:common:moveArtifactsToPackage
Serverless: Invoke aws:common:validate
Serverless Domain Manager: NotFoundException: Invalid domain name identifier specified
 
 Error ---------------------------------------------------
 
  Error: Error: **not-for-public**.eu-west-1.amazonaws.com not found.
      at ServerlessCustomDomain.<anonymous> (/Users/limbus/repository/plantuml-serverless/node_modules/serverless-domain-manager/dist/index.js:311:27)
      at Generator.throw (<anonymous>)
      at rejected (/Users/limbus/repository/plantuml-serverless/node_modules/serverless-domain-manager/dist/index.js:5:65)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              16.4.0
     Framework Version:         2.46.0 (local)
     Plugin Version:            5.3.0
     SDK Version:               4.2.3
     Components Version:        3.12.0

I changed following parts in the serverless.yml (only domain/plantuml and certificateName):

custom:
  domains:
    plantuml: "**not-for-public**.eu-west-1.amazonaws.com"
  customDomain:
    certificateName: "*.execute-api.eu-west-1.amazonaws.com"

I do not understand, why the domain and certificate is needed here... anyway... can you help?

Reason for trying to update: The (older) version in the serverless repo (https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:293246570391:applications~plantuml-render) seems not to be working with Java 8 (Corretto). I tried to change the environment of the lambda functions manually to Java 8 (Corretto). That did not work.

Setting PLANTUML_LIMIT_SIZE

I'd like to set the PLANTUML_LIMIT_SIZE environment variable to support larger drawings in accordance with I want to generate huge diagrams! here.

Any idea where in your code I should set that?

UI?

Hi, really like what you did here :-)

Would it be possible to release also the UI as a function?
It seems its almost done, but I'm lacking some knowledge to do it myself...

Thanks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.