From 18061966d7cb1f7c120a861243a1143ca368f4f6 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sat, 19 Mar 2022 00:23:10 +0100 Subject: [PATCH] [TASK] Finish building first working release --- .gitignore | 8 ++++++++ Dockerfile | 8 ++++++++ Makefile | 28 ++++++++++++++++++++++++++++ check | 1 - check.in.dist.json | 17 +++++++++++++++++ check_test.py | 15 +++++++++++++++ in.in.dist.json | 17 +++++++++++++++++ in_test.py | 15 +++++++++++++++ out | 18 ++++++++++++------ out.in.dist.json | 17 +++++++++++++++++ out_test.py | 15 +++++++++++++++ requirements.txt | 11 +++++++++++ tmp.in/.keep | 0 tmp.out/.keep | 0 14 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 check.in.dist.json create mode 100755 check_test.py create mode 100644 in.in.dist.json create mode 100755 in_test.py create mode 100644 out.in.dist.json create mode 100755 out_test.py create mode 100644 requirements.txt create mode 100644 tmp.in/.keep create mode 100644 tmp.out/.keep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c9af961 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/env/ +/check.in.json +/in.in.json +/out.in.json +/tmp.out/* +!/tmp.out/.keep +/tmp.in/* +!/tmp.in/.keep diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1ca0b2b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +# syntax=docker/dockerfile:1 + +FROM python:3.8-slim-buster + +COPY requirements.txt requirements.txt +RUN pip3 install -r requirements.txt + +COPY check in out /opt/resource/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b58dc74 --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +.SILENT: + +make_and_deploy: + docker build --tag aptly-resource . + docker tag aptly-resource:latest docker.datentonne.net/concourse/aptly-resource:latest + docker push docker.datentonne.net/concourse/aptly-resource:latest + +test_check: + HTTPS_PROXY="http://localhost:8080" \ + CURL_CA_BUNDLE="${HOME}/.mitmproxy/mitmproxy-ca-cert.pem" \ + ./check_test.py + +test_in: + HTTPS_PROXY="http://localhost:8080" \ + CURL_CA_BUNDLE="${HOME}/.mitmproxy/mitmproxy-ca-cert.pem" \ + ./in_test.py + +test_out: + HTTPS_PROXY="http://localhost:8080" \ + CURL_CA_BUNDLE="${HOME}/.mitmproxy/mitmproxy-ca-cert.pem" \ + ./out_test.py + +proxy: + mitmproxy \ + --set keep_host_header=true \ + --set console_flowlist_layout=list \ + --set console_mouse=false \ + --set view_order_reversed=true diff --git a/check b/check index a8bd22c..6751aba 100755 --- a/check +++ b/check @@ -20,7 +20,6 @@ import semver root = os.path.dirname(os.path.abspath(__file__)) config = json.loads(sys.stdin.read()) -directory = sys.argv[1] previous_version = False if 'version' in config and 'version' in config['version']: diff --git a/check.in.dist.json b/check.in.dist.json new file mode 100644 index 0000000..20f695b --- /dev/null +++ b/check.in.dist.json @@ -0,0 +1,17 @@ +{ + "source": { + "api_uri": "", + "repo_uri": "", + "repo": "", + "distribution": "debian", + "component": "main", + "architecture": "amd64", + "package": "", + "username": "", + "password": "", + "timeout": 1800 + }, + "version": { + "version": "" + } +} diff --git a/check_test.py b/check_test.py new file mode 100755 index 0000000..0972f10 --- /dev/null +++ b/check_test.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +''' +aptly-resource test out +''' + +from subprocess import run + +with open('check.in.json', 'r', encoding='utf-8') as f: + contents = f.read() + +run(['./check tmp'], + input = contents.encode(), + check = True, + shell = True, + ) diff --git a/in.in.dist.json b/in.in.dist.json new file mode 100644 index 0000000..20f695b --- /dev/null +++ b/in.in.dist.json @@ -0,0 +1,17 @@ +{ + "source": { + "api_uri": "", + "repo_uri": "", + "repo": "", + "distribution": "debian", + "component": "main", + "architecture": "amd64", + "package": "", + "username": "", + "password": "", + "timeout": 1800 + }, + "version": { + "version": "" + } +} diff --git a/in_test.py b/in_test.py new file mode 100755 index 0000000..4c1c5d5 --- /dev/null +++ b/in_test.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +''' +aptly-resource test out +''' + +from subprocess import run + +with open('in.in.json', 'r', encoding='utf-8') as f: + contents = f.read() + +run(['./in tmp.in'], + input = contents.encode(), + check = True, + shell = True, + ) diff --git a/out b/out index 5c24317..b7bf357 100755 --- a/out +++ b/out @@ -58,25 +58,31 @@ archive_filename_parts = archive_filename.split('_') file_hash = hashlib.sha256() -with open(directory + '/' + archive_filename, 'rb') as f: +with open(directory + '/' + archive_path, 'rb') as f: fb = f.read(BLOCK_SIZE) while len(fb) > 0: file_hash.update(fb) fb = f.read(BLOCK_SIZE) -#aptly.files.upload( -# config['source']['repo'], -# directory + '/' + archive_path -# ) +aptly.files.upload( + config['source']['repo'], + directory + '/' + archive_path + ) aptly.repos.add_uploaded_file( reponame = config['source']['repo'], dir = config['source']['repo'], - remove_processed_files = False, + remove_processed_files = True, force_replace = True ) +aptly.publish.update( + prefix = config['source']['repo'], + distribution = config['source']['distribution'], + force_overwrite = True + ) + print(json.dumps({ 'version': {'version': archive_filename_parts[1]}, 'metadata': [ diff --git a/out.in.dist.json b/out.in.dist.json new file mode 100644 index 0000000..a74b990 --- /dev/null +++ b/out.in.dist.json @@ -0,0 +1,17 @@ +{ + "source": { + "api_uri": "", + "repo_uri": "", + "repo": "", + "distribution": "debian", + "component": "main", + "architecture": "amd64", + "package": "", + "username": "", + "password": "", + "timeout": 1800 + }, + "params": { + "archive_file": "filename" + } +} diff --git a/out_test.py b/out_test.py new file mode 100755 index 0000000..d44aae1 --- /dev/null +++ b/out_test.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +''' +aptly-resource test out +''' + +from subprocess import run + +with open('out.in.json', 'r', encoding='utf-8') as f: + contents = f.read() + +run(['./out tmp.out'], + input = contents.encode(), + check = True, + shell = True, + ) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..67e5938 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,11 @@ +aptly-api-client==0.2.3 +certifi==2021.10.8 +charset-normalizer==2.0.12 +idna==3.3 +iso8601==1.0.2 +pytz==2021.3 +PyYAML==6.0 +requests==2.27.1 +semver==2.13.0 +typing==3.7.4.3 +urllib3==1.26.8 diff --git a/tmp.in/.keep b/tmp.in/.keep new file mode 100644 index 0000000..e69de29 diff --git a/tmp.out/.keep b/tmp.out/.keep new file mode 100644 index 0000000..e69de29