-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
mermaidcli/node_modules/ | ||
vendor/ | ||
in/ | ||
out/ | ||
.DS_Store | ||
.idea/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This stage builds the mermaidcli executable. | ||
FROM node:12.12.0-buster as node | ||
|
||
WORKDIR /root | ||
|
||
# copy the mermaidcli node package into the container and install | ||
COPY ./mermaidcli/* . | ||
|
||
RUN npm install | ||
|
||
|
||
# This stage builds the go executable. | ||
FROM golang:1.13-buster as go | ||
|
||
WORKDIR /root | ||
COPY . . | ||
|
||
RUN go build -o bin/app cmd/app/main.go | ||
|
||
|
||
# Final stage that will be pushed. | ||
FROM debian:buster-slim | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
RUN apt update 2>/dev/null && \ | ||
apt install -y --no-install-recommends \ | ||
ca-certificates \ | ||
2>/dev/null | ||
|
||
COPY --from=node /root/node_modules/.bin/mmdc ./mermaidcli | ||
COPY --from=go /root/bin/app ./app | ||
|
||
# We should now have all the required dependencies to build the proto files. | ||
CMD ["./app", "--mermaid=./mermaidcli"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# mermaid-server | ||
|
||
Use mermaid-js to generate diagrams in a HTTP endpoint. | ||
|
||
While this currently serves the diagrams via HTTP, it could easily be manipulated to server diagrams via other means. | ||
|
||
## Basic usage | ||
|
||
Start the HTTP server: | ||
``` | ||
go run cmd/app/main.go --mermaid=./mermaidcli/node_modules/.bin/mmdc --in=./in --out=./out | ||
``` | ||
|
||
Send CURL request to generate a diagram: | ||
``` | ||
curl --location --request POST 'http://localhost:80/generate' \ | ||
--header 'Content-Type: text/plain' \ | ||
--data-raw 'graph LR | ||
A-->B | ||
B-->C | ||
C-->D | ||
C-->F | ||
' | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"mermaid-server/internal" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
var testInput = []byte(` | ||
graph TB | ||
subgraph "Jira" | ||
createTicket["Create ticket"] | ||
updateTicket["Update ticket"] | ||
fireWebhook["Fire webhook"] | ||
createTicket-->fireWebhook | ||
updateTicket-->fireWebhook | ||
end | ||
subgraph "Jira Webhook" | ||
receiveWebhook["Receive webhook"] | ||
storeEvent["Store event in immutable list"] | ||
publishNewStoredEventEvent["Publish message to notify system of new event"] | ||
createEvent["Create internal event that will be stored"] | ||
setCreatedAt["Set created at date to now"] | ||
setSourceJira["Set source to Jira webhook"] | ||
receiveWebhook-->createEvent-->setCreatedAt-->setSourceJira-->storeEvent | ||
storeEvent-->publishNewStoredEventEvent | ||
end | ||
fireWebhook-->receiveWebhook | ||
subgraph "Play Event" | ||
publishEventUpdated["Publish message to notify system of new status"] | ||
verifyEventSource["Verify event source"] | ||
parsePayload["Parse event payload using source to determine structure"] | ||
findEventHandler["Find the handler for the specific event type + version"] | ||
getLatestPersistedState["Get latest persisted state"] | ||
changeInMemoryStateUsingEventData["Change in-memory state using event data"] | ||
persistUpdatedState["Persist updated state"] | ||
verifyEventSource-->parsePayload | ||
parsePayload-->findEventHandler | ||
findEventHandler-->getLatestPersistedState-->changeInMemoryStateUsingEventData-->persistUpdatedState | ||
persistUpdatedState-->publishEventUpdated | ||
end | ||
publishNewStoredEventEvent-->verifyEventSource | ||
`) | ||
|
||
func main() { | ||
mermaid := flag.String("mermaid", "", "The full path to the mermaidcli executable.") | ||
in := flag.String("in", "", "Directory to store input files.") | ||
out := flag.String("out", "", "Directory to store output files.") | ||
flag.Parse() | ||
|
||
if *mermaid == "" { | ||
_, _ = fmt.Fprintf(os.Stderr, "Missing required argument `mermaid`") | ||
os.Exit(1) | ||
} | ||
|
||
if *in == "" { | ||
_, _ = fmt.Fprintf(os.Stderr, "Missing required argument `in`") | ||
os.Exit(1) | ||
} | ||
|
||
if *out == "" { | ||
_, _ = fmt.Fprintf(os.Stderr, "Missing required argument `out`") | ||
os.Exit(1) | ||
} | ||
|
||
cache := internal.NewDiagramCache() | ||
generator := internal.NewGenerator(cache, *mermaid, *in, *out) | ||
|
||
httpHandler := internal.GenerateHTTPHandler(generator) | ||
|
||
r := http.NewServeMux() | ||
r.Handle("/generate", http.HandlerFunc(httpHandler)) | ||
|
||
httpServer := &http.Server{ | ||
Addr: ":80", | ||
Handler: r, | ||
} | ||
_, _ = fmt.Fprintf(os.Stdout, "Listening on address %s", httpServer.Addr) | ||
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { | ||
_, _ = fmt.Fprintf(os.Stderr, "Could not listen for http connections: %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
_, _ = fmt.Fprintf(os.Stdout, "Shutdown") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/tomwright/mermaid-server | ||
|
||
go 1.13 |