Skip to content

LIU-458: Upgrade test_docker.py images to 22.04 #318

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

myxie
Copy link
Collaborator

@myxie myxie commented Apr 9, 2025

  • Doing this alone causes errors because nc is not available on base ubuntu:22.04 images.
  • Need to install netstat (nc) onto image
  • Easiest way to do this is using a dockerfile with the docker-py API.

JIRA Ticket

LIU-458

Type

  • Feature (addition)
  • Bug fix
  • Refactor (change)
  • Documentation

Problem/Issue

Our test_docker instances are using Ubuntu:14.04 containers, which is incredibly old. We should support tests using newer versions of ubuntu.

Solution

I have updated to 22.04 containers. This was almost as simple as bumping the numbers, but our test_clientServer test case uses the nc (netstat) command. This is not installed available by default on Ubuntu 22.04 (presumably because they are slimmer images).

I have added a CustomContainer class in test_docker.py that builds a Dockerfile from an input string and then builds the image, using the docker-py library we already use. The image is not cleaned up so it takes much less time to run the test after the first time the image is built (I have added code to do so if needed).

Checklist

  • Unittests added
    • These are the unit tests
  • Documentation added
    • These are not user-facing changes.

Summary by Sourcery

Upgrade test Docker images from Ubuntu 14.04 to Ubuntu 22.04 and add support for installing netcat in test containers

New Features:

  • Added ability to create custom Docker images dynamically during testing

Bug Fixes:

  • Resolved compatibility issues with Ubuntu 22.04 images by adding a custom container creation method to install netcat

Enhancements:

  • Introduced a CustomContainer class to dynamically build Docker images with additional dependencies
  • Updated Docker test cases to use Ubuntu 22.04 images

- Doing this alone causes errors because nc is not available on base ubuntu:22.04 images.
- Need to install netstat (nc) onto image
- Easiest way to do this is using a dockerfile with the docker-py API.
Copy link
Contributor

sourcery-ai bot commented Apr 9, 2025

Reviewer's Guide by Sourcery

This PR upgrades the base image for DockerApp tests from Ubuntu 14.04 to Ubuntu 22.04. It introduces a CustomContainer class to handle custom image creation, which is used to install netcat for the test_clientServer test case. Additionally, it fixes a bug in the DockerApp class related to container IP replacement.

Sequence diagram for DockerApp IP replacement

sequenceDiagram
    participant DockerApp
    participant ContainerIpWaiter

    DockerApp->>ContainerIpWaiter: Add ContainerIpWaiter
    activate ContainerIpWaiter
    ContainerIpWaiter->>DockerApp: waitForIp()
    activate DockerApp
    DockerApp-->>ContainerIpWaiter: uid, ip
    deactivate DockerApp
    ContainerIpWaiter-->>DockerApp: uid, ip
    deactivate ContainerIpWaiter
    DockerApp->>DockerApp: Replace %containerIp[{uid}]% with ip
Loading

File-Level Changes

Change Details Files
Introduces a CustomContainer class to build Docker images from a Dockerfile string.
  • Adds a CustomContainer class with methods to create and remove Docker images.
  • Implements create_container to build an image from a Dockerfile string.
  • Implements remove_container to remove a Docker image.
daliuge-engine/test/apps/test_docker.py
Updates the base image for DockerApp tests from Ubuntu 14.04 to Ubuntu 22.04.
  • Updates the image parameter in several DockerApp instantiations to use ubuntu:22.04.
  • Adds a Dockerfile to install netcat for the test_clientServer test case.
daliuge-engine/test/apps/test_docker.py
Fixes a bug in handleInterest and run methods of the DockerApp class related to container IP replacement.
  • Corrects the string formatting in handleInterest and run to properly replace container IP placeholders in commands.
  • Uses f-strings for string formatting.
daliuge-engine/dlg/apps/dockerapp.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @myxie - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a method to CustomContainer to check if an image exists before creating it.
  • Consider adding a teardown method to DockerTests to remove the custom container after the tests are complete.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 393 to 396
if isinstance(drop, DockerApp):
if "%containerIp[{0}]%".format(drop.uid) in self._command:
if f"%containerIp[{{{drop.uid}}}]%" in self._command:
self._waiters.append(ContainerIpWaiter(drop))
logger.debug("%r: Added ContainerIpWaiter for %r", self, drop)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Merge nested if conditions (merge-nested-ifs)

Suggested change
if isinstance(drop, DockerApp):
if "%containerIp[{0}]%".format(drop.uid) in self._command:
if f"%containerIp[{{{drop.uid}}}]%" in self._command:
self._waiters.append(ContainerIpWaiter(drop))
logger.debug("%r: Added ContainerIpWaiter for %r", self, drop)
if isinstance(drop, DockerApp) and f"%containerIp[{{{drop.uid}}}]%" in self._command:
self._waiters.append(ContainerIpWaiter(drop))
logger.debug("%r: Added ContainerIpWaiter for %r", self, drop)


ExplanationToo much nesting can make code difficult to understand, and this is especially
true in Python, where there are no brackets to help out with the delineation of
different nesting levels.

Reading deeply nested code is confusing, since you have to keep track of which
conditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two if conditions can be combined using
and is an easy win.

Comment on lines 240 to 241
command="cp /opt/file %s" % (tempDir,),
additionalBindings=[tempDir, "%s:/opt/file" % (tempFile,)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Replace interpolated string formatting with f-string [×2] (replace-interpolation-with-fstring)

Suggested change
command="cp /opt/file %s" % (tempDir,),
additionalBindings=[tempDir, "%s:/opt/file" % (tempFile,)],
command=f"cp /opt/file {tempDir}",
additionalBindings=[tempDir, f"{tempFile}:/opt/file"],

@coveralls
Copy link

Coverage Status

coverage: 78.678% (-0.02%) from 78.701%
when pulling ecbde29 on LIU-458
into 9caf08d on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants