Skip to content

Commit

Permalink
fix: rootless docker refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarIthawi committed Nov 16, 2023
1 parent 0cf636b commit de09c83
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 42 deletions.
24 changes: 0 additions & 24 deletions tests/commands/test_dev.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
import unittest
from unittest.mock import patch, MagicMock

from .base import TestCommandMixin

from tutor.commands import dev
from tutor.types import Config


class DevTests(unittest.TestCase, TestCommandMixin):
def test_dev_help(self) -> None:
result = self.invoke(["dev", "--help"])
self.assertEqual(0, result.exit_code)
self.assertIsNone(result.exception)

@patch("tutor.utils.is_docker_rootless")
def test_rootless_no_ulimits(self, mock_is_docker_rootless: MagicMock) -> None:
configs: Config = {
"DEV_PROJECT_NAME": "maple",
}

mock_is_docker_rootless.return_value = False
task_runner = dev.DevTaskRunner("/app", configs)
self.assertIn(
"/app/env/local/docker-compose.ulimits.yml",
task_runner.docker_compose_files,
)

mock_is_docker_rootless.return_value = True
task_runner = dev.DevTaskRunner("/app", configs)
self.assertNotIn(
"/app/env/local/docker-compose.ulimits.yml",
task_runner.docker_compose_files,
)
7 changes: 0 additions & 7 deletions tutor/commands/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from tutor import hooks
from tutor.commands import compose
from tutor.types import Config, get_typed
from tutor import utils


class DevTaskRunner(compose.ComposeTaskRunner):
Expand All @@ -25,12 +24,6 @@ def __init__(self, root: str, config: Config):
tutor_env.pathjoin(self.root, "dev", "docker-compose.override.yml"),
]

if not utils.is_docker_rootless():
# Setting `ulimits` throws an error when running in rootless mode.
self.docker_compose_files += [
tutor_env.pathjoin(self.root, "local", "docker-compose.ulimits.yml"),
]

self.docker_compose_job_files += [
tutor_env.pathjoin(self.root, "local", "docker-compose.jobs.yml"),
tutor_env.pathjoin(self.root, "dev", "docker-compose.jobs.yml"),
Expand Down
1 change: 1 addition & 0 deletions tutor/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def _prepare_environment() -> None:
("TUTOR_APP", __app__.replace("-", "_")),
("TUTOR_VERSION", __version__),
("is_buildkit_enabled", utils.is_buildkit_enabled),
("is_docker_rootless", utils.is_docker_rootless),
],
)

Expand Down
9 changes: 9 additions & 0 deletions tutor/templates/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ services:
command: openedx-assets watch-themes --env dev
restart: unless-stopped

{% if RUN_ELASTICSEARCH and is_docker_rootless() %}
elasticsearch:
ulimits:
memlock:
# Fixes error setting rlimits for ready process in rootless docker
soft: 0
hard: 0
{% endif %}

{{ patch("local-docker-compose-dev-services")|indent(2) }}
11 changes: 0 additions & 11 deletions tutor/templates/local/docker-compose.ulimits.yml

This file was deleted.

4 changes: 4 additions & 0 deletions tutor/templates/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ services:
- bootstrap.memory_lock=true
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms{{ ELASTICSEARCH_HEAP_SIZE }} -Xmx{{ ELASTICSEARCH_HEAP_SIZE }}"
ulimits:
memlock:
soft: -1
hard: -1
restart: unless-stopped
user: "1000:1000"
volumes:
Expand Down

0 comments on commit de09c83

Please sign in to comment.