2019-11-02 21:32:58 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-04-09 08:05:17 +07:00
|
|
|
"os"
|
2019-11-02 21:32:58 +07:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2020-04-05 19:37:21 +07:00
|
|
|
|
|
|
|
"github.com/authelia/authelia/internal/utils"
|
2019-11-02 21:32:58 +07:00
|
|
|
)
|
|
|
|
|
2020-04-09 08:05:17 +07:00
|
|
|
//nolint:unparam
|
2019-11-02 21:32:58 +07:00
|
|
|
func waitUntilServiceLogDetected(
|
|
|
|
interval time.Duration,
|
|
|
|
timeout time.Duration,
|
|
|
|
dockerEnvironment *DockerEnvironment,
|
|
|
|
service string,
|
2019-11-19 06:37:36 +07:00
|
|
|
logPatterns []string) error {
|
2019-11-02 21:32:58 +07:00
|
|
|
log.Debug("Waiting for service " + service + " to be ready...")
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-11-02 21:32:58 +07: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-19 06:37:36 +07:00
|
|
|
for _, pattern := range logPatterns {
|
|
|
|
if strings.Contains(logs, pattern) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false, nil
|
2019-11-02 21:32:58 +07:00
|
|
|
})
|
|
|
|
|
|
|
|
fmt.Print("\n")
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-11-02 21:32:58 +07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-30 23:49:52 +07:00
|
|
|
func waitUntilAutheliaBackendIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
return waitUntilServiceLogDetected(
|
2019-11-02 21:32:58 +07:00
|
|
|
5*time.Second,
|
|
|
|
90*time.Second,
|
|
|
|
dockerEnvironment,
|
|
|
|
"authelia-backend",
|
2020-03-10 14:14:28 +07:00
|
|
|
[]string{"Authelia is listening for"})
|
2019-11-30 23:49:52 +07:00
|
|
|
}
|
2019-11-02 21:32:58 +07:00
|
|
|
|
2019-11-30 23:49:52 +07:00
|
|
|
func waitUntilAutheliaFrontendIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
return waitUntilServiceLogDetected(
|
2019-11-02 21:32:58 +07:00
|
|
|
5*time.Second,
|
|
|
|
90*time.Second,
|
|
|
|
dockerEnvironment,
|
|
|
|
"authelia-frontend",
|
2019-11-19 06:37:36 +07:00
|
|
|
[]string{"You can now view web in the browser.", "Compiled with warnings", "Compiled successfully!"})
|
2019-11-30 23:49:52 +07:00
|
|
|
}
|
2019-11-16 04:10:12 +07:00
|
|
|
|
2020-11-27 16:59:22 +07: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 23:49:52 +07:00
|
|
|
log.Info("Waiting for Authelia to be ready...")
|
|
|
|
|
|
|
|
if err := waitUntilAutheliaBackendIsReady(dockerEnvironment); err != nil {
|
2019-11-16 04:10:12 +07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-02 23:20:40 +07:00
|
|
|
if os.Getenv("CI") != stringTrue {
|
2020-04-09 08:05:17 +07:00
|
|
|
if err := waitUntilAutheliaFrontendIsReady(dockerEnvironment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-30 23:49:52 +07:00
|
|
|
}
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2020-11-27 16:59:22 +07:00
|
|
|
if suite == "ActiveDirectory" {
|
|
|
|
if err := waitUntilSambaIsReady(dockerEnvironment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-30 23:49:52 +07:00
|
|
|
log.Info("Authelia is now ready!")
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-11-16 04:10:12 +07:00
|
|
|
return nil
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|