diff --git a/HadesCloneContainer/Dockerfile b/HadesCloneContainer/Dockerfile index b03ff52..d2d77e9 100644 --- a/HadesCloneContainer/Dockerfile +++ b/HadesCloneContainer/Dockerfile @@ -23,4 +23,4 @@ COPY --from=builder /app/hades-clone . RUN chmod +x /app/hades-clone # Run your Go application and then sleep indefinitely -ENTRYPOINT ["/app/hades-clone"] \ No newline at end of file +ENTRYPOINT ["/app/hades-clone"] diff --git a/HadesScheduler/docker/docker.go b/HadesScheduler/docker/docker.go index c211a39..32eb886 100644 --- a/HadesScheduler/docker/docker.go +++ b/HadesScheduler/docker/docker.go @@ -18,16 +18,19 @@ import ( var cli *client.Client var global_envs []string = []string{} +var container_autoremove bool type Scheduler struct{} type DockerConfig struct { - DockerHost string `env:"DOCKER_HOST" envDefault:"unix:///var/run/docker.sock"` + DockerHost string `env:"DOCKER_HOST" envDefault:"unix:///var/run/docker.sock"` + ContainerAutoremove bool `env:"CONTAINER_AUTOREMOVE" envDefault:"true` } func init() { var DockerCfg DockerConfig utils.LoadConfig(&DockerCfg) + container_autoremove = DockerCfg.ContainerAutoremove var err error // Create a new Docker client @@ -99,7 +102,7 @@ func executeStep(ctx context.Context, client *client.Client, step payload.Step, Target: "/shared", }, }, - AutoRemove: true, + AutoRemove: container_autoremove, // Remove the container after it is done only if the config is set to true } // Create the bash script if there is one diff --git a/HadesScheduler/main.go b/HadesScheduler/main.go index dab144a..ea15c74 100644 --- a/HadesScheduler/main.go +++ b/HadesScheduler/main.go @@ -29,6 +29,7 @@ func main() { var executorCfg utils.ExecutorConfig utils.LoadConfig(&executorCfg) + log.Debug("Executor config: ", executorCfg) var err error rabbitmqURL := fmt.Sprintf("amqp://%s:%s@%s/", cfg.User, cfg.Password, cfg.Url) @@ -52,7 +53,7 @@ func main() { log.Info("Started HadesScheduler in Docker mode") scheduler = docker.Scheduler{} default: - log.Fatal("Invalid executor specified") + log.Fatalf("Invalid executor specified: %s", executorCfg.Executor) } BuildQueue.Dequeue(scheduler.ScheduleJob) diff --git a/docker-comose.k8s.yml b/docker-comose.k8s.yml index f2119f5..1494f56 100644 --- a/docker-comose.k8s.yml +++ b/docker-comose.k8s.yml @@ -8,5 +8,6 @@ services: - KUBECONFIG=/root/.kube/config - RABBITMQ_DEFAULT_USER - RABBITMQ_DEFAULT_PASS + - HADES_EXECUTOR=k8s volumes: - ./.kube/config:/root/.kube/config diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..c760759 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,20 @@ +# docker compose file for the project with three services + +version: '3.7' +services: + hadesAPI: + environment: + - RABBITMQ_URL=rabbitmq:5672 + - RABBITMQ_DEFAULT_USER + - RABBITMQ_DEFAULT_PASS + - DEBUG=true + hadesScheduler: + environment: + - RABBITMQ_URL=rabbitmq:5672 + - RABBITMQ_DEFAULT_USER + - RABBITMQ_DEFAULT_PASS + - HADES_EXECUTOR=docker + - CONTAINER_AUTOREMOVE=false + - DEBUG=true + volumes: + - /var/run/docker.sock:/var/run/docker.sock \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index fa19e1a..0833e9f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,8 @@ services: context: . dockerfile: ./HadesAPI/Dockerfile ports: - - "8080:8080" + # Set the Port to 8081 to avoid conflicts with the artemis server + - "8081:8080" networks: - hades depends_on: @@ -24,6 +25,10 @@ services: build: context: . dockerfile: ./HadesScheduler/Dockerfile + volumes: + - type: bind + source: /var/run/docker.sock + target: /var/run/docker.sock networks: - hades depends_on: @@ -31,6 +36,9 @@ services: condition: service_healthy environment: - RABBITMQ_URL=rabbitmq:5672 + - RABBITMQ_DEFAULT_USER + - RABBITMQ_DEFAULT_PASS + - HADES_EXECUTOR=docker rabbitmq: container_name: rabbitmq diff --git a/shared/utils/config.go b/shared/utils/config.go index 8e03cf5..2e38dda 100644 --- a/shared/utils/config.go +++ b/shared/utils/config.go @@ -17,7 +17,7 @@ type K8sConfig struct { } type ExecutorConfig struct { - Executor string `env:"EXECUTOR,notEmpty" envDefault:"k8s"` + Executor string `env:"HADES_EXECUTOR,notEmpty" envDefault:"docker"` } func LoadConfig(cfg interface{}) {