diff --git a/cmd/doco-cd/http_handler.go b/cmd/doco-cd/http_handler.go index ce7a003..5ff57c3 100644 --- a/cmd/doco-cd/http_handler.go +++ b/cmd/doco-cd/http_handler.go @@ -192,7 +192,7 @@ func (h *handlerData) WebhookHandler(w http.ResponseWriter, r *http.Request) { } func (h *handlerData) HealthCheckHandler(w http.ResponseWriter, _ *http.Request) { - err := docker.VerifySocketConnection(h.appConfig.DockerAPIVersion) + err := docker.VerifySocketConnection() if err != nil { h.log.Error(docker.ErrDockerSocketConnectionFailed.Error(), logger.ErrAttr(err)) JSONError(w, "unhealthy", err.Error(), "", http.StatusServiceUnavailable) diff --git a/cmd/doco-cd/main.go b/cmd/doco-cd/main.go index 33ea964..4819e2c 100644 --- a/cmd/doco-cd/main.go +++ b/cmd/doco-cd/main.go @@ -44,7 +44,7 @@ func main() { log.Info("starting application", slog.String("version", Version), slog.String("log_level", c.LogLevel)) // Test/verify the connection to the docker socket - err = docker.VerifySocketConnection(c.DockerAPIVersion) + err = docker.VerifySocketConnection() if err != nil { log.Critical(docker.ErrDockerSocketConnectionFailed.Error(), logger.ErrAttr(err)) } diff --git a/cmd/doco-cd/main_test.go b/cmd/doco-cd/main_test.go index 2b6171b..818330f 100644 --- a/cmd/doco-cd/main_test.go +++ b/cmd/doco-cd/main_test.go @@ -182,7 +182,7 @@ func TestHandleEvent(t *testing.T) { } }) - err = docker.VerifySocketConnection(appConfig.DockerAPIVersion) + err = docker.VerifySocketConnection() if err != nil { t.Fatalf("Failed to verify docker socket connection: %v", err) } diff --git a/docs b/docs index a41ebb0..5921808 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit a41ebb088fcd5f8bd9487e43eb9d956da8cc55d2 +Subproject commit 59218088b343f382c3b112bdd9c73f65e6693dc8 diff --git a/go.mod b/go.mod index d575e81..a1751ce 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/caarlos0/env/v11 v11.2.2 github.com/compose-spec/compose-go/v2 v2.4.3 github.com/creasty/defaults v1.8.0 - github.com/docker/cli 8c22315e3123 + github.com/docker/cli v27.3.2-0.20241008150905-cb3048fbebb1+incompatible github.com/docker/compose/v2 v2.30.1 github.com/docker/docker v27.3.1+incompatible github.com/go-git/go-git/v5 v5.12.0 diff --git a/internal/config/app_config.go b/internal/config/app_config.go index 79deae4..02d82fa 100644 --- a/internal/config/app_config.go +++ b/internal/config/app_config.go @@ -10,20 +10,16 @@ import ( // AppConfig is used to configure this application type AppConfig struct { - LogLevel string `env:"LOG_LEVEL,required" envDefault:"info"` // LogLevel is the log level for the application - HttpPort uint16 `env:"HTTP_PORT,required" envDefault:"80" validate:"min=1,max=65535"` // HttpPort is the port the HTTP server will listen on - WebhookSecret string `env:"WEBHOOK_SECRET,required"` // WebhookSecret is the secret used to authenticate the webhook - GitAccessToken string `env:"GIT_ACCESS_TOKEN"` // GitAccessToken is the access token used to authenticate with the Git server (e.g. GitHub) for private repositories - AuthType string `env:"AUTH_TYPE" envDefault:"oauth2"` // AuthType is the type of authentication to use when cloning repositories - SkipTLSVerification bool `env:"SKIP_TLS_VERIFICATION" envDefault:"false"` // SkipTLSVerification skips the TLS verification when cloning repositories. - DockerAPIVersion string `env:"DOCKER_API_VERSION" envDefault:"v1.40" validate:"regexp=^v[0-9]+\\.[0-9]+$"` // DockerAPIVersion is the version of the Docker API to use - DockerQuietDeploy bool `env:"DOCKER_QUIET_DEPLOY" envDefault:"true"` // DockerQuietDeploy suppresses the status output of dockerCli in deployments (e.g. pull, create, start) + LogLevel string `env:"LOG_LEVEL,required" envDefault:"info"` // LogLevel is the log level for the application + HttpPort uint16 `env:"HTTP_PORT,required" envDefault:"80" validate:"min=1,max=65535"` // HttpPort is the port the HTTP server will listen on + WebhookSecret string `env:"WEBHOOK_SECRET,required"` // WebhookSecret is the secret used to authenticate the webhook + GitAccessToken string `env:"GIT_ACCESS_TOKEN"` // GitAccessToken is the access token used to authenticate with the Git server (e.g. GitHub) for private repositories + AuthType string `env:"AUTH_TYPE" envDefault:"oauth2"` // AuthType is the type of authentication to use when cloning repositories + SkipTLSVerification bool `env:"SKIP_TLS_VERIFICATION" envDefault:"false"` // SkipTLSVerification skips the TLS verification when cloning repositories. + DockerQuietDeploy bool `env:"DOCKER_QUIET_DEPLOY" envDefault:"true"` // DockerQuietDeploy suppresses the status output of dockerCli in deployments (e.g. pull, create, start) } -var ( - ErrInvalidLogLevel = validator.TextErr{Err: errors.New("invalid log level, must be one of debug, info, warn, error")} - ErrInvalidDockerAPIVersion = validator.TextErr{Err: errors.New("invalid Docker API version format, must be e.g. v1.40")} -) +var ErrInvalidLogLevel = validator.TextErr{Err: errors.New("invalid log level, must be one of debug, info, warn, error")} // GetAppConfig returns the configuration func GetAppConfig() (*AppConfig, error) { @@ -38,10 +34,6 @@ func GetAppConfig() (*AppConfig, error) { } if err := validator.Validate(cfg); err != nil { - if strings.Contains(err.Error(), "DockerAPIVersion") { - return nil, ErrInvalidDockerAPIVersion - } - return nil, err } diff --git a/internal/config/app_config_test.go b/internal/config/app_config_test.go index 2c8f206..5d1c0a7 100644 --- a/internal/config/app_config_test.go +++ b/internal/config/app_config_test.go @@ -20,7 +20,6 @@ func TestGetAppConfig(t *testing.T) { "HTTP_PORT": "8080", "WEBHOOK_SECRET": "secret", "AUTH_TYPE": "oauth2", - "DOCKER_API_VERSION": "v1.40", "GIT_ACCESS_TOKEN": "token", "SKIP_TLS_VERIFICATION": "false", }, @@ -34,15 +33,6 @@ func TestGetAppConfig(t *testing.T) { }, expectedErr: ErrInvalidLogLevel, }, - { - name: "invalid API version", - envVars: map[string]string{ - "LOG_LEVEL": "info", - "WEBHOOK_SECRET": "secret", - "DOCKER_API_VERSION": "1.40", - }, - expectedErr: ErrInvalidDockerAPIVersion, - }, } for _, tt := range tests { diff --git a/internal/docker/compose.go b/internal/docker/compose.go index b9a0d9b..326f6cc 100644 --- a/internal/docker/compose.go +++ b/internal/docker/compose.go @@ -68,13 +68,13 @@ func NewHttpClient() *http.Client { } // VerifySocketRead verifies whether the application can read from the docker socket -func VerifySocketRead(httpClient *http.Client, apiVersion string) error { +func VerifySocketRead(httpClient *http.Client) error { reqBody, err := json.Marshal("") if err != nil { return err } - req, err := http.NewRequest("GET", fmt.Sprintf("http://localhost/%s/info", apiVersion), bytes.NewReader(reqBody)) + req, err := http.NewRequest("GET", "http://localhost/info", bytes.NewReader(reqBody)) if err != nil { return err } @@ -97,7 +97,7 @@ func VerifySocketRead(httpClient *http.Client, apiVersion string) error { } // VerifySocketConnection verifies whether the application can connect to the docker socket -func VerifySocketConnection(apiVersion string) error { +func VerifySocketConnection() error { // Check if the docker socket file exists if _, err := os.Stat("/var/run/docker.sock"); errors.Is(err, os.ErrNotExist) { return err @@ -120,7 +120,7 @@ func VerifySocketConnection(apiVersion string) error { httpClient := NewHttpClient() defer httpClient.CloseIdleConnections() - err = VerifySocketRead(httpClient, apiVersion) + err = VerifySocketRead(httpClient) if err != nil { return err } diff --git a/internal/docker/compose_test.go b/internal/docker/compose_test.go index 32ae9e1..bcc80fb 100644 --- a/internal/docker/compose_test.go +++ b/internal/docker/compose_test.go @@ -50,12 +50,7 @@ var ( ) func TestVerifySocketConnection(t *testing.T) { - c, err := config.GetAppConfig() - if err != nil { - t.Fatal(err) - } - - err = VerifySocketConnection(c.DockerAPIVersion) + err := VerifySocketConnection() if err != nil { t.Fatal(err) } @@ -110,7 +105,7 @@ func TestDeployCompose(t *testing.T) { t.Log("Verify socket connection") - err = VerifySocketConnection(c.DockerAPIVersion) + err = VerifySocketConnection() if err != nil { t.Fatal(err) }