mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
a991379a74
Some tests are not fully rewritten in Go, a typescript wrapper is called instead until we remove the remaining TS tests and dependencies. Also, dockerize every components (mainly Authelia backend, frontend and kind) so that the project does not interfere with user host anymore (open ports for instance). The only remaining intrusive change is the one done during bootstrap to add entries in /etc/hosts. It will soon be avoided using authelia.com domain that I own.
112 lines
2.4 KiB
Go
112 lines
2.4 KiB
Go
package suites
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/clems4ever/authelia/utils"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var kubernetesSuiteName = "Kubernetes"
|
|
|
|
func init() {
|
|
kind := Kind{}
|
|
kubectl := Kubectl{}
|
|
|
|
setup := func(suitePath string) error {
|
|
exists, err := kind.ClusterExists()
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if exists {
|
|
log.Debug("Kubernetes cluster already exists")
|
|
} else {
|
|
err = kind.CreateCluster()
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
log.Debug("Building authelia:dist image...")
|
|
if err := utils.Shell("authelia-scripts docker build").Run(); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debug("Loading images into Kubernetes container...")
|
|
if err = loadDockerImages(); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debug("Deploying thirdparties...")
|
|
if err = kubectl.DeployThirdparties(); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debug("Waiting for services to be ready...")
|
|
if err := waitAllPodsAreReady(5 * time.Minute); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debug("Deploying Authelia...")
|
|
if err = kubectl.DeployAuthelia(); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debug("Waiting for services to be ready...")
|
|
if err := waitAllPodsAreReady(2 * time.Minute); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debug("Starting proxy...")
|
|
if err := kubectl.StartProxy(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
teardown := func(suitePath string) error {
|
|
kubectl.StopProxy()
|
|
return kind.DeleteCluster()
|
|
}
|
|
|
|
GlobalRegistry.Register(kubernetesSuiteName, Suite{
|
|
TestTimeout: 60 * time.Second,
|
|
SetUp: setup,
|
|
SetUpTimeout: 10 * time.Minute,
|
|
TearDown: teardown,
|
|
TearDownTimeout: 10 * time.Minute,
|
|
Description: "This suite has been created to test Authelia in a Kubernetes context and using nginx as the ingress controller.",
|
|
})
|
|
}
|
|
|
|
func loadDockerImages() error {
|
|
kind := Kind{}
|
|
images := []string{"authelia:dist", "authelia-example-backend"}
|
|
|
|
for _, image := range images {
|
|
err := kind.LoadImage(image)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func waitAllPodsAreReady(timeout time.Duration) error {
|
|
kubectl := Kubectl{}
|
|
// Wait in case the deployment has just been done and some services do not appear in kubectl logs.
|
|
time.Sleep(1 * time.Second)
|
|
fmt.Println("Check services are running")
|
|
if err := kubectl.WaitPodsReady(timeout); err != nil {
|
|
return err
|
|
}
|
|
fmt.Println("All pods are ready")
|
|
return nil
|
|
}
|