Skip to content

Commit

Permalink
Merge branch 'release/v1.3.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
axllent committed Jan 30, 2023
2 parents d101ec0 + 52bf19a commit df3b27b
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 217 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

Notable changes to Mailpit will be documented in this file.

## v1.3.7

### Feature
- Add Kubernetes API health (livez/readyz) endpoints

### Libs
- Upgrade to esbuild 0.17.5


## v1.3.6

### Bugfix
Expand Down
16 changes: 11 additions & 5 deletions esbuild.config.js → esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const { build } = require('esbuild')
const pluginVue = require('esbuild-plugin-vue-next')
const { sassPlugin } = require('esbuild-sass-plugin');
import * as esbuild from 'esbuild'
import pluginVue from 'esbuild-plugin-vue-next'
import { sassPlugin } from 'esbuild-sass-plugin'

const doWatch = process.env.WATCH == 'true' ? true : false;
const doMinify = process.env.MINIFY == 'true' ? true : false;

build({
const ctx = await esbuild.context({
entryPoints: ["server/ui-src/app.js"],
bundle: true,
watch: doWatch,
minify: doMinify,
sourcemap: false,
outfile: "server/ui/dist/app.js",
Expand All @@ -20,3 +19,10 @@ build({
},
logLevel: "info"
})

if (doWatch) {
await ctx.watch()
} else {
await ctx.rebuild()
ctx.dispose()
}
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e

VERSION=$(curl --silent --location --max-time "${TIMEOUT}" "https://api.github.com/repos/${GH_REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ $? -ne 0 ]; then
echo -ne "\nThere was an error trying to check what is the latest version of ssbak.\nPlease try again later.\n"
echo -ne "\nThere was an error trying to check what is the latest version of Mailpit.\nPlease try again later.\n"
exit 1
fi

Expand Down
402 changes: 201 additions & 201 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "0.0.0",
"private": true,
"scripts": {
"build": "node esbuild.config.js",
"watch": "WATCH=true node esbuild.config.js",
"package": "MINIFY=true node esbuild.config.js"
"build": "node esbuild.config.mjs",
"watch": "WATCH=true node esbuild.config.mjs",
"package": "MINIFY=true node esbuild.config.mjs"
},
"dependencies": {
"axios": "^1.2.1",
Expand All @@ -20,7 +20,7 @@
"devDependencies": {
"@popperjs/core": "^2.11.5",
"@vue/compiler-sfc": "^3.2.37",
"esbuild": "^0.16.1",
"esbuild": "^0.17.5",
"esbuild-plugin-vue-next": "^0.1.4",
"esbuild-sass-plugin": "^2.3.2"
}
Expand Down
8 changes: 8 additions & 0 deletions server/handlers/k8healthz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package handlers

import "net/http"

// Healthz is a liveness probe
func HealthzHandler(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
}
17 changes: 17 additions & 0 deletions server/handlers/k8sready.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package handlers

import (
"net/http"
"sync/atomic"
)

// ReadyzHandler is a ready probe that signals k8s to be able to retrieve traffic
func ReadyzHandler(isReady *atomic.Value) http.HandlerFunc {
return func(w http.ResponseWriter, _ *http.Request) {
if isReady == nil || !isReady.Load().(bool) {
http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable)
return
}
w.WriteHeader(http.StatusOK)
}
}
24 changes: 18 additions & 6 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@ package server
import (
"compress/gzip"
"embed"
"io"
"io/fs"
"net/http"
"os"
"strings"

"github.com/axllent/mailpit/config"
"github.com/axllent/mailpit/server/apiv1"
"github.com/axllent/mailpit/server/handlers"
"github.com/axllent/mailpit/server/websockets"
"github.com/axllent/mailpit/utils/logger"
"github.com/gorilla/mux"
"io"
"io/fs"
"net/http"
"os"
"strings"
"sync/atomic"
)

//go:embed ui
var embeddedFS embed.FS

// Listen will start the httpd
func Listen() {
isReady := &atomic.Value{}
isReady.Store(false)

serverRoot, err := fs.Sub(embeddedFS, "ui")
if err != nil {
logger.Log().Errorf("[http] %s", err)
Expand All @@ -33,6 +37,10 @@ func Listen() {

r := defaultRoutes()

// kubernetes probes
r.HandleFunc("/livez", handlers.HealthzHandler)
r.HandleFunc("/readyz", handlers.ReadyzHandler(isReady))

// web UI websocket
r.HandleFunc(config.Webroot+"api/events", apiWebsocket).Methods("GET")

Expand All @@ -51,13 +59,17 @@ func Listen() {
logger.Log().Info("[http] enabling web UI basic authentication")
}

// Mark the application here as ready
isReady.Store(true)

if config.UISSLCert != "" && config.UISSLKey != "" {
logger.Log().Infof("[http] starting secure server on https://%s%s", config.HTTPListen, config.Webroot)
logger.Log().Fatal(http.ListenAndServeTLS(config.HTTPListen, config.UISSLCert, config.UISSLKey, nil))
} else {
logger.Log().Infof("[http] starting server on http://%s%s", config.HTTPListen, config.Webroot)
logger.Log().Fatal(http.ListenAndServe(config.HTTPListen, nil))
}

}

func defaultRoutes() *mux.Router {
Expand Down

0 comments on commit df3b27b

Please sign in to comment.