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...")
|
|
|
|
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")
|
|
|
|
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",
|
2020-03-10 07:14:28 +00:00
|
|
|
[]string{"Authelia is 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
|
|
|
|
2019-11-30 16:49:52 +00:00
|
|
|
func waitUntilAutheliaIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
log.Info("Waiting for Authelia to be ready...")
|
|
|
|
|
|
|
|
if err := waitUntilAutheliaBackendIsReady(dockerEnvironment); err != nil {
|
2019-11-15 21:10:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-09 01:05:17 +00:00
|
|
|
if os.Getenv("CI") != "true" {
|
|
|
|
if err := waitUntilAutheliaFrontendIsReady(dockerEnvironment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-30 16:49:52 +00:00
|
|
|
}
|
|
|
|
log.Info("Authelia is now ready!")
|
2019-11-15 21:10:12 +00:00
|
|
|
return nil
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|