From 1ffa6ad50266b420a469cc9c321866cc5afaf55b Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sat, 14 Nov 2020 23:33:03 +0100 Subject: [PATCH] #7: Moving to Github Actions --- .dockerignore | 6 + .github/workflows/test-and-release.yaml | 25 +++ .gitignore | 4 + .infrastructure/x86_64.Dockerfile | 13 +- .rkd/makefile.yaml | 81 ++++++++ Pipfile | 19 -- Pipfile.lock | 236 ------------------------ docs/source/index.rst | 2 +- requirements.txt | 19 +- setup-venv.sh | 12 ++ setup.cfg | 2 +- 11 files changed, 149 insertions(+), 270 deletions(-) create mode 100644 .github/workflows/test-and-release.yaml create mode 100644 .rkd/makefile.yaml delete mode 100644 Pipfile delete mode 100644 Pipfile.lock create mode 100755 setup-venv.sh diff --git a/.dockerignore b/.dockerignore index cd558e9..cc568e2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,7 @@ /.infrastructure/*.Dockerfile +/.venv +*.pyc +.coveragerc +/example +/docs +/tests diff --git a/.github/workflows/test-and-release.yaml b/.github/workflows/test-and-release.yaml new file mode 100644 index 0000000..e388b03 --- /dev/null +++ b/.github/workflows/test-and-release.yaml @@ -0,0 +1,25 @@ +name: Test and release a package +on: [push] + +jobs: + build: + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install dependencies + run: pip install -r ./requirements.txt + + - name: Install project via setuptools + run: "rkd :install" + + - name: Run unit tests + run: "rkd :test:unit" + + - name: Run functional tests + run: "rkd :test:functional" diff --git a/.gitignore b/.gitignore index 2ca5871..f05bb8f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ /.idea *.pyc /.coverage +.rkd/logs +*__pycache__* +/.venv +.venv-setup.log diff --git a/.infrastructure/x86_64.Dockerfile b/.infrastructure/x86_64.Dockerfile index 21d74fe..62b89b5 100644 --- a/.infrastructure/x86_64.Dockerfile +++ b/.infrastructure/x86_64.Dockerfile @@ -1,6 +1,6 @@ -FROM alpine:3.9 +FROM alpine:3.12 -RUN apk --update add python3 bash perl curl wget grep sed docker sudo mysql-client postgresql-client make git supervisor tzdata \ +RUN apk --update add python3 bash perl curl wget grep sed docker sudo mysql-client postgresql-client git supervisor tzdata \ sshpass openssh-client ADD . /infracheck ADD .git /infracheck/ @@ -14,8 +14,11 @@ RUN cd /infracheck \ # install as a package && git remote remove origin || true \ && git remote add origin https://github.com/riotkit-org/infracheck.git \ - && apk add --update gcc python3-dev musl-dev linux-headers postgresql-dev \ - && make install \ + \ + && apk add --no-cache --update --virtual BUILD_DEPS py3-pip gcc python3-dev musl-dev linux-headers postgresql-dev libffi-dev \ + && pip3 install pbr==5.4.5 \ + && pip3 install -r /infracheck/requirements.txt \ + && rkd :install \ # after installing as package extract infrastructural files \ && cp -pr /infracheck/entrypoint.sh / \ @@ -28,6 +31,6 @@ RUN cd /infracheck \ # simple check that application does not crash at the beginning (is correctly packaged) && infracheck --help \ \ - && apk del gcc python3-dev musl-dev linux-headers postgresql-dev + && apk del BUILD_DEPS ENTRYPOINT ["/entrypoint.sh"] diff --git a/.rkd/makefile.yaml b/.rkd/makefile.yaml new file mode 100644 index 0000000..e457d0b --- /dev/null +++ b/.rkd/makefile.yaml @@ -0,0 +1,81 @@ +version: org.riotkit.rkd/yaml/v1 +imports: + - rkd_python + +environment: + REPO: "quay.io/riotkit/infracheck" + +tasks: + :test:unit: + description: Run unit tests + steps: + - "%RKD% :py:unittest --src-dir=./ --tests-dir=tests --pattern='unit_test_*.py'" + + :test:functional: + description: Run unit tests + steps: + - "python -m unittest discover -s . -p 'functional_test*.py'" + - "cd infracheck && ./functional-test.sh" + + :install: + description: Install via setuptools + steps: + - python3 ./setup.py install + + :image: + description: Build a docker image + arguments: + "--git-tag": + help: "Will tag the image considering this version" + required: False + "--push": + help: "Push or only build?" + action: store_true + "--arch": + help: "Architecture name" + default: "x86_64" + steps: | + #!python + tag = ctx.get_arg('--git-tag') + should_push = ctx.get_arg('--push') + arch = ctx.get_arg('--arch') + docker_tag = 'latest-dev-' + arch + repo = os.getenv('REPO') + + if tag: + docker_tag = arch + '-' + tag + + image_name = '{repo}:{tag}'.format(tag=docker_tag, repo=repo) + + this.sh('docker build . -f ./.infrastructure/{docker_arch}.Dockerfile -t {image}' + .format(docker_arch=arch, image=image_name)) + + this.sh('docker tag {image} {image}-$(date "+%Y-%m-%d")'.format(image=image_name)) + + if should_push: + this.sh('docker push {image}'.format(image=image_name)) + this.sh('docker push {image}-$(date "+%Y-%m-%d")'.format(image=image_name)) + + :release:pypi: + description: Release to PyPI + steps: + - "%RKD% :py:build" + - "%RKD% :py:publish --password=${PYPI_PASSWORD} --username=__token__ --skip-existing" + + :release:docker:x86: + description: Release into docker registry (x86 image) + arguments: + "--git-tag": + help: "Git tag name" + required: true + steps: + - "%RKD% :image --push --git-tag=${ARG_GIT_TAG} --arch=x86_64" + + :release:docker:arm: + description: Release into docker registry (arm image) + arguments: + "--git-tag": + help: "Git tag name" + required: true + steps: + - "%RKD% :image --push --git-tag=${ARG_GIT_TAG} --arch=arm" diff --git a/Pipfile b/Pipfile deleted file mode 100644 index cdf0667..0000000 --- a/Pipfile +++ /dev/null @@ -1,19 +0,0 @@ -[[source]] -name = "pypi" -url = "https://pypi.org/simple" -verify_ssl = true - -[dev-packages] -coverage = "*" -unittest-data-provider = "*" -mock = "*" -docker = "*" - -[packages] -tornado = ">=5.1,<6.0" -pytz = "*" -whois = "*" -ovh = "*" -python-dateutil = "*" -psutil = "*" -psycopg2-binary = "*" diff --git a/Pipfile.lock b/Pipfile.lock deleted file mode 100644 index 7d4bdc8..0000000 --- a/Pipfile.lock +++ /dev/null @@ -1,236 +0,0 @@ -{ - "_meta": { - "hash": { - "sha256": "3c1f3ba3b33471aa42b8e292d38eac383e6b8b113fc117d6c192af2a61de2cd1" - }, - "pipfile-spec": 6, - "requires": {}, - "sources": [ - { - "name": "pypi", - "url": "https://pypi.org/simple", - "verify_ssl": true - } - ] - }, - "default": { - "ovh": { - "hashes": [ - "sha256:03c7a5e7a62e7bc09b899f7692c694360be7db93ebe44428d6605fccda244692", - "sha256:f74d190c4bff0953d76124cb8ed319a8a999138720e42957f0db481ef4746ae8" - ], - "index": "pypi", - "version": "==0.5.0" - }, - "psutil": { - "hashes": [ - "sha256:094f899ac3ef72422b7e00411b4ed174e3c5a2e04c267db6643937ddba67a05b", - "sha256:10b7f75cc8bd676cfc6fa40cd7d5c25b3f45a0e06d43becd7c2d2871cbb5e806", - "sha256:1b1575240ca9a90b437e5a40db662acd87bbf181f6aa02f0204978737b913c6b", - "sha256:21231ef1c1a89728e29b98a885b8e0a8e00d09018f6da5cdc1f43f988471a995", - "sha256:28f771129bfee9fc6b63d83a15d857663bbdcae3828e1cb926e91320a9b5b5cd", - "sha256:70387772f84fa5c3bb6a106915a2445e20ac8f9821c5914d7cbde148f4d7ff73", - "sha256:b560f5cd86cf8df7bcd258a851ca1ad98f0d5b8b98748e877a0aec4e9032b465", - "sha256:b74b43fecce384a57094a83d2778cdfc2e2d9a6afaadd1ebecb2e75e0d34e10d", - "sha256:e85f727ffb21539849e6012f47b12f6dd4c44965e56591d8dec6e8bc9ab96f4a", - "sha256:fd2e09bb593ad9bdd7429e779699d2d47c1268cbde4dda95fcd1bd17544a0217", - "sha256:ffad8eb2ac614518bbe3c0b8eb9dffdb3a8d2e3a7d5da51c5b974fb723a5c5aa" - ], - "index": "pypi", - "version": "==5.6.7" - }, - "psycopg2-binary": { - "hashes": [ - "sha256:040234f8a4a8dfd692662a8308d78f63f31a97e1c42d2480e5e6810c48966a29", - "sha256:086f7e89ec85a6704db51f68f0dcae432eff9300809723a6e8782c41c2f48e03", - "sha256:18ca813fdb17bc1db73fe61b196b05dd1ca2165b884dd5ec5568877cabf9b039", - "sha256:19dc39616850342a2a6db70559af55b22955f86667b5f652f40c0e99253d9881", - "sha256:2166e770cb98f02ed5ee2b0b569d40db26788e0bf2ec3ae1a0d864ea6f1d8309", - "sha256:3a2522b1d9178575acee4adf8fd9f979f9c0449b00b4164bb63c3475ea6528ed", - "sha256:3aa773580f85a28ffdf6f862e59cb5a3cc7ef6885121f2de3fca8d6ada4dbf3b", - "sha256:3b5deaa3ee7180585a296af33e14c9b18c218d148e735c7accf78130765a47e3", - "sha256:407af6d7e46593415f216c7f56ba087a9a42bd6dc2ecb86028760aa45b802bd7", - "sha256:4c3c09fb674401f630626310bcaf6cd6285daf0d5e4c26d6e55ca26a2734e39b", - "sha256:4c6717962247445b4f9e21c962ea61d2e884fc17df5ddf5e35863b016f8a1f03", - "sha256:50446fae5681fc99f87e505d4e77c9407e683ab60c555ec302f9ac9bffa61103", - "sha256:5057669b6a66aa9ca118a2a860159f0ee3acf837eda937bdd2a64f3431361a2d", - "sha256:5dd90c5438b4f935c9d01fcbad3620253da89d19c1f5fca9158646407ed7df35", - "sha256:659c815b5b8e2a55193ede2795c1e2349b8011497310bb936da7d4745652823b", - "sha256:69b13fdf12878b10dc6003acc8d0abf3ad93e79813fd5f3812497c1c9fb9be49", - "sha256:7a1cb80e35e1ccea3e11a48afe65d38744a0e0bde88795cc56a4d05b6e4f9d70", - "sha256:7e6e3c52e6732c219c07bd97fff6c088f8df4dae3b79752ee3a817e6f32e177e", - "sha256:7f42a8490c4fe854325504ce7a6e4796b207960dabb2cbafe3c3959cb00d1d7e", - "sha256:84156313f258eafff716b2961644a4483a9be44a5d43551d554844d15d4d224e", - "sha256:8578d6b8192e4c805e85f187bc530d0f52ba86c39172e61cd51f68fddd648103", - "sha256:890167d5091279a27e2505ff0e1fb273f8c48c41d35c5b92adbf4af80e6b2ed6", - "sha256:98e10634792ac0e9e7a92a76b4991b44c2325d3e7798270a808407355e7bb0a1", - "sha256:9aadff9032e967865f9778485571e93908d27dab21d0fdfdec0ca779bb6f8ad9", - "sha256:9f24f383a298a0c0f9b3113b982e21751a8ecde6615494a3f1470eb4a9d70e9e", - "sha256:a73021b44813b5c84eda4a3af5826dd72356a900bac9bd9dd1f0f81ee1c22c2f", - "sha256:afd96845e12638d2c44d213d4810a08f4dc4a563f9a98204b7428e567014b1cd", - "sha256:b73ddf033d8cd4cc9dfed6324b1ad2a89ba52c410ef6877998422fcb9c23e3a8", - "sha256:b8f490f5fad1767a1331df1259763b3bad7d7af12a75b950c2843ba319b2415f", - "sha256:dbc5cd56fff1a6152ca59445178652756f4e509f672e49ccdf3d79c1043113a4", - "sha256:eac8a3499754790187bb00574ab980df13e754777d346f85e0ff6df929bcd964", - "sha256:eaed1c65f461a959284649e37b5051224f4db6ebdc84e40b5e65f2986f101a08" - ], - "index": "pypi", - "version": "==2.8.4" - }, - "python-dateutil": { - "hashes": [ - "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c", - "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a" - ], - "index": "pypi", - "version": "==2.8.1" - }, - "pytz": { - "hashes": [ - "sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d", - "sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be" - ], - "index": "pypi", - "version": "==2019.3" - }, - "six": { - "hashes": [ - "sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd", - "sha256:30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66" - ], - "version": "==1.13.0" - }, - "tornado": { - "hashes": [ - "sha256:0662d28b1ca9f67108c7e3b77afabfb9c7e87bde174fbda78186ecedc2499a9d", - "sha256:4e5158d97583502a7e2739951553cbd88a72076f152b4b11b64b9a10c4c49409", - "sha256:732e836008c708de2e89a31cb2fa6c0e5a70cb60492bee6f1ea1047500feaf7f", - "sha256:8154ec22c450df4e06b35f131adc4f2f3a12ec85981a203301d310abf580500f", - "sha256:8e9d728c4579682e837c92fdd98036bd5cdefa1da2aaf6acf26947e6dd0c01c5", - "sha256:d4b3e5329f572f055b587efc57d29bd051589fb5a43ec8898c77a47ec2fa2bbb", - "sha256:e5f2585afccbff22390cddac29849df463b252b711aa2ce7c5f3f342a5b3b444" - ], - "index": "pypi", - "version": "==5.1.1" - }, - "whois": { - "hashes": [ - "sha256:ee7fd23b13cdf33b94d633a31edac9f4e4015a72455f5d669837a8ad100612ce" - ], - "index": "pypi", - "version": "==0.9.4" - } - }, - "develop": { - "certifi": { - "hashes": [ - "sha256:017c25db2a153ce562900032d5bc68e9f191e44e9a0f762f373977de9df1fbb3", - "sha256:25b64c7da4cd7479594d035c08c2d809eb4aab3a26e5a990ea98cc450c320f1f" - ], - "version": "==2019.11.28" - }, - "chardet": { - "hashes": [ - "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", - "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" - ], - "version": "==3.0.4" - }, - "coverage": { - "hashes": [ - "sha256:08907593569fe59baca0bf152c43f3863201efb6113ecb38ce7e97ce339805a6", - "sha256:0be0f1ed45fc0c185cfd4ecc19a1d6532d72f86a2bac9de7e24541febad72650", - "sha256:141f08ed3c4b1847015e2cd62ec06d35e67a3ac185c26f7635f4406b90afa9c5", - "sha256:19e4df788a0581238e9390c85a7a09af39c7b539b29f25c89209e6c3e371270d", - "sha256:23cc09ed395b03424d1ae30dcc292615c1372bfba7141eb85e11e50efaa6b351", - "sha256:245388cda02af78276b479f299bbf3783ef0a6a6273037d7c60dc73b8d8d7755", - "sha256:331cb5115673a20fb131dadd22f5bcaf7677ef758741312bee4937d71a14b2ef", - "sha256:386e2e4090f0bc5df274e720105c342263423e77ee8826002dcffe0c9533dbca", - "sha256:3a794ce50daee01c74a494919d5ebdc23d58873747fa0e288318728533a3e1ca", - "sha256:60851187677b24c6085248f0a0b9b98d49cba7ecc7ec60ba6b9d2e5574ac1ee9", - "sha256:63a9a5fc43b58735f65ed63d2cf43508f462dc49857da70b8980ad78d41d52fc", - "sha256:6b62544bb68106e3f00b21c8930e83e584fdca005d4fffd29bb39fb3ffa03cb5", - "sha256:6ba744056423ef8d450cf627289166da65903885272055fb4b5e113137cfa14f", - "sha256:7494b0b0274c5072bddbfd5b4a6c6f18fbbe1ab1d22a41e99cd2d00c8f96ecfe", - "sha256:826f32b9547c8091679ff292a82aca9c7b9650f9fda3e2ca6bf2ac905b7ce888", - "sha256:93715dffbcd0678057f947f496484e906bf9509f5c1c38fc9ba3922893cda5f5", - "sha256:9a334d6c83dfeadae576b4d633a71620d40d1c379129d587faa42ee3e2a85cce", - "sha256:af7ed8a8aa6957aac47b4268631fa1df984643f07ef00acd374e456364b373f5", - "sha256:bf0a7aed7f5521c7ca67febd57db473af4762b9622254291fbcbb8cd0ba5e33e", - "sha256:bf1ef9eb901113a9805287e090452c05547578eaab1b62e4ad456fcc049a9b7e", - "sha256:c0afd27bc0e307a1ffc04ca5ec010a290e49e3afbe841c5cafc5c5a80ecd81c9", - "sha256:dd579709a87092c6dbee09d1b7cfa81831040705ffa12a1b248935274aee0437", - "sha256:df6712284b2e44a065097846488f66840445eb987eb81b3cc6e4149e7b6982e1", - "sha256:e07d9f1a23e9e93ab5c62902833bf3e4b1f65502927379148b6622686223125c", - "sha256:e2ede7c1d45e65e209d6093b762e98e8318ddeff95317d07a27a2140b80cfd24", - "sha256:e4ef9c164eb55123c62411f5936b5c2e521b12356037b6e1c2617cef45523d47", - "sha256:eca2b7343524e7ba246cab8ff00cab47a2d6d54ada3b02772e908a45675722e2", - "sha256:eee64c616adeff7db37cc37da4180a3a5b6177f5c46b187894e633f088fb5b28", - "sha256:ef824cad1f980d27f26166f86856efe11eff9912c4fed97d3804820d43fa550c", - "sha256:efc89291bd5a08855829a3c522df16d856455297cf35ae827a37edac45f466a7", - "sha256:fa964bae817babece5aa2e8c1af841bebb6d0b9add8e637548809d040443fee0", - "sha256:ff37757e068ae606659c28c3bd0d923f9d29a85de79bf25b2b34b148473b5025" - ], - "index": "pypi", - "version": "==4.5.4" - }, - "docker": { - "hashes": [ - "sha256:6e06c5e70ba4fad73e35f00c55a895a448398f3ada7faae072e2bb01348bafc1", - "sha256:8f93775b8bdae3a2df6bc9a5312cce564cade58d6555f2c2570165a1270cd8a7" - ], - "index": "pypi", - "version": "==4.1.0" - }, - "idna": { - "hashes": [ - "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407", - "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c" - ], - "version": "==2.8" - }, - "mock": { - "hashes": [ - "sha256:83657d894c90d5681d62155c82bda9c1187827525880eda8ff5df4ec813437c3", - "sha256:d157e52d4e5b938c550f39eb2fd15610db062441a9c2747d3dbfa9298211d0f8" - ], - "index": "pypi", - "version": "==3.0.5" - }, - "requests": { - "hashes": [ - "sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4", - "sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31" - ], - "version": "==2.22.0" - }, - "six": { - "hashes": [ - "sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd", - "sha256:30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66" - ], - "version": "==1.13.0" - }, - "unittest-data-provider": { - "hashes": [ - "sha256:86bc7fb6608c2570aeedadea346fe3034afc940807dd7519e95e5dbc899ac2be" - ], - "index": "pypi", - "version": "==1.0.1" - }, - "urllib3": { - "hashes": [ - "sha256:a8a318824cc77d1fd4b2bec2ded92646630d7fe8619497b142c84a9e6f5a7293", - "sha256:f3c5fd51747d450d4dcf6f923c81f78f811aab8205fda64b0aba34a4e48b0745" - ], - "version": "==1.25.7" - }, - "websocket-client": { - "hashes": [ - "sha256:1151d5fb3a62dc129164292e1227655e4bbc5dd5340a5165dfae61128ec50aa9", - "sha256:1fd5520878b68b84b5748bb30e592b10d0a91529d5383f74f4964e72b297fd3a" - ], - "version": "==0.56.0" - } - } -} diff --git a/docs/source/index.rst b/docs/source/index.rst index b79a9df..5f18c06 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -3,7 +3,7 @@ RiotKit's Infracheck ==================== HTTP healthcheck endpoint + shell healthcheck runner. -Simple, easy to setup, easy to understand. Works perfectly with Docker. +Simple, easy to setup, easy to understand. Works perfectly with Docker. A perfectly fitting universal brick in your monitoring. .. code:: json diff --git a/requirements.txt b/requirements.txt index 0b8bb51..cc3f118 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,11 @@ -ovh==0.5.0 -psutil==5.6.7 -psycopg2-binary==2.8.4 -python-dateutil==2.8.1 -pytz==2019.3 -six==1.13.0 -tornado==5.1.1 -whois==0.9.4 +ovh >= 0.5.0, <0.6 +psutil >= 5.7.2, < 6 +psycopg2-binary >= 2.8.4, < 3 +python-dateutil >= 2.8.1, < 3 +pytz >= 2019.3 +six >= 1.15.0, < 2 +tornado >= 5.1.1, < 6 +whois >= 0.9.4, < 1 + +rkd>=2.2, <3 +rkd-python>=2.2, <3 diff --git a/setup-venv.sh b/setup-venv.sh new file mode 100755 index 0000000..a4607e9 --- /dev/null +++ b/setup-venv.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +if test -d .venv; then + echo "source ./.venv/bin/activate" + exit 0 +fi + +virtualenv .venv +source ./.venv/bin/activate +pip install -r requirements.txt +echo "source ./.venv/bin/activate" diff --git a/setup.cfg b/setup.cfg index c54ae20..b5b6c88 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [metadata] name = infracheck author = RiotKit Collective -author_email = marek_andrzejczak@riseup.net +author_email = riotkit@riseup.net summary = KISS healthcheck implemented in Python and Bash license = MIT description-file = DESCRIPTION.rst