Skip to content

Commit

Permalink
Address Pull Request issues.
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick J. McNerthney <pat@mcnerthney.com>
  • Loading branch information
iciclespider committed Jun 17, 2020
1 parent ce3a377 commit ff79d62
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ docs/_build/

# PyBuilder
target/

# Downloaded by test.sh
get-pip.py
6 changes: 3 additions & 3 deletions dockerfile_parse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ def __init__(self, path=None,
cache_content=False,
env_replace=True,
parent_env=None,
build_args=None,
fileobj=None):
fileobj=None,
build_args=None):
"""
Initialize source of Dockerfile
:param path: path to (directory with) Dockerfile
:param cache_content: cache Dockerfile content inside DockerfileParser
:param env_replace: return content with variables replaced
:param parent_env: python dict of inherited env vars from parent image
:param build_args: python dict of build args used when building image
:param fileobj: seekable file-like object containing Dockerfile content
as bytes (will be truncated on write)
:param build_args: python dict of build args used when building image
"""

self.fileobj = fileobj
Expand Down
2 changes: 1 addition & 1 deletion python-dockerfile-parse.spec
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ py.test-%{python3_version} -v tests
* Tue Jun 02 2020 Robert Cerven <rcerven@redhat.com> 0.0.18-1
- new upstream release: 0.0.18

* Fri Apr 24 2020 Martin Bašti <mbasti@redhat.com> 0.0.17-1
* Fri Apr 24 2020 Martin Basti <mbasti@redhat.com> 0.0.17-1
- new upstream release: 0.0.17

* Tue Jan 21 2020 Robert Cerven <rcerven@redhat.com> - 0.0.16-1
Expand Down
23 changes: 23 additions & 0 deletions test-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -eux

# This script tests the test.sh script using many permutations
# of operating systems, python versions, and actions. Recreating
# the container for each permutation for every action ensures
# that a prior action did not already install a required package.

export ENGINE=${ENGINE:="docker"}
export RECREATE_CONTAINER=${RECREATE_CONTAINER:="true"}

for os in fedora:29 fedora:30 fedora:31 centos:7 centos:8
do
os_version=$(echo $os | cut -d : -f 2)
os=$(echo $os | cut -d : -f 1)
for python_version in 2 3
do
for action in test bandit pylint markdownlint
do
ACTION=$action PYTHON_VERSION=$python_version OS=$os OS_VERSION=$os_version ./test.sh
done
done
done
25 changes: 15 additions & 10 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PYTHON_VERSION=${PYTHON_VERSION:="2"}
ACTION=${ACTION:="test"}
IMAGE="$OS:$OS_VERSION"
CONTAINER_NAME="dockerfile-parse-$OS-$OS_VERSION-py$PYTHON_VERSION"
RECREATE_CONTAINER=${RECREATE_CONTAINER:="false"}

if [[ $ACTION == "markdownlint" ]]; then
IMAGE="ruby"
Expand All @@ -23,6 +24,16 @@ for dir in ${EXTRA_MOUNT:-}; do
engine_mounts=("${engine_mounts[@]}" -v "$dir":"$dir":z)
done

# Force recreation of the container
if $RECREATE_CONTAINER; then
if [[ $($ENGINE ps -q -f name="$CONTAINER_NAME" | wc -l) -gt 0 ]]; then
$ENGINE kill $CONTAINER_NAME
fi
if [[ $($ENGINE ps -qa -f name="$CONTAINER_NAME" | wc -l) -gt 0 ]]; then
$ENGINE rm $CONTAINER_NAME
fi
fi

# Create or resurrect container if needed
if [[ $($ENGINE ps -qa -f name="$CONTAINER_NAME" | wc -l) -eq 0 ]]; then
$ENGINE run --name "$CONTAINER_NAME" -d "${engine_mounts[@]}" -w "$PWD" -ti "$IMAGE" sleep infinity
Expand All @@ -38,26 +49,20 @@ function setup_dfp() {
fi

if [[ $OS == "fedora" || ( $OS == "centos" && $OS_VERSION -gt 7 ) ]]; then
PIP="pip$PYTHON_VERSION"
PKG="dnf"
PKG_EXTRA="dnf-plugins-core"
BUILDDEP="dnf builddep"
PYTHON="python$PYTHON_VERSION"
else
PIP="pip"
PKG="yum"
PKG_EXTRA="yum-utils epel-release"
BUILDDEP="yum-builddep"
PYTHON="python"
fi
PIP="pip$PYTHON_VERSION"
PYTHON="python$PYTHON_VERSION"

# Install dependencies
$RUN $PKG install -y $PKG_EXTRA
$RUN $BUILDDEP -y python-dockerfile-parse.spec
if [[ $OS != "fedora" ]]; then
# Install dependecies for test, as check is disabled for rhel
$RUN $PKG install -y $PYTHON-six
fi

# Install package
$RUN $PKG install -y $PYTHON-pip
Expand All @@ -69,7 +74,7 @@ function setup_dfp() {

# CentOS needs to have setuptools updates to make pytest-cov work
if [[ $OS != "fedora" ]]; then
$RUN $PIP install -U 'setuptools<45'
$RUN $PIP install -U "setuptools$([[ $PYTHON_VERSION == 3 ]] || echo -n '<45')"

# Watch out for https://github.com/pypa/setuptools/issues/937
$RUN curl -O https://bootstrap.pypa.io/2.6/get-pip.py
Expand All @@ -94,7 +99,7 @@ case ${ACTION} in
;;
"pylint")
setup_dfp
$RUN $PKG install -y "${PYTHON}-pylint"
$RUN $PIP install pylint
PACKAGES='dockerfile_parse tests'
TEST_CMD="${PYTHON} -m pylint ${PACKAGES}"
;;
Expand Down

0 comments on commit ff79d62

Please sign in to comment.