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