Skip to content

Commit

Permalink
Adds docker invoke tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
HazardDede committed May 4, 2020
1 parent 5ad31cd commit 7a3dc2d
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ tag = True
search = version = "{current_version}"
replace = version = "{new_version}"

[bumpversion:file:tasks/config.py]
search = VERSION = "{current_version}"
replace = VERSION = "{new_version}"

[bumpversion:file:Makefile]

[bumpversion:file:pnp/runner/pnp.py]
Expand Down
81 changes: 81 additions & 0 deletions requirements.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
argh==0.26.2
argresolver==0.3.3
astroid==2.4.0
async-generator==1.10; python_version == "3.5"
asyncio==3.4.3
asyncws==0.1
atomicwrites==1.4.0; sys_platform == "win32"
attrs==19.3.0
beautifulsoup4==4.9.0
binaryornot==0.4.4
boltons==20.1.0
bumpversion==0.5.3
cachetools==4.1.0
certifi==2020.4.5.1
chardet==3.0.4
colorama==0.4.3; sys_platform == "win32"
contextlib2==0.6.0.post1
coverage==5.1
coveralls==2.0.0
cronex==0.1.3.1
dictmentor==0.2.2
docopt==0.6.2
entrypoints==0.3
face==20.1.1
flake8==3.7.9
glom==19.10.0
idna==2.9
importlib-metadata==1.6.0; python_version < "3.8"
influxdb==5.3.0
invoke==1.4.1
isort==4.3.21
jinja2==2.11.2
lazy-object-proxy==1.4.3
markdownpp==1.5.1
markupsafe==1.1.1
mccabe==0.6.1
mock==3.0.5
more-itertools==8.2.0
msgpack==0.6.1
mypy==0.770
mypy-extensions==0.4.3
packaging==20.3
paho-mqtt==1.5.0
pathlib2==2.3.5; python_version < "3.6"
pathspec==0.8.0
pathtools==0.1.2
pluggy==0.13.1
psutil==5.7.0
py==1.8.1
pycodestyle==2.5.0
pyflakes==2.1.1
pylint==2.5.0
pyparsing==2.4.7
pytest==5.4.1
pytest-asyncio==0.11.0
pytest-cov==2.8.1
python-box==3.4.6
python-dateutil==2.8.1
pytz==2020.1
pyyaml==5.3.1
requests==2.23.0
ruamel.yaml==0.16.10
ruamel.yaml.clib==0.2.0; platform_python_implementation == "CPython" and python_version < "3.9"
schedule==0.6.0
schema==0.7.2
schiene==0.23
six==1.14.0
slacker==0.14.0
soupsieve==1.9.5
syncasync==20180812
toml==0.10.0
typed-ast==1.4.1
typing-extensions==3.7.4.2
tzlocal==2.0.0
urllib3==1.25.9
watchdog==0.8.3
wcwidth==0.1.9
websockets==6.0
wrapt==1.12.1
yamllint==1.23.0
zipp==1.2.0; python_version < "3.8"
2 changes: 1 addition & 1 deletion scripts/test-container
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function run() {
docker run -it --rm \
-v ${SOURCE}:/src \
${IMAGE} \
bash -c "poetry export --without-hashes --dev -f requirements.txt > requirements.dev && pip install --extra-index-url https://www.piwheels.hostedpi.com/simple -r requirements.dev && cd /src && make test || bash"
bash -c "cd /src; poetry export --without-hashes --dev -f requirements.txt > requirements.dev && pip install --extra-index-url https://www.piwheels.hostedpi.com/simple -r requirements.dev && invoke test || bash"
}

IMAGE=$1
Expand Down
13 changes: 12 additions & 1 deletion tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
from invoke import Collection
from invoke import Collection, task

from tasks import docker
from tasks import linting
from tasks import testing
from tasks.config import VERSION

ns = Collection()

docker = Collection.from_module(docker, name="docker")
linting = Collection.from_module(linting, name="lint")
testing = Collection.from_module(testing, name="test")


@task
def version(ctx):
print(VERSION)


ns.add_collection(docker)
ns.add_collection(linting)
ns.add_collection(testing)
ns.add_task(version)
10 changes: 9 additions & 1 deletion tasks/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import os

# VERSION
VERSION = "0.22.0"

# PROJECT ROOT
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

# PATH STUFF
CONFIGS_PATH = os.path.join(PROJECT_ROOT, 'config')
DOCS_PATH = os.path.join(PROJECT_ROOT, 'docs')
SCRIPTS_PATH = os.path.join(PROJECT_ROOT, 'scripts')
SOURCE_PATH = os.path.join(PROJECT_ROOT, 'pnp')
TEST_PATH = os.path.join(PROJECT_ROOT, 'tests')

LOCAL_IMAGE_NAME = 'pnp:local'
# DOCKER STUFF
LOCAL_IMAGE_NAME = 'pnp'
LOCAL_IMAGE_TAG = 'local'
ARM_SUFFIX_TAG = 'arm'
PUBLIC_IMAGE_NAME = 'hazard/pnp'
112 changes: 112 additions & 0 deletions tasks/docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from invoke import task

from tasks.config import (
ARM_SUFFIX_TAG,
LOCAL_IMAGE_NAME,
LOCAL_IMAGE_TAG,
PUBLIC_IMAGE_NAME,
SCRIPTS_PATH,
VERSION
)


_LOCAL_IMAGE = "{}:{}".format(LOCAL_IMAGE_NAME, LOCAL_IMAGE_TAG)
_LOCAL_IMAGE_ARM = "{}-{}".format(_LOCAL_IMAGE, ARM_SUFFIX_TAG)

_PUBLIC_IMAGE = "{}:{}".format(PUBLIC_IMAGE_NAME, VERSION)
_PUBLIC_IMAGE_ARM = "{}-{}".format(_PUBLIC_IMAGE, ARM_SUFFIX_TAG)

_PUBLIC_IMAGE_LATEST = "{}:latest".format(PUBLIC_IMAGE_NAME)
_PUBLIC_IMAGE_ARM_LATEST = "{}-{}".format(_PUBLIC_IMAGE_LATEST, ARM_SUFFIX_TAG)


@task
def config(ctx):
"""Show local and public image names."""
print("LOCAL IMAGE:\t\t", _LOCAL_IMAGE)
print("LOCAL IMAGE ARM:\t", _LOCAL_IMAGE_ARM)
print("PUBLIC IMAGE:\t\t", _PUBLIC_IMAGE)
print("PUBLIC IMAGE ARM:\t", _PUBLIC_IMAGE_ARM)
print("PUBLIC IMAGE LATEST:\t", _PUBLIC_IMAGE_LATEST)
print("PUBLIC IMAGE LATEST ARM:", _PUBLIC_IMAGE_ARM_LATEST)


@task
def make_amd64(ctx):
"""Builds the docker image for amd64 as target architecture."""
ctx.run(
"docker build -t {local_image} -f Dockerfile .".format(local_image=_LOCAL_IMAGE)
)


@task
def make_arm(ctx):
"""Builds the docker image for armhf as target architecture."""
ctx.run(
"docker build -t {local_image} -f Dockerfile.arm32v7 .".format(local_image=_LOCAL_IMAGE_ARM)
)


@task(make_amd64, make_arm)
def make(ctx):
"""Builds the docker image for all configured architectures."""


@task(make_amd64)
def test_amd64(ctx):
"""Runs the test-suite on amd64 docker container."""
ctx.run(
"{scripts}/test-container {local_image}".format(scripts=SCRIPTS_PATH, local_image=_LOCAL_IMAGE),
pty=True
)


@task(make_amd64)
def test_arm(ctx):
"""Runs the test-suite on armhf docker container."""
ctx.run(
"{scripts}/test-container {local_image}".format(scripts=SCRIPTS_PATH, local_image=_LOCAL_IMAGE_ARM),
pty=True
)


@task(test_amd64, test_arm, default=True)
def test(ctx):
"""Runs the test suite on all available docker containers."""


@task(make_amd64)
def push_amd64(ctx):
"""Push the amd64 docker image to docker hub."""
ctx.run(
"docker tag {local_image} {public_image}".format(local_image=_LOCAL_IMAGE, public_image=_PUBLIC_IMAGE)
)
ctx.run(
"docker push {public_image}".format(public_image=_PUBLIC_IMAGE)
)


@task(make_arm)
def push_arm(ctx):
"""Push the armhf docker image to docker hub."""
ctx.run(
"docker tag {local_image} {public_image}".format(local_image=_LOCAL_IMAGE_ARM, public_image=_PUBLIC_IMAGE_ARM)
)
ctx.run(
"docker push {public_image}".format(public_image=_PUBLIC_IMAGE_ARM)
)


@task(push_amd64, push_arm)
def release(ctx):
"""Mark the last pushed images as latest for amd64 and armhf architectures."""
ctx.run(
"docker tag {public_image} {latest_image} && docker push {latest_image}".format(
public_image=_PUBLIC_IMAGE, latest_image=_PUBLIC_IMAGE_LATEST
)
)
ctx.run(
"docker tag {public_image} {latest_image} && docker push {latest_image}".format(
public_image=_PUBLIC_IMAGE_ARM, latest_image=_PUBLIC_IMAGE_ARM_LATEST
)
)
23 changes: 23 additions & 0 deletions tasks/release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# next-version: lint test-configs test
# $(eval NEXT_VERSION := $(shell bumpversion --dry-run --allow-dirty --list $(VERSION_PART) | grep new_version | sed s,"^.*=",,))
# @echo Next version is $(NEXT_VERSION)
# bumpversion $(VERSION_PART)
# @echo "Review your version changes first"
# @echo "Accept your version: \`make accept-version\`"
# @echo "Revoke your version: \`make revoke-version\`"
#
# accept-version:
# git push && git push --tags
#
# revoke-version:
# git tag -d `git describe --tags --abbrev=0` # delete the tag
# git reset --hard HEAD~1 # rollback the commit
#
# dist:
# poetry build
#
# release-test: dist
# poetry publish --repository testpypi
#
# release: dist
# poetry publish
2 changes: 1 addition & 1 deletion tests/plugins/pull/test_simple_repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def callback(plugin, payload):
with start_runner(runner):
time.sleep(0.01)

assert len(events) >= 5
assert len(events) >= 2
assert all([p == "Hello World" for p in events])


Expand Down

0 comments on commit 7a3dc2d

Please sign in to comment.