mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License.AGPL.txt in the project root for license information.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
log "github.com/gitpod-io/gitpod/common-go/log"
|
|
"github.com/gitpod-io/gitpod/image-builder/bob/pkg/builder"
|
|
)
|
|
|
|
// buildCmd represents the build command
|
|
var buildCmd = &cobra.Command{
|
|
Use: "build",
|
|
Short: "Runs the image build and is configured using environment variables (see pkg/builder/config.go for details)",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
log.Init("bob", "", true, true)
|
|
log := log.WithField("command", "build")
|
|
|
|
t0 := time.Now()
|
|
if os.Geteuid() != 0 {
|
|
log.Fatal("must run as root")
|
|
}
|
|
|
|
// give the headless listener some time to attach
|
|
time.Sleep(1 * time.Second)
|
|
|
|
cfg, err := builder.GetConfigFromEnv()
|
|
if err != nil {
|
|
log.WithError(err).Fatal("cannot get config")
|
|
return
|
|
}
|
|
|
|
b := &builder.Builder{
|
|
Config: cfg,
|
|
}
|
|
err = b.Build()
|
|
if err != nil {
|
|
log.WithError(err).Error("build failed")
|
|
|
|
// make sure we're running long enough to have our logs read
|
|
if dt := time.Since(t0); dt < 5*time.Second {
|
|
time.Sleep(10 * time.Second)
|
|
}
|
|
|
|
os.Exit(1)
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(buildCmd)
|
|
}
|