authelia/cmd/authelia-scripts/cmd_build.go

65 lines
1.2 KiB
Go
Raw Normal View History

package main
import (
"os"
"github.com/authelia/authelia/internal/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func buildAutheliaBinary() {
cmd := utils.CommandWithStdout("go", "build", "-o", "../../"+OutputDir+"/authelia")
cmd.Dir = "cmd/authelia"
cmd.Env = append(os.Environ(),
"GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=1")
err := cmd.Run()
if err != nil {
panic(err)
}
}
func buildFrontend() {
// Install npm dependencies
cmd := utils.CommandWithStdout("npm", "ci")
2019-11-30 16:49:52 +00:00
cmd.Dir = "web"
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
// Then build the frontend
cmd = utils.CommandWithStdout("npm", "run", "build")
2019-11-30 16:49:52 +00:00
cmd.Dir = "web"
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
2019-11-30 16:49:52 +00:00
if err := os.Rename("web/build", OutputDir+"/public_html"); err != nil {
log.Fatal(err)
}
}
// Build build Authelia
func Build(cobraCmd *cobra.Command, args []string) {
log.Info("Building Authelia...")
Clean(cobraCmd, args)
log.Debug("Creating `" + OutputDir + "` directory")
err := os.MkdirAll(OutputDir, os.ModePerm)
if err != nil {
panic(err)
}
log.Debug("Building Authelia Go binary...")
buildAutheliaBinary()
log.Debug("Building Authelia frontend...")
buildFrontend()
}