2019-11-02 14:32:58 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-04-09 01:05:17 +00:00
|
|
|
"os"
|
2019-11-02 14:32:58 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2020-04-05 12:37:21 +00:00
|
|
|
|
|
|
|
"github.com/authelia/authelia/internal/utils"
|
2019-11-02 14:32:58 +00:00
|
|
|
)
|
|
|
|
|
2020-04-09 01:05:17 +00:00
|
|
|
//nolint:unparam
|
2019-11-02 14:32:58 +00:00
|
|
|
func waitUntilServiceLogDetected(
|
|
|
|
interval time.Duration,
|
|
|
|
timeout time.Duration,
|
|
|
|
dockerEnvironment *DockerEnvironment,
|
|
|
|
service string,
|
2019-11-18 23:37:36 +00:00
|
|
|
logPatterns []string) error {
|
2019-11-02 14:32:58 +00:00
|
|
|
log.Debug("Waiting for service " + service + " to be ready...")
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2019-11-02 14:32:58 +00:00
|
|
|
err := utils.CheckUntil(5*time.Second, 1*time.Minute, func() (bool, error) {
|
|
|
|
logs, err := dockerEnvironment.Logs(service, []string{"--tail", "20"})
|
|
|
|
fmt.Printf(".")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2019-11-18 23:37:36 +00:00
|
|
|
for _, pattern := range logPatterns {
|
|
|
|
if strings.Contains(logs, pattern) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false, nil
|
2019-11-02 14:32:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
fmt.Print("\n")
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2019-11-02 14:32:58 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:49:52 +00:00
|
|
|
func waitUntilAutheliaBackendIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
return waitUntilServiceLogDetected(
|
2019-11-02 14:32:58 +00:00
|
|
|
5*time.Second,
|
|
|
|
90*time.Second,
|
|
|
|
dockerEnvironment,
|
|
|
|
"authelia-backend",
|
2021-08-03 09:55:21 +00:00
|
|
|
[]string{"Listening for"})
|
2019-11-30 16:49:52 +00:00
|
|
|
}
|
2019-11-02 14:32:58 +00:00
|
|
|
|
2019-11-30 16:49:52 +00:00
|
|
|
func waitUntilAutheliaFrontendIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
return waitUntilServiceLogDetected(
|
2019-11-02 14:32:58 +00:00
|
|
|
5*time.Second,
|
|
|
|
90*time.Second,
|
|
|
|
dockerEnvironment,
|
|
|
|
"authelia-frontend",
|
2019-11-18 23:37:36 +00:00
|
|
|
[]string{"You can now view web in the browser.", "Compiled with warnings", "Compiled successfully!"})
|
2019-11-30 16:49:52 +00:00
|
|
|
}
|
2019-11-15 21:10:12 +00:00
|
|
|
|
2020-11-27 09:59:22 +00:00
|
|
|
func waitUntilSambaIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
return waitUntilServiceLogDetected(
|
|
|
|
5*time.Second,
|
|
|
|
90*time.Second,
|
|
|
|
dockerEnvironment,
|
|
|
|
"sambaldap",
|
|
|
|
[]string{"samba entered RUNNING state"})
|
|
|
|
}
|
|
|
|
|
|
|
|
func waitUntilAutheliaIsReady(dockerEnvironment *DockerEnvironment, suite string) error {
|
2019-11-30 16:49:52 +00:00
|
|
|
log.Info("Waiting for Authelia to be ready...")
|
|
|
|
|
|
|
|
if err := waitUntilAutheliaBackendIsReady(dockerEnvironment); err != nil {
|
2019-11-15 21:10:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-01-16 10:25:02 +00:00
|
|
|
if os.Getenv("CI") != stringTrue && suite != "CLI" {
|
2020-04-09 01:05:17 +00:00
|
|
|
if err := waitUntilAutheliaFrontendIsReady(dockerEnvironment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-30 16:49:52 +00:00
|
|
|
}
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2020-11-27 09:59:22 +00:00
|
|
|
if suite == "ActiveDirectory" {
|
|
|
|
if err := waitUntilSambaIsReady(dockerEnvironment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:49:52 +00:00
|
|
|
log.Info("Authelia is now ready!")
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2019-11-15 21:10:12 +00:00
|
|
|
return nil
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|