Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Fix README and docker (#12)
Browse files Browse the repository at this point in the history
* Fix README and DOCKER_HUB_CACHED_REPO issue

* _docker_image_inspect should check DOCKER_HUB_REPO as well.

* fix comment.

* Bump version
  • Loading branch information
guan-kevin authored May 24, 2022
1 parent 99e4f58 commit 5c9dd1f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,50 @@ $ pip3 install bugswarm-client
```

## Usage
See [this documentation page](http://www.bugswarm.org/docs/toolset/bugswarm-cli).
Download a Docker image and enter the Docker container associated with an artifact.
```shell
$ bugswarm run --image-tag <image_tag>
```
> Depending on how Docker is configured on your machine, you may need to enter an administrator password.
Download a Docker image and enter the Docker container with a shared folder between the container and the host machine.

```shell
$ bugswarm run --image-tag <image_tag> --use-sandbox
```

Show metadata for an artifact.

```shell
$ bugswarm show --image-tag <image_tag> --token <token>
```

Show usage text for the entire tool or for a specific sub-command.

```shell
$ bugswarm --help
$ bugswarm <sub-command> --help
```

Show the version.

```shell
$ bugswarm --version
```

Please note that artifacts are first attempted to be pulled from `bugswarm/cached-images`, and if not found then they are attempted to be pulled from `bugswarm/images`.

## Example

```shell
$ bugswarm run --image-tag nutzam-nutz-140438299
$ bugswarm show --image-tag nutzam-nutz-140438299 --token <token>
```

> [Requires a token](http://www.bugswarm.org/contact/)
## Development
Execute the following commands to install the tool in ["editable" mode](https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs).
Execute the following commands to install the tool in ["editable" mode](https://pip.pypa.io/en/stable/cli/pip_install/#editable-installs).
1. Clone this repository.
```
$ git clone https://github.com/BugSwarm/client.git
Expand All @@ -27,5 +65,5 @@ Execute the following commands to install the tool in ["editable" mode](https://
```
1. Install the tool.
```
$ pip3 install --upgrade --force-reinstall --process-dependency-links -e .
$ pip3 install --upgrade --force-reinstall -e .
```
27 changes: 20 additions & 7 deletions bugswarm/client/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import sys

from bugswarm.common import log
from bugswarm.common.credentials import DOCKER_HUB_REPO, DOCKER_HUB_CACHED_REPO
from bugswarm.common.shell_wrapper import ShellWrapper
import bugswarm.common.credentials as credentials

SCRIPT_DEFAULT = '/bin/bash'
HOST_SANDBOX_DEFAULT = '~/bugswarm-sandbox'
CONTAINER_SANDBOX_DEFAULT = '/bugswarm-sandbox'

DOCKER_HUB_REPO = \
credentials.DOCKER_HUB_REPO if hasattr(credentials, 'DOCKER_HUB_REPO') else 'bugswarm/images'
DOCKER_HUB_CACHED_REPO = \
credentials.DOCKER_HUB_CACHED_REPO if hasattr(credentials, 'DOCKER_HUB_CACHED_REPO') else 'bugswarm/cached-images'


# By default, this function downloads the image, enters the container, and executes '/bin/bash' in the container.
# The executed script can be changed by passing the script argument.
Expand Down Expand Up @@ -79,8 +84,9 @@ def docker_pull(image_tag):
assert isinstance(image_tag, str)

# Exit early if the image already exists locally.
if _image_exists_locally(image_tag):
return True
exists, image_location = _image_exists_locally(image_tag)
if exists:
return True, image_location

image_location = _image_location(image_tag)
command = 'sudo docker pull {}'.format(image_location)
Expand All @@ -100,19 +106,26 @@ def docker_pull(image_tag):
return returncode == 0, image_location


# Returns True if the image already exists locally.
# Returns True and image_location if the image already exists locally.
def _docker_image_inspect(image_tag):
image_location = _image_location(image_tag)
command = 'sudo docker image inspect {}'.format(image_location)
_, _, returncode = ShellWrapper.run_commands(command,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, shell=True)
# For a non-existent image, docker image inspect has a non-zero exit status.
if returncode == 0:
if returncode != 0:
image_location = '{}:{}'.format(DOCKER_HUB_REPO, image_tag)
command = 'sudo docker image inspect {}'.format(image_location)
_, _, returncode = ShellWrapper.run_commands(command,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, shell=True)
if returncode == 0:
log.info('The image', image_location, 'already exists locally and is up to date.')
else:
log.info('The image', image_location, 'already exists locally and is up to date.')
return returncode == 0
return returncode == 0, image_location


# Returns True if the image already exists locally.
# Returns True and image_location if the image already exists locally.
def _image_exists_locally(image_tag):
return _docker_image_inspect(image_tag)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='bugswarm-client',
version='0.1.6',
version='0.1.7',
url='https://github.com/BugSwarm/client',
author='BugSwarm',
author_email='dev.bugswarm@gmail.com',
Expand Down

0 comments on commit 5c9dd1f

Please # to comment.