From ffcc9c0c9cd0d0bb6aceaea9ba245cb595a92984 Mon Sep 17 00:00:00 2001 From: Erik Wilson Date: Wed, 20 Mar 2019 00:21:49 +0000 Subject: [PATCH] Package static assets Include static Helm assets in the build process needed for air-gap --- main.go | 1 + pkg/server/server.go | 7 ++++++- pkg/static/stage.go | 27 +++++++++++++++++++++++++++ scripts/download | 11 +++++++++-- types/codegen/main.go | 16 ++++++++++++++++ 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 pkg/static/stage.go diff --git a/main.go b/main.go index dc9211b98b..878b0a22aa 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ //go:generate go run types/codegen/cleanup/main.go //go:generate go run types/codegen/main.go //go:generate go fmt pkg/deploy/zz_generated_bindata.go +//go:generate go fmt pkg/static/zz_generated_bindata.go //go:generate go fmt pkg/openapi/zz_generated_bindata.go package main diff --git a/pkg/server/server.go b/pkg/server/server.go index 2c4e5cff6b..84106ab7ed 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -19,11 +19,12 @@ import ( "github.com/rancher/k3s/pkg/deploy" "github.com/rancher/k3s/pkg/helm" "github.com/rancher/k3s/pkg/servicelb" + "github.com/rancher/k3s/pkg/static" "github.com/rancher/k3s/pkg/tls" appsv1 "github.com/rancher/k3s/types/apis/apps/v1" batchv1 "github.com/rancher/k3s/types/apis/batch/v1" corev1 "github.com/rancher/k3s/types/apis/core/v1" - "github.com/rancher/k3s/types/apis/k3s.cattle.io/v1" + v1 "github.com/rancher/k3s/types/apis/k3s.cattle.io/v1" rbacv1 "github.com/rancher/k3s/types/apis/rbac.authorization.k8s.io/v1" "github.com/rancher/norman" "github.com/rancher/norman/pkg/clientaccess" @@ -118,6 +119,10 @@ func startNorman(ctx context.Context, config *Config) (string, error) { func(ctx context.Context) error { return servicelb.Register(ctx, norman.GetServer(ctx).K8sClient, !config.DisableServiceLB) }, + func(ctx context.Context) error { + dataDir := filepath.Join(controlConfig.DataDir, "static") + return static.Stage(dataDir) + }, func(ctx context.Context) error { dataDir := filepath.Join(controlConfig.DataDir, "manifests") templateVars := map[string]string{"%{CLUSTER_DNS}%": controlConfig.ClusterDNS.String()} diff --git a/pkg/static/stage.go b/pkg/static/stage.go new file mode 100644 index 0000000000..8bd177afd4 --- /dev/null +++ b/pkg/static/stage.go @@ -0,0 +1,27 @@ +package static + +import ( + "io/ioutil" + "os" + "path/filepath" + + "github.com/pkg/errors" + "github.com/sirupsen/logrus" +) + +func Stage(dataDir string) error { + for _, name := range AssetNames() { + content, err := Asset(name) + if err != nil { + return err + } + p := filepath.Join(dataDir, name) + logrus.Info("Writing static file: ", p) + os.MkdirAll(filepath.Dir(p), 0700) + if err := ioutil.WriteFile(p, content, 0600); err != nil { + return errors.Wrapf(err, "failed to write to %s", name) + } + } + + return nil +} diff --git a/scripts/download b/scripts/download index 25683be8b6..495e903518 100755 --- a/scripts/download +++ b/scripts/download @@ -1,10 +1,17 @@ #!/bin/bash -ROOT_VERSION=v0.0.1 - source $(dirname $0)/version.sh cd $(dirname $0)/.. +ROOT_VERSION=v0.0.1 +TRAEFIK_VERSION=1.64.0 +CHARTS_DIR=build/static/charts + +mkdir -p ${CHARTS_DIR} + curl --compressed -sfL https://github.com/ibuildthecloud/k3s-root/releases/download/${ROOT_VERSION}/k3s-root-${ARCH}.tar | tar xf - ln -sf pigz bin/unpigz + +TRAEFIK_FILE=traefik-${TRAEFIK_VERSION}.tgz +curl -sfL https://kubernetes-charts.storage.googleapis.com/${TRAEFIK_FILE} -o ${CHARTS_DIR}/${TRAEFIK_FILE} diff --git a/types/codegen/main.go b/types/codegen/main.go index 2351a2ad5f..db39225aa6 100644 --- a/types/codegen/main.go +++ b/types/codegen/main.go @@ -48,6 +48,22 @@ func main() { logrus.Fatal(err) } + bc = &bindata.Config{ + Input: []bindata.InputConfig{ + { + Path: "build/static", + Recursive: true, + }, + }, + Package: "static", + NoMetadata: true, + Prefix: "build/static/", + Output: "pkg/static/zz_generated_bindata.go", + } + if err := bindata.Translate(bc); err != nil { + logrus.Fatal(err) + } + bc = &bindata.Config{ Input: []bindata.InputConfig{ {