Skip to content

Commit

Permalink
Merge 3b54357 into a02edc4
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-alkov committed Apr 16, 2020
2 parents a02edc4 + 3b54357 commit 0548aff
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .mdlint_style
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
all
rule 'MD013', :code_blocks => false

2 changes: 2 additions & 0 deletions .mdlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
style "./.mdlint_style"

3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ env:
OS_VERSION=31
PYTHON_VERSION=3
ENGINE=docker
- ACTION=markdownlint
IMAGE=ruby
ENGINE=docker
script:
- pip install coveralls
- ./test.sh
Expand Down
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
dockerfile-parse
====
# dockerfile-parse

[![Build Status](https://travis-ci.org/containerbuildsystem/dockerfile-parse.svg?branch=master)](https://travis-ci.org/containerbuildsystem/dockerfile-parse)
[![Coverage Status](https://coveralls.io/repos/containerbuildsystem/dockerfile-parse/badge.svg?branch=master&service=github)](https://coveralls.io/github/containerbuildsystem/dockerfile-parse?branch=master)
[![build status]][build status link]
[![coverage status]][coverage status link]

Python library for parsing Dockerfile files.

## Installation

### from PyPI
### From PyPI

```
$ pip install dockerfile-parse
```shell
pip install dockerfile-parse
```

### From git

### from git

Clone this git repo and install dockerfile-parse using python installer:
Clone this git repo and install using the python installer

```shell
$ git clone https://github.com/containerbuildsystem/dockerfile-parse.git
$ cd dockerfile-parse
$ sudo pip install .
git clone https://github.com/containerbuildsystem/dockerfile-parse.git
cd dockerfile-parse
sudo pip install .
```

## Usage
Expand All @@ -48,3 +46,8 @@ dfp.baseimage = 'centos:7'
# Print the new Dockerfile with an updated FROM line:
print(dfp.content)
```

[build status]: https://travis-ci.org/containerbuildsystem/dockerfile-parse.svg?branch=master
[build status link]: https://travis-ci.org/containerbuildsystem/dockerfile-parse
[coverage status]: https://coveralls.io/repos/containerbuildsystem/dockerfile-parse/badge.svg?branch=master&service=github
[coverage status link]: https://coveralls.io/github/containerbuildsystem/dockerfile-parse?branch=master
3 changes: 1 addition & 2 deletions docs/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Maintainers will complete the following section


Maintainers will complete the following section:
- [ ] Commit messages are descriptive enough
- [ ] "Signed-off-by:" line is present in each commit
- [ ] Code coverage from testing does not decrease and new code is covered
111 changes: 62 additions & 49 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,83 +7,96 @@ OS=${OS:="centos"}
OS_VERSION=${OS_VERSION:="7"}
PYTHON_VERSION=${PYTHON_VERSION:="2"}
ACTION=${ACTION:="test"}
IMAGE="$OS:$OS_VERSION"
IMAGE=${IMAGE:="$OS:$OS_VERSION"}
CONTAINER_NAME="dockerfile-parse-$OS-$OS_VERSION-py$PYTHON_VERSION"

if [[ $ACTION == "markdownlint" ]]; then
CONTAINER_NAME="dockerfile-parse-$ACTION-$IMAGE"
fi

RUN="$ENGINE exec -ti $CONTAINER_NAME"

# Use arrays to prevent globbing and word splitting
engine_mounts=(-v "$PWD":"$PWD":z)
for dir in ${EXTRA_MOUNT:-}; do
engine_mounts=("${engine_mounts[@]}" -v "$dir":"$dir":z)
done

# Pull fedora images from registry.fedoraproject.org
if [[ $OS == "fedora" ]]; then
IMAGE="registry.fedoraproject.org/$IMAGE"
fi


CONTAINER_NAME="dockerfile-parse-$OS-$OS_VERSION-py$PYTHON_VERSION"
RUN="$ENGINE exec -ti $CONTAINER_NAME"
if [[ $OS == "fedora" ]]; then
PIP_PKG="python$PYTHON_VERSION-pip"
PIP="pip$PYTHON_VERSION"
PKG="dnf"
PKG_EXTRA="dnf-plugins-core"
BUILDDEP="dnf builddep"
PYTHON="python$PYTHON_VERSION"
else
PIP_PKG="python-pip"
PIP="pip"
PKG="yum"
PKG_EXTRA="yum-utils epel-release"
BUILDDEP="yum-builddep"
PYTHON="python"
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
elif [[ $($ENGINE ps -q -f name="$CONTAINER_NAME" | wc -l) -eq 0 ]]; then
echo found stopped existing container, restarting. volume mounts cannot be updated.
$ENGINE container start "$CONTAINER_NAME"
fi

# 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 yum install -y python-six
fi

# Install package
$RUN $PKG install -y $PIP_PKG
if [[ $PYTHON_VERSION == 3 ]]; then
# https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
$RUN mkdir -p /usr/local/lib/python3.6/site-packages/
fi
$RUN $PYTHON setup.py install
function setup_dfp() {
# Pull fedora images from registry.fedoraproject.org
if [[ $OS == "fedora" ]]; then
IMAGE="registry.fedoraproject.org/$IMAGE"
fi

# CentOS needs to have setuptools updates to make pytest-cov work
if [[ $OS != "fedora" ]]; then
$RUN $PIP install -U setuptools
if [[ $OS == "fedora" ]]; then
PIP_PKG="python$PYTHON_VERSION-pip"
PIP="pip$PYTHON_VERSION"
PKG="dnf"
PKG_EXTRA="dnf-plugins-core"
BUILDDEP="dnf builddep"
PYTHON="python$PYTHON_VERSION"
else
PIP_PKG="python-pip"
PIP="pip"
PKG="yum"
PKG_EXTRA="yum-utils epel-release"
BUILDDEP="yum-builddep"
PYTHON="python"
fi

# Watch out for https://github.com/pypa/setuptools/issues/937
$RUN curl -O https://bootstrap.pypa.io/2.6/get-pip.py
$RUN $PYTHON get-pip.py
fi
# 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 yum install -y python-six
fi

$RUN $PIP install -r tests/requirements.txt
# Install package
$RUN $PKG install -y $PIP_PKG
if [[ $PYTHON_VERSION == 3 ]]; then
# https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
$RUN mkdir -p /usr/local/lib/python3.6/site-packages/
fi
$RUN $PYTHON setup.py install

if [[ $PYTHON_VERSION -gt 2 ]]; then $RUN $PIP install -r requirements-py3.txt; fi
# CentOS needs to have setuptools updates to make pytest-cov work
if [[ $OS != "fedora" ]]; then
$RUN $PIP install -U setuptools

# Watch out for https://github.com/pypa/setuptools/issues/937
$RUN curl -O https://bootstrap.pypa.io/2.6/get-pip.py
$RUN $PYTHON get-pip.py
fi

$RUN $PIP install -r tests/requirements.txt

if [[ $PYTHON_VERSION -gt 2 ]]; then $RUN $PIP install -r requirements-py3.txt; fi
}

case ${ACTION} in
"test")
setup_dfp
TEST_CMD="py.test --cov dockerfile_parse --cov-report html -vv tests"
;;
"bandit")
setup_dfp
$RUN $PKG install -y git-core
$RUN $PIP install bandit
TEST_CMD="bandit-baseline -r dockerfile_parse -ll -ii"
;;
"markdownlint")
$RUN gem install mdl
TEST_CMD="mdl -g ."
;;
*)
echo "Unknown action: ${ACTION}"
exit 2
Expand Down

0 comments on commit 0548aff

Please sign in to comment.