21 Commits

Author SHA1 Message Date
Tom Wright
c23c29bd9e Update github action go version 2021-08-14 16:37:41 +01:00
Tom Wright
d252a491e4 Use grace instead of lifetime 2021-08-14 16:34:07 +01:00
Tom Wright
0b061ec570 Merge pull request #9 from TomWright/dependabot/docker/golang-1.16.7-buster
Bump golang from 1.16.6-buster to 1.16.7-buster
2021-08-14 16:18:25 +01:00
Tom Wright
e51d488c9f Merge pull request #10 from TomWright/dependabot/docker/node-16.6.2-buster-slim
Bump node from 16.5.0-buster-slim to 16.6.2-buster-slim
2021-08-14 16:18:09 +01:00
dependabot[bot]
ba7c8be38a Bump node from 16.5.0-buster-slim to 16.6.2-buster-slim
Bumps node from 16.5.0-buster-slim to 16.6.2-buster-slim.

---
updated-dependencies:
- dependency-name: node
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-14 15:17:30 +00:00
dependabot[bot]
047e47c138 Bump golang from 1.16.6-buster to 1.16.7-buster
Bumps golang from 1.16.6-buster to 1.16.7-buster.

---
updated-dependencies:
- dependency-name: golang
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-14 15:17:24 +00:00
Tom Wright
dc5bca1962 Merge pull request #8 from mmorel-35/master
Update Dependencies
2021-08-14 16:16:46 +01:00
Tom Wright
750e8c7ea9 Upgrade mermaid cli and add missing package in Dockerfile 2021-08-14 16:15:36 +01:00
Matthieu MOREL
a35e3d7085 Merge branch 'master' into master 2021-07-31 14:32:32 +02:00
Tom Wright
f7459c7d89 Merge pull request #7 from TomWright/dependabot/npm_and_yarn/mermaidcli/ws-7.4.6
Bump ws from 7.3.1 to 7.4.6 in /mermaidcli
2021-07-30 22:46:16 +01:00
dependabot[bot]
90359524c5 Bump actions/cache from 1 to 2.1.6 (#3)
Bumps [actions/cache](https://github.com/actions/cache) from 1 to 2.1.6.
- [Release notes](https://github.com/actions/cache/releases)
- [Commits](https://github.com/actions/cache/compare/v1...v2.1.6)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-28 22:17:27 +02:00
dependabot[bot]
f95701f228 Bump golang from 1.15-buster to 1.16.6-buster (#5)
Bumps golang from 1.15-buster to 1.16.6-buster.

---
updated-dependencies:
- dependency-name: golang
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-28 22:15:51 +02:00
dependabot[bot]
19a86c6774 Bump @mermaid-js/mermaid-cli from 8.6.4 to 8.11.0 in /mermaidcli (#6)
Bumps [@mermaid-js/mermaid-cli](https://github.com/mermaid-js/mermaid-cli) from 8.6.4 to 8.11.0.
- [Release notes](https://github.com/mermaid-js/mermaid-cli/releases)
- [Commits](https://github.com/mermaid-js/mermaid-cli/compare/8.6.4...8.11.0)

---
updated-dependencies:
- dependency-name: "@mermaid-js/mermaid-cli"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-28 22:15:17 +02:00
dependabot[bot]
20b9a399b0 Bump github.com/tomwright/lifetime from 1.0.0 to 1.0.1 (#7)
Bumps [github.com/tomwright/lifetime](https://github.com/tomwright/lifetime) from 1.0.0 to 1.0.1.
- [Release notes](https://github.com/tomwright/lifetime/releases)
- [Commits](https://github.com/tomwright/lifetime/compare/v1.0.0...v1.0.1)

---
updated-dependencies:
- dependency-name: github.com/tomwright/lifetime
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-28 22:14:52 +02:00
dependabot[bot]
65ceba9e32 Bump node from 12.12.0-buster-slim to 16.5.0-buster-slim (#4)
Bumps node from 12.12.0-buster-slim to 16.5.0-buster-slim.

---
updated-dependencies:
- dependency-name: node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-28 22:13:48 +02:00
dependabot[bot]
65bbc334f5 Bump actions/setup-go from 1 to 2.1.3 (#2)
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 1 to 2.1.3.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v1...v2.1.3)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-28 22:12:24 +02:00
dependabot[bot]
ae587caf8e Bump actions/checkout from 1 to 2.3.4 (#1)
Bumps [actions/checkout](https://github.com/actions/checkout) from 1 to 2.3.4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v1...v2.3.4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-28 22:11:49 +02:00
Matthieu MOREL
57684645cc Create dependabot.yml 2021-07-28 22:08:15 +02:00
dependabot[bot]
57cfd74df7 Bump ws from 7.3.1 to 7.4.6 in /mermaidcli
Bumps [ws](https://github.com/websockets/ws) from 7.3.1 to 7.4.6.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/7.3.1...7.4.6)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-30 06:42:05 +00:00
Tom Wright
4bd13d8620 Delete FUNDING.yml 2021-01-11 17:45:10 +00:00
Tom Wright
5d8b7c961b Create FUNDING.yml 2020-11-06 15:12:02 +00:00
13 changed files with 3365 additions and 248 deletions

18
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,18 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
- package-ecosystem: docker
directory: /
schedule:
interval: weekly
- package-ecosystem: npm
directory: /mermaidcli
schedule:
interval: weekly

View File

@@ -7,14 +7,14 @@ jobs:
build: build:
strategy: strategy:
matrix: matrix:
go-version: [1.15.x] go-version: [1.16.x]
platform: [ubuntu-latest] platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v1 uses: actions/checkout@v2.3.4
- name: Set env - name: Set env
run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF:10} run: echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV
- name: Build - name: Build
run: docker build -t tomwright/mermaid-server:latest -t tomwright/mermaid-server:${{ env.RELEASE_VERSION }} -f Dockerfile . run: docker build -t tomwright/mermaid-server:latest -t tomwright/mermaid-server:${{ env.RELEASE_VERSION }} -f Dockerfile .
- name: Login - name: Login

View File

@@ -4,17 +4,17 @@ jobs:
test: test:
strategy: strategy:
matrix: matrix:
go-version: [1.15.x] go-version: [1.16.x]
platform: [ubuntu-latest] platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
steps: steps:
- name: Install Go - name: Install Go
uses: actions/setup-go@v1 uses: actions/setup-go@v2.1.3
with: with:
go-version: ${{ matrix.go-version }} go-version: ${{ matrix.go-version }}
- name: Checkout code - name: Checkout code
uses: actions/checkout@v1 uses: actions/checkout@v2.3.4
- uses: actions/cache@v1 - uses: actions/cache@v2.1.6
with: with:
path: ~/go/pkg/mod path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

View File

@@ -1,5 +1,5 @@
# This stage builds the go executable. # This stage builds the go executable.
FROM golang:1.15-buster as go FROM golang:1.16.7-buster as go
WORKDIR /root WORKDIR /root
COPY ./ ./ COPY ./ ./
@@ -10,7 +10,7 @@ RUN go build -o bin/app cmd/app/main.go
# Final stage that will be pushed. # Final stage that will be pushed.
FROM debian:buster-slim FROM debian:buster-slim
FROM node:12.12.0-buster-slim as node FROM node:16.6.2-buster-slim as node
WORKDIR /root WORKDIR /root
@@ -64,6 +64,7 @@ RUN apt-get update 2>/dev/null && \
lsb-release \ lsb-release \
xdg-utils \ xdg-utils \
wget \ wget \
libxshmfence1 \
2>/dev/null 2>/dev/null
COPY --from=go /root/bin/app ./app COPY --from=go /root/bin/app ./app

View File

@@ -4,7 +4,7 @@ import (
"context" "context"
"flag" "flag"
"fmt" "fmt"
"github.com/tomwright/lifetime" "github.com/tomwright/grace"
"github.com/tomwright/mermaid-server/internal" "github.com/tomwright/mermaid-server/internal"
"os" "os"
) )
@@ -31,19 +31,16 @@ func main() {
os.Exit(1) os.Exit(1)
} }
g := grace.Init(context.Background())
cache := internal.NewDiagramCache() cache := internal.NewDiagramCache()
generator := internal.NewGenerator(cache, *mermaid, *in, *out, *puppeteer) generator := internal.NewGenerator(cache, *mermaid, *in, *out, *puppeteer)
httpService := internal.NewHTTPService(generator) httpRunner := internal.NewHTTPRunner(generator)
cleanupService := internal.NewCleanupService(generator) cleanupRunner := internal.NewCleanupRunner(generator)
lt := lifetime.New(context.Background()).Init() g.Run(httpRunner)
g.Run(cleanupRunner)
// Start the http service. g.Wait()
lt.Start(httpService)
// Start the cleanup service.
lt.Start(cleanupService)
// Wait for all routines to stop running.
lt.Wait()
} }

5
go.mod
View File

@@ -2,4 +2,7 @@ module github.com/tomwright/mermaid-server
go 1.15 go 1.15
require github.com/tomwright/lifetime v1.0.0 require (
github.com/tomwright/grace v0.1.2
github.com/tomwright/gracehttpserverrunner v0.1.0
)

6
go.sum
View File

@@ -1,2 +1,4 @@
github.com/tomwright/lifetime v1.0.0 h1:Yzj+Td38eUUdZ1ewvOegywFBmKyaCh+8HjKBmeXw6OM= github.com/tomwright/grace v0.1.2 h1:8kH+S2GLqnwgWqUzi9CcjNoWJANZQnw9Xw65NPUr6WA=
github.com/tomwright/lifetime v1.0.0/go.mod h1:GUCHgRaR/zStvtJiOd3B4gIZayeiz3TgApC9kNYAOQI= github.com/tomwright/grace v0.1.2/go.mod h1:RKqz4gB3sQJpyas/CuiiriQQfUxSXhtWRfYtE7MG+Ok=
github.com/tomwright/gracehttpserverrunner v0.1.0 h1:n4iafOnJQEmRn05i1QzU+FPS0CU4ybxilyEdBEH/Ulk=
github.com/tomwright/gracehttpserverrunner v0.1.0/go.mod h1:FFHjVUgXu7KygMn+QlaoCesVlPOhaCnCvw35nvgzt5I=

46
internal/cleanup.go Normal file
View File

@@ -0,0 +1,46 @@
package internal
import (
"context"
"github.com/tomwright/grace"
"log"
"time"
)
// NewCleanupRunner returns a runner that can be used cleanup old diagrams.
func NewCleanupRunner(generator Generator) grace.Runner {
return &cleanupService{
generator: generator,
runEvery: time.Minute * 5,
cleanupLast: time.Hour,
}
}
// cleanupService is a runner that is used cleanup old diagrams.
type cleanupService struct {
generator Generator
runEvery time.Duration
cleanupLast time.Duration
}
// Run starts the cleanup process.
func (s *cleanupService) Run(ctx context.Context) error {
for {
select {
case <-ctx.Done():
return nil
default:
}
if err := s.generator.CleanUp(s.cleanupLast); err != nil {
log.Printf("error when cleaning up: %s", err.Error())
}
select {
case <-time.After(s.runEvery):
continue
case <-ctx.Done():
return nil
}
}
}

View File

@@ -1,41 +0,0 @@
package internal
import (
"log"
"time"
)
// NewCleanupService returns a service that can be used cleanup old diagrams.
func NewCleanupService(generator Generator) *cleanupService {
return &cleanupService{
generator: generator,
stopCh: make(chan struct{}),
}
}
// cleanupService is a service that can be used cleanup old diagrams.
type cleanupService struct {
generator Generator
stopCh chan struct{}
}
// Start starts the cleanup service.
func (s *cleanupService) Start() error {
for {
if err := s.generator.CleanUp(time.Hour); err != nil {
log.Printf("error when cleaning up: %s", err.Error())
}
select {
case <-time.After(time.Minute * 5):
continue
case <-s.stopCh:
return nil
}
}
}
// Stop stops the cleanup service.
func (s *cleanupService) Stop() {
close(s.stopCh)
}

View File

@@ -3,13 +3,32 @@ package internal
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/tomwright/grace"
"github.com/tomwright/gracehttpserverrunner"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
"time"
) )
// NewHTTPRunner returns a grace runner that runs a HTTP server.
func NewHTTPRunner(generator Generator) grace.Runner {
httpHandler := generateHTTPHandler(generator)
r := http.NewServeMux()
r.Handle("/generate", http.HandlerFunc(httpHandler))
return &gracehttpserverrunner.HTTPServerRunner{
Server: &http.Server{
Addr: ":80",
Handler: r,
},
ShutdownTimeout: time.Second * 5,
}
}
func writeJSON(rw http.ResponseWriter, value interface{}, status int) { func writeJSON(rw http.ResponseWriter, value interface{}, status int) {
bytes, err := json.Marshal(value) bytes, err := json.Marshal(value)
if err != nil { if err != nil {

View File

@@ -1,47 +0,0 @@
package internal
import (
"net/http"
)
// NewHTTPService returns a service that can be used to start a http server
// that will generate diagrams.
func NewHTTPService(generator Generator) *httpService {
return &httpService{
generator: generator,
}
}
// httpService is a service that can be used to start a http server
// that will generate diagrams.
type httpService struct {
httpServer *http.Server
generator Generator
}
// Start starts the HTTP server.
func (s *httpService) Start() error {
httpHandler := generateHTTPHandler(s.generator)
r := http.NewServeMux()
r.Handle("/generate", http.HandlerFunc(httpHandler))
s.httpServer = &http.Server{
Addr: ":80",
Handler: r,
}
if err := s.httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
if err != http.ErrServerClosed {
return err
}
}
return nil
}
func (s *httpService) Stop() {
if s != nil {
_ = s.httpServer.Close()
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -9,6 +9,6 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@mermaid-js/mermaid-cli": "^8.6.4" "@mermaid-js/mermaid-cli": "^8.11.4"
} }
} }