From 6f04223d0135e1debb005f2a9802f081ed21d203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Thu, 1 Jul 2021 07:12:41 +0200 Subject: [PATCH] fix: empty entrypoints in docker-compose=2.0.0.beta4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An issue with the latest release of docker-compose was reported here: https://discuss.overhang.io/t/undefined-entrypoint-throws-error-in-docker-compose-2-0-0-beta-4/1716 The mysql-job definition had an empty entrypoint (`[]`). This was causing the following error: the initiation of mysql fails with “services.mysql-job.entrypoint must be a string … Error: Command failed with status 15” I can't remember at all why we had to define an empty entrypoint. It probably has to do with the fact that we could not run `sh -e -c "..."` commands in mysql jobs. Similarly, the k8s job definition sets `command: []`. I tested both local and k8s deployments without these definitions and they work just fine. So I guess we can get rid of them. --- CHANGELOG.md | 1 + tutor/commands/k8s.py | 17 +++++++---------- tutor/templates/k8s/jobs.yml | 2 -- tutor/templates/local/docker-compose.jobs.yml | 2 -- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d15da52f10..e5ac1f6a19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Note: Breaking changes between versions are indicated by "💥". ## Unreleased +- [Bugfix] Fix mysql initialisation in docker-compose==2.0.0beta4. - [Improvement] Tutor is now published on pypi as "tutor". ## v12.0.1 (2021-06-22) diff --git a/tutor/commands/k8s.py b/tutor/commands/k8s.py index 31814c6707..dc4ee6cf55 100644 --- a/tutor/commands/k8s.py +++ b/tutor/commands/k8s.py @@ -114,16 +114,13 @@ def run_job(self, service: str, command: str) -> int: job["metadata"]["name"] = job_name job["metadata"].setdefault("labels", {}) job["metadata"]["labels"]["app.kubernetes.io/name"] = job_name - # Define k8s entrypoint/args - shell_command = ["sh", "-e", "-c"] - if job["spec"]["template"]["spec"]["containers"][0].get("command") == []: - # Empty "command" (aka: entrypoint) might not be taken into account by jobs, so we need to manually - # override the entrypoint. We do not do this for every job, because some entrypoints are actually useful. - job["spec"]["template"]["spec"]["containers"][0]["command"] = shell_command - container_args = [command] - else: - container_args = shell_command + [command] - job["spec"]["template"]["spec"]["containers"][0]["args"] = container_args + # Define k8s args (aka: CMD) + job["spec"]["template"]["spec"]["containers"][0]["args"] = [ + "sh", + "-e", + "-c", + command, + ] job["spec"]["backoffLimit"] = 1 job["spec"]["ttlSecondsAfterFinished"] = 3600 # Save patched job to "jobs.yml" file diff --git a/tutor/templates/k8s/jobs.yml b/tutor/templates/k8s/jobs.yml index aa2bb70e82..96a4d3ad06 100644 --- a/tutor/templates/k8s/jobs.yml +++ b/tutor/templates/k8s/jobs.yml @@ -77,7 +77,6 @@ spec: containers: - name: mysql image: {{ DOCKER_IMAGE_MYSQL }} - command: [] --- apiVersion: batch/v1 kind: Job @@ -105,4 +104,3 @@ spec: value: "{{ FORUM_MONGODB_DATABASE }}" {{ patch("k8s-jobs") }} - diff --git a/tutor/templates/local/docker-compose.jobs.yml b/tutor/templates/local/docker-compose.jobs.yml index c5885ac365..26b123788d 100644 --- a/tutor/templates/local/docker-compose.jobs.yml +++ b/tutor/templates/local/docker-compose.jobs.yml @@ -3,8 +3,6 @@ services: mysql-job: image: {{ DOCKER_IMAGE_MYSQL }} - entrypoint: [] - command: ["echo", "done"] depends_on: {{ [("mysql", RUN_MYSQL)]|list_if }} lms-job: