Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add podman support #248

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions .github/workflows/basic-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ jobs:
cli_smoke_tests:
name: CLI smoke tests
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8, '3.x']
executable_name: [rocker, rodman]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies And Self
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -e .
- name: Check main runs
run: |
${{ matrix.executable_name }} ubuntu 'true'
- name: Check rocker help
run: |
${{ matrix.executable_name }} -h
test_helper_functions:
name: Test Helper Functions
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8, '3.x']
Expand All @@ -46,10 +69,3 @@ jobs:
- name: Check detector help
run: |
detect_docker_image_os ubuntu -h
- name: Check main runs
run: |
rocker ubuntu 'true'
- name: Check rocker help
run: |
rocker -h

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
'package_data': {'rocker': ['templates/*.em']},
'entry_points': {
'console_scripts': [
'rocker = rocker.cli:main',
'rocker = rocker.cli:rocker_main',
'rodman = rocker.cli:rodman_main',
'detect_docker_image_os = rocker.cli:detect_image_os',
],
'rocker.extensions': [
Expand Down
10 changes: 9 additions & 1 deletion src/rocker/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .os_detector import detect_os


def main():
def main(implementation='rocker'):

parser = argparse.ArgumentParser(
description='A tool for running docker with extra options',
Expand All @@ -50,6 +50,7 @@ def main():

args = parser.parse_args()
args_dict = vars(args)
args_dict['use_podman'] = implementation == 'podman'

if args.noexecute:
from .core import OPERATIONS_DRY_RUN
Expand Down Expand Up @@ -94,3 +95,10 @@ def detect_image_os():
return 0
else:
return 1

def rocker_main():
return main(implementation='rocker')


def rodman_main():
return main(implementation='podman')
13 changes: 10 additions & 3 deletions src/rocker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def docker_build(docker_client = None, output_callback = None, **kwargs):
image_id = match.group(1)

if image_id:
return image_id
return docker_client.inspect_image(image_id).get('Id')
else:
print("no more output and success not detected")
return None
Expand Down Expand Up @@ -365,7 +365,14 @@ def generate_docker_cmd(self, command='', **kwargs):
image = image_name
else:
image = self.image_id
cmd = "docker run"
cmd = ""
podman_prefix = ""
if kwargs.get('use_podman'):
cmd += "podman run"
podman_prefix = "docker-daemon:"
else:
cmd += "docker run"

if(not kwargs.get('nocleanup')):
# remove container only if --nocleanup is not present
cmd += " --rm"
Expand All @@ -374,7 +381,7 @@ def generate_docker_cmd(self, command='', **kwargs):
if operating_mode != OPERATIONS_NON_INTERACTIVE:
# only disable for OPERATIONS_NON_INTERACTIVE
cmd += " -it"
cmd += "%(docker_args)s %(image)s %(command)s" % locals()
cmd += "%(docker_args)s %(podman_prefix)s%(image)s %(command)s" % locals()
return cmd

def run(self, command='', **kwargs):
Expand Down
5 changes: 5 additions & 0 deletions src/rocker/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ class User(RockerExtension):
def get_name():
return 'user'

def get_docker_args(self, cliargs):
if cliargs.get('use_podman', False):
return ' --userns=keep-id '
return ''

def get_environment_subs(self):
if not self._env_subs:
user_vars = ['name', 'uid', 'gid', 'gecos','dir', 'shell']
Expand Down
8 changes: 8 additions & 0 deletions test/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@ def test_user_extension(self):
snippet_result = p.get_snippet(user_override_active_cliargs)
self.assertFalse('-s' in snippet_result)

user_podman_args = mock_cliargs
args_result = p.get_docker_args(user_podman_args)
self.assertNotIn('--userns=keep-id', args_result)

user_podman_args['use_podman'] = True
args_result = p.get_docker_args(user_podman_args)
self.assertIn('--userns=keep-id', args_result)

@pytest.mark.docker
def test_user_collisions(self):
plugins = list_plugins()
Expand Down
Loading