Skip to content

Commit

Permalink
build: do not bundle management API docs by default
Browse files Browse the repository at this point in the history
This reduces the build time and binary size

GitOrigin-RevId: 527ff9f044ac347cbf96195f5e3560fd1680fde5
  • Loading branch information
oncilla committed Mar 26, 2022
1 parent a574cee commit ea83919
Show file tree
Hide file tree
Showing 24 changed files with 124 additions and 60 deletions.
14 changes: 14 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@io_bazel_rules_go//go:def.bzl", "nogo")
Expand Down Expand Up @@ -36,6 +37,19 @@ flake8_lint_config(
],
)

# Add a build flag to enable bundling the management API documentation with the
# binaries. This can be enabled by passing --//:mgmtapi_bundle_doc=true when
# invoking bazel
bool_flag(
name = "mgmtapi_bundle_doc",
build_setting_default = False,
)

config_setting(
name = "mgmtapi_bundle_doc_build",
flag_values = {":mgmtapi_bundle_doc": "true"},
)

# This is the SCION distributable package. It contains all (binary) services,
# and the required tools.
pkg_tar(
Expand Down
5 changes: 4 additions & 1 deletion control/mgmtapi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ go_library(
"spec.go",
":api_generated", # keep
],
embedsrcs = [":bundle"], # keep
embedsrcs = select({
"//:mgmtapi_bundle_doc_build": [":bundle"],
"//conditions:default": [":dummy.html"],
}), # keep
importpath = "github.com/scionproto/scion/control/mgmtapi",
visibility = ["//visibility:public"],
deps = [
Expand Down
Empty file added control/mgmtapi/dummy.html
Empty file.
8 changes: 0 additions & 8 deletions control/mgmtapi/index.html

This file was deleted.

10 changes: 7 additions & 3 deletions control/mgmtapi/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ package mgmtapi

import (
"bytes"
_ "embed"
"embed"
"net/http"
"time"

"github.com/scionproto/scion/private/mgmtapi"
)

//go:embed index.html
var index []byte
//go:embed *.html
var f embed.FS

var (
index = mgmtapi.ResolveIndex(f)

modtime = time.Now()

spec = func() []byte {
Expand Down
6 changes: 5 additions & 1 deletion daemon/mgmtapi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ go_library(
"spec.go",
":api_generated", # keep
],
embedsrcs = [":bundle"], # keep
embedsrcs = select({
"//:mgmtapi_bundle_doc_build": [":bundle"],
"//conditions:default": [":dummy.html"],
}), # keep
importpath = "github.com/scionproto/scion/daemon/mgmtapi",
visibility = ["//visibility:public"],
deps = [
"//private/mgmtapi:go_default_library",
"//private/mgmtapi/cppki/api:go_default_library",
"//private/mgmtapi/segments/api:go_default_library",
"@com_github_deepmap_oapi_codegen//pkg/runtime:go_default_library", # keep
Expand Down
Empty file added daemon/mgmtapi/dummy.html
Empty file.
8 changes: 0 additions & 8 deletions daemon/mgmtapi/index.html

This file was deleted.

10 changes: 7 additions & 3 deletions daemon/mgmtapi/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ package mgmtapi

import (
"bytes"
_ "embed"
"embed"
"net/http"
"time"

"github.com/scionproto/scion/private/mgmtapi"
)

//go:embed index.html
var index []byte
//go:embed *.html
var f embed.FS

var (
index = mgmtapi.ResolveIndex(f)

modtime = time.Now()

spec = func() []byte {
Expand Down
6 changes: 5 additions & 1 deletion dispatcher/mgmtapi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ go_library(
"spec.go",
":api_generated", # keep
],
embedsrcs = [":bundle"], # keep
embedsrcs = select({
"//:mgmtapi_bundle_doc_build": [":bundle"],
"//conditions:default": [":dummy.html"],
}), # keep
importpath = "github.com/scionproto/scion/dispatcher/mgmtapi",
visibility = ["//visibility:public"],
deps = [
"//private/mgmtapi:go_default_library",
"@com_github_getkin_kin_openapi//openapi3:go_default_library", # keep
"@com_github_go_chi_chi_v5//:go_default_library", # keep
],
Expand Down
Empty file added dispatcher/mgmtapi/dummy.html
Empty file.
8 changes: 0 additions & 8 deletions dispatcher/mgmtapi/index.html

This file was deleted.

10 changes: 7 additions & 3 deletions dispatcher/mgmtapi/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ package mgmtapi

import (
"bytes"
_ "embed"
"embed"
"net/http"
"time"

"github.com/scionproto/scion/private/mgmtapi"
)

//go:embed index.html
var index []byte
//go:embed *.html
var f embed.FS

var (
index = mgmtapi.ResolveIndex(f)

modtime = time.Now()

spec = func() []byte {
Expand Down
6 changes: 5 additions & 1 deletion gateway/mgmtapi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ go_library(
"spec.go",
":api_generated", # keep
],
embedsrcs = [":bundle"], # keep
embedsrcs = select({
"//:mgmtapi_bundle_doc_build": [":bundle"],
"//conditions:default": [":dummy.html"],
}), # keep
importpath = "github.com/scionproto/scion/gateway/mgmtapi",
visibility = ["//visibility:public"],
deps = [
"//private/mgmtapi:go_default_library",
"@com_github_deepmap_oapi_codegen//pkg/runtime:go_default_library", # keep
"@com_github_getkin_kin_openapi//openapi3:go_default_library", # keep
"@com_github_go_chi_chi_v5//:go_default_library", # keep
Expand Down
Empty file added gateway/mgmtapi/dummy.html
Empty file.
8 changes: 0 additions & 8 deletions gateway/mgmtapi/index.html

This file was deleted.

10 changes: 7 additions & 3 deletions gateway/mgmtapi/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ package mgmtapi

import (
"bytes"
_ "embed"
"embed"
"net/http"
"time"

"github.com/scionproto/scion/private/mgmtapi"
)

//go:embed index.html
var index []byte
//go:embed *.html
var f embed.FS

var (
index = mgmtapi.ResolveIndex(f)

modtime = time.Now()

spec = func() []byte {
Expand Down
2 changes: 2 additions & 0 deletions private/mgmtapi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ go_library(
"config.go",
"errors.go",
"helpers.go",
"spec.go",
],
embedsrcs = ["index.html"],
importpath = "github.com/scionproto/scion/private/mgmtapi",
visibility = ["//visibility:public"],
deps = ["//private/config:go_default_library"],
Expand Down
13 changes: 13 additions & 0 deletions private/mgmtapi/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>

<body>
<h1>Service Management UI not bundled</h1>

The service management UI is not bundled in this binary.

The OpenAPI spec is available at <a href="./spec.json">/spec.json</a>

</body>

</html>
37 changes: 37 additions & 0 deletions private/mgmtapi/spec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2022 Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package mgmtapi

import (
"embed"
"errors"
"io/fs"
)

//go:embed index.html
var index []byte

// ResolveIndex resolves the service management API index page from the passed
// filesystem. If it is not present, a placeholder is returned.
func ResolveIndex(f embed.FS) []byte {
raw, err := f.ReadFile("index.html")
if errors.Is(err, fs.ErrNotExist) {
return append([]byte(nil), index...)
}
if err != nil {
panic(err)
}
return raw
}
5 changes: 4 additions & 1 deletion router/mgmtapi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ go_library(
"spec.go",
":api_generated", # keep
],
embedsrcs = [":bundle"], # keep
embedsrcs = select({
"//:mgmtapi_bundle_doc_build": [":bundle"],
"//conditions:default": [":dummy.html"],
}), # keep
importpath = "github.com/scionproto/scion/router/mgmtapi",
visibility = ["//visibility:public"],
deps = [
Expand Down
Empty file added router/mgmtapi/dummy.html
Empty file.
8 changes: 0 additions & 8 deletions router/mgmtapi/index.html

This file was deleted.

10 changes: 7 additions & 3 deletions router/mgmtapi/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ package mgmtapi

import (
"bytes"
_ "embed"
"embed"
"net/http"
"time"

"github.com/scionproto/scion/private/mgmtapi"
)

//go:embed index.html
var index []byte
//go:embed *.html
var f embed.FS

var (
index = mgmtapi.ResolveIndex(f)

modtime = time.Now()

spec = func() []byte {
Expand Down

0 comments on commit ea83919

Please sign in to comment.