2019-10-29 20:54:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
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"
|
2020-04-05 12:37:21 +00:00
|
|
|
|
|
|
|
"github.com/authelia/authelia/internal/utils"
|
2019-10-29 20:54:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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() {
|
2020-05-02 05:06:39 +00:00
|
|
|
// Install npm dependencies.
|
2019-12-27 11:07:53 +00:00
|
|
|
cmd := utils.CommandWithStdout("yarn", "install")
|
2020-05-02 16:20:40 +00:00
|
|
|
cmd.Dir = webDirectory
|
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)
|
2019-10-29 20:54:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Then build the frontend.
|
2019-12-27 11:07:53 +00:00
|
|
|
cmd = utils.CommandWithStdout("yarn", "build")
|
2020-05-02 16:20:40 +00:00
|
|
|
cmd.Dir = webDirectory
|
2020-04-21 00:23:28 +00:00
|
|
|
cmd.Env = append(os.Environ(), "INLINE_RUNTIME_CHUNK=false")
|
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)
|
|
|
|
}
|
|
|
|
|
2020-04-28 14:07:20 +00:00
|
|
|
if err := os.Rename("web/build", "./public_html"); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateEmbeddedAssets() {
|
|
|
|
cmd := utils.CommandWithStdout("go", "get", "-u", "aletheia.icu/broccoli")
|
|
|
|
|
|
|
|
err := cmd.Run()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = utils.CommandWithStdout("go", "generate", ".")
|
|
|
|
cmd.Dir = "internal/server"
|
|
|
|
|
|
|
|
err = cmd.Run()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.Rename("./public_html", OutputDir+"/public_html"); err != nil {
|
2019-11-02 14:32:58 +00:00
|
|
|
log.Fatal(err)
|
2019-10-29 20:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Build build Authelia.
|
2019-10-29 20:54:47 +00:00
|
|
|
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 frontend...")
|
2019-10-29 20:54:47 +00:00
|
|
|
buildFrontend()
|
2020-04-28 14:07:20 +00:00
|
|
|
|
|
|
|
log.Debug("Building Authelia Go binary...")
|
|
|
|
generateEmbeddedAssets()
|
|
|
|
buildAutheliaBinary()
|
2019-10-29 20:54:47 +00:00
|
|
|
}
|