2019-10-30 03:54:47 +07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2021-06-18 11:35:43 +07:00
|
|
|
"strings"
|
2019-10-30 03:54:47 +07:00
|
|
|
|
2019-11-02 21:32:58 +07:00
|
|
|
log "github.com/sirupsen/logrus"
|
2019-10-30 03:54:47 +07:00
|
|
|
"github.com/spf13/cobra"
|
2020-04-05 19:37:21 +07:00
|
|
|
|
|
|
|
"github.com/authelia/authelia/internal/utils"
|
2019-10-30 03:54:47 +07:00
|
|
|
)
|
|
|
|
|
2021-06-18 11:35:43 +07:00
|
|
|
func buildAutheliaBinary(xflags []string) {
|
|
|
|
cmd := utils.CommandWithStdout("go", "build", "-o", "../../"+OutputDir+"/authelia", "-ldflags", strings.Join(xflags, " "))
|
2019-11-02 03:15:58 +07:00
|
|
|
cmd.Dir = "cmd/authelia"
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-10-30 03:54:47 +07:00
|
|
|
cmd.Env = append(os.Environ(),
|
2021-06-22 07:45:33 +07:00
|
|
|
"GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=0")
|
2019-10-30 03:54:47 +07:00
|
|
|
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
2021-01-03 11:28:46 +07:00
|
|
|
log.Fatal(err)
|
2019-10-30 03:54:47 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildFrontend() {
|
2019-12-27 18:07:53 +07:00
|
|
|
cmd := utils.CommandWithStdout("yarn", "install")
|
2020-05-02 23:20:40 +07:00
|
|
|
cmd.Dir = webDirectory
|
2019-10-30 03:54:47 +07:00
|
|
|
|
2021-01-03 11:28:46 +07:00
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
2019-11-02 21:32:58 +07:00
|
|
|
log.Fatal(err)
|
2019-10-30 03:54:47 +07:00
|
|
|
}
|
|
|
|
|
2019-12-27 18:07:53 +07:00
|
|
|
cmd = utils.CommandWithStdout("yarn", "build")
|
2020-05-02 23:20:40 +07:00
|
|
|
cmd.Dir = webDirectory
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2020-04-21 07:23:28 +07:00
|
|
|
cmd.Env = append(os.Environ(), "INLINE_RUNTIME_CHUNK=false")
|
2019-10-30 03:54:47 +07:00
|
|
|
|
2021-01-03 11:28:46 +07:00
|
|
|
err = cmd.Run()
|
|
|
|
if err != nil {
|
2019-11-02 21:32:58 +07:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2021-01-03 11:28:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func buildSwagger() {
|
2021-08-02 11:55:34 +07:00
|
|
|
swaggerVer := "3.51.2"
|
2021-01-03 11:28:46 +07:00
|
|
|
cmd := utils.CommandWithStdout("bash", "-c", "wget -q https://github.com/swagger-api/swagger-ui/archive/v"+swaggerVer+".tar.gz -O ./v"+swaggerVer+".tar.gz")
|
|
|
|
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-02-22 06:07:06 +07:00
|
|
|
cmd = utils.CommandWithStdout("cp", "-r", "api", "internal/server/public_html")
|
2021-01-03 11:28:46 +07:00
|
|
|
|
|
|
|
err = cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-02-22 06:07:06 +07:00
|
|
|
cmd = utils.CommandWithStdout("tar", "-C", "internal/server/public_html/api", "--exclude=index.html", "--strip-components=2", "-xf", "v"+swaggerVer+".tar.gz", "swagger-ui-"+swaggerVer+"/dist")
|
2021-01-03 11:28:46 +07:00
|
|
|
|
|
|
|
err = cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = utils.CommandWithStdout("rm", "./v"+swaggerVer+".tar.gz")
|
|
|
|
|
|
|
|
err = cmd.Run()
|
|
|
|
if err != nil {
|
2020-04-28 21:07:20 +07:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 06:07:06 +07:00
|
|
|
func cleanAssets() {
|
|
|
|
if err := os.Rename("internal/server/public_html", OutputDir+"/public_html"); err != nil {
|
2021-01-03 11:28:46 +07:00
|
|
|
log.Fatal(err)
|
2020-04-28 21:07:20 +07:00
|
|
|
}
|
|
|
|
|
2021-02-22 06:07:06 +07:00
|
|
|
cmd := utils.CommandWithStdout("mkdir", "-p", "internal/server/public_html/api")
|
2020-06-17 13:25:35 +07:00
|
|
|
|
2021-02-22 06:07:06 +07:00
|
|
|
if err := cmd.Run(); err != nil {
|
2021-01-03 11:28:46 +07:00
|
|
|
log.Fatal(err)
|
2020-06-17 13:25:35 +07:00
|
|
|
}
|
|
|
|
|
2021-02-22 06:07:06 +07:00
|
|
|
cmd = utils.CommandWithStdout("bash", "-c", "touch internal/server/public_html/{index.html,api/index.html,api/openapi.yml}")
|
2020-04-28 21:07:20 +07:00
|
|
|
|
2021-02-22 06:07:06 +07:00
|
|
|
if err := cmd.Run(); err != nil {
|
2019-11-02 21:32:58 +07:00
|
|
|
log.Fatal(err)
|
2019-10-30 03:54:47 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 12:06:39 +07:00
|
|
|
// Build build Authelia.
|
2019-10-30 03:54:47 +07:00
|
|
|
func Build(cobraCmd *cobra.Command, args []string) {
|
2019-11-02 21:32:58 +07:00
|
|
|
log.Info("Building Authelia...")
|
|
|
|
|
2019-10-30 03:54:47 +07:00
|
|
|
Clean(cobraCmd, args)
|
|
|
|
|
2021-06-18 11:35:43 +07:00
|
|
|
xflags, err := getXFlags("", "0", "")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-11-02 21:32:58 +07:00
|
|
|
log.Debug("Creating `" + OutputDir + "` directory")
|
2021-06-18 11:35:43 +07:00
|
|
|
err = os.MkdirAll(OutputDir, os.ModePerm)
|
2019-10-30 03:54:47 +07:00
|
|
|
|
|
|
|
if err != nil {
|
2021-01-03 11:28:46 +07:00
|
|
|
log.Fatal(err)
|
2019-10-30 03:54:47 +07:00
|
|
|
}
|
|
|
|
|
2019-11-02 21:32:58 +07:00
|
|
|
log.Debug("Building Authelia frontend...")
|
2019-10-30 03:54:47 +07:00
|
|
|
buildFrontend()
|
2020-04-28 21:07:20 +07:00
|
|
|
|
2021-01-03 11:28:46 +07:00
|
|
|
log.Debug("Building swagger-ui frontend...")
|
|
|
|
buildSwagger()
|
|
|
|
|
2021-06-25 18:53:20 +07:00
|
|
|
buildkite, _ := cobraCmd.Flags().GetBool("buildkite")
|
|
|
|
if buildkite {
|
|
|
|
log.Debug("Buildkite job detected, skipping Authelia Go binary build")
|
|
|
|
} else {
|
|
|
|
log.Debug("Building Authelia Go binary...")
|
|
|
|
buildAutheliaBinary(xflags)
|
|
|
|
}
|
|
|
|
|
2021-02-22 06:07:06 +07:00
|
|
|
cleanAssets()
|
2019-10-30 03:54:47 +07:00
|
|
|
}
|