Serve FontAwesome & Bootstrap ourself

Instead of using external CDNs for Bootstrap and FontAwesome, this patch
makes Alertmanager serve these libraries itself.
This commit is contained in:
Max Leonard Inden 2017-06-07 15:50:44 +02:00
parent 2cf38e4c2e
commit dd7ffe0515
No known key found for this signature in database
GPG Key ID: 5403C5464810BC26
18 changed files with 5324 additions and 31 deletions

View File

@ -60,7 +60,12 @@ assets:
-@$(GO) get -u github.com/jteeuwen/go-bindata/...
# Using "-mode 420" and "-modtime 1" to make assets make target deterministic.
# It sets all file permissions and time stamps to 420 and 1
@go-bindata $(bindata_flags) -mode 420 -modtime 1 -pkg ui -o ui/bindata.go ui/app/script.js ui/app/index.html ui/app/favicon.ico
@go-bindata $(bindata_flags) -mode 420 -modtime 1 -pkg ui -o \
ui/bindata.go ui/app/script.js \
ui/app/index.html \
ui/app/favicon.ico \
ui/lib/...
@go-bindata $(bindata_flags) -mode 420 -modtime 1 -pkg deftmpl -o template/internal/deftmpl/bindata.go template/default.tmpl
promu:

View File

@ -4,8 +4,6 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Alertmanager</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://use.fontawesome.com/b7508bb100.js"></script>
</head>
<body>
<script>

View File

@ -66,7 +66,13 @@ init flags location =
if prod then
Api.makeApiUrl location.pathname
else
Api.makeApiUrl "http://localhost:9093"
Api.makeApiUrl "http://localhost:9093/"
libUrl =
if prod then
location.pathname
else
"http://localhost:9093/"
in
update (urlUpdate location)
(Model
@ -79,6 +85,8 @@ init flags location =
initStatusModel
location.pathname
apiUrl
libUrl
Loading
Loading
)

View File

@ -20,7 +20,9 @@ type alias Model =
, status : StatusModel
, basePath : String
, apiUrl : String
, libUrl : String
, bootstrapCSS : ApiData String
, fontAwesomeCSS : ApiData String
}
@ -42,6 +44,7 @@ type Msg
| RedirectAlerts
| UpdateFilter String
| BootstrapCSSLoaded (ApiData String)
| FontAwesomeCSSLoaded (ApiData String)
type Route

View File

@ -129,3 +129,6 @@ update msg ({ basePath, apiUrl } as model) =
BootstrapCSSLoaded css ->
( { model | bootstrapCSS = css }, Cmd.none )
FontAwesomeCSSLoaded css ->
( { model | fontAwesomeCSS = css }, Cmd.none )

View File

@ -4,7 +4,7 @@ import Html exposing (Html, node, text, div)
import Html.Attributes exposing (class, rel, href, src, style)
import Html.Events exposing (on)
import Json.Decode exposing (succeed)
import Types exposing (Msg(MsgForSilenceForm, MsgForSilenceView, BootstrapCSSLoaded), Model, Route(..))
import Types exposing (Msg(MsgForSilenceForm, MsgForSilenceView, BootstrapCSSLoaded, FontAwesomeCSSLoaded), Model, Route(..))
import Utils.Views exposing (error, loading)
import Utils.Types exposing (ApiData(Failure, Success))
import Views.SilenceList.Views as SilenceList
@ -19,42 +19,49 @@ import Views.NavBar.Views exposing (navBar)
view : Model -> Html Msg
view model =
div []
[ renderLink "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"
, fontAwesome
, case model.bootstrapCSS of
Success _ ->
[ renderCSS model.libUrl
, case ( model.bootstrapCSS, model.fontAwesomeCSS ) of
( Success _, Success _ ) ->
div []
[ navBar model.route
, div [ class "container pb-4" ] [ currentView model ]
]
Failure err ->
div []
[ div [ style [ ( "padding", "40px" ), ( "color", "red" ) ] ] [ text err ]
, navBar model.route
, div [ class "container pb-4" ] [ currentView model ]
]
( Failure err, _ ) ->
failureView model err
( _, Failure err ) ->
failureView model err
_ ->
text ""
]
renderLink : String -> Html Msg
renderLink url =
failureView : Model -> String -> Html Msg
failureView model err =
div []
[ div [ style [ ( "padding", "40px" ), ( "color", "red" ) ] ] [ text err ]
, navBar model.route
, div [ class "container pb-4" ] [ currentView model ]
]
renderCSS : String -> Html Msg
renderCSS assetsUrl =
div []
[ cssNode (assetsUrl ++ "lib/bootstrap-4.0.0-alpha.6-dist/css/bootstrap.min.css") BootstrapCSSLoaded
, cssNode (assetsUrl ++ "lib/font-awesome-4.7.0/css/font-awesome.min.css") FontAwesomeCSSLoaded
]
cssNode : String -> (ApiData String -> Msg) -> Html Msg
cssNode url msg =
node "link"
[ href url
, rel "stylesheet"
, on "load" (succeed (BootstrapCSSLoaded (Success url)))
, on "error" (succeed (BootstrapCSSLoaded (Failure ("Failed to load Bootstrap CSS from: " ++ url))))
]
[]
fontAwesome : Html msg
fontAwesome =
node "script"
[ src "https://use.fontawesome.com/b7508bb100.js"
, on "load" (succeed (msg (Success url)))
, on "error" (succeed (msg (Failure ("Failed to load CSS from: " ++ url))))
]
[]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 434 KiB

View File

@ -18,6 +18,7 @@ import (
"io"
"net/http"
_ "net/http/pprof" // Comment this line to disable pprof endpoint.
"path/filepath"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@ -62,6 +63,13 @@ func Register(r *route.Router, reloadCh chan<- struct{}) {
serveAsset(w, req, "ui/app/favicon.ico")
}))
r.Get("/lib/*filepath", ihf("lib_files",
func(w http.ResponseWriter, req *http.Request) {
fp := route.Param(req.Context(), "filepath")
serveAsset(w, req, filepath.Join("ui/lib", fp))
},
))
r.Post("/-/reload", func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("Reloading configuration file..."))
reloadCh <- struct{}{}