From b24af469a15d172e91e9fb46fb393d1f2422060e Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Wed, 20 Dec 2023 13:38:26 +0100 Subject: [PATCH 01/20] [#13] Test: removed python:3 agent --- Jenkinsfile | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 37b8ab8..65ea60f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,10 +1,4 @@ pipeline { - agent { - docker { - image 'python:3' - args '-u root' - } - } environment { GITEA_CREDS = credentials('AMARILLO-JENKINS-GITEA-USER') TWINE_REPO_URL = "https://git.gerhardt.io/api/packages/amarillo/pypi" @@ -14,46 +8,6 @@ pipeline { TAG = 'latest' } stages { - stage('Create virtual environment') { - steps { - echo 'Creating virtual environment' - sh '''python -m venv .venv - . .venv/bin/activate''' - - } - } - stage('Installing requirements') { - steps { - echo 'Installing packages' - sh 'python -m pip install -r requirements.txt' - sh 'python -m pip install --upgrade build' - sh 'python -m pip install --upgrade twine' - } - } - stage('Test') { - steps { - echo 'Testing' - } - } - stage('Build package') { - steps { - echo 'Building package' - sh 'python -m build' - } - } - stage('Publish package') { - steps { - sh 'python -m twine upload --skip-existing --verbose --repository-url $TWINE_REPO_URL --username $GITEA_CREDS_USR --password $GITEA_CREDS_PSW ./dist/*' - } - } - stage('Install docker') { - steps { - echo 'Installing docker' - sh 'curl -fsSl https://get.docker.com | sh' - echo 'Starting docker daemon' - sh 'systemctl start docker' - } - } stage('Build docker image') { steps { echo 'Building image' From 3a4e2ce422a403e27ca897ae88057009e2cdd2ca Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Wed, 20 Dec 2023 13:40:44 +0100 Subject: [PATCH 02/20] [#13] Added agent any --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 65ea60f..c28f8cc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,5 @@ pipeline { + agent any environment { GITEA_CREDS = credentials('AMARILLO-JENKINS-GITEA-USER') TWINE_REPO_URL = "https://git.gerhardt.io/api/packages/amarillo/pypi" From 2447c966e34bccd6af050f4489d6b9c1e0539cc1 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Wed, 20 Dec 2023 13:48:29 +0100 Subject: [PATCH 03/20] [#13] use quotes around 'GITEA_CREDS' --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index c28f8cc..8d451e2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,7 @@ pipeline { steps { echo 'Pushing image to registry' script { - docker.withRegistry(REGISTRY_URL, GITEA_CREDS){ + docker.withRegistry(REGISTRY_URL, 'GITEA_CREDS'){ docker.image("${OWNER}/${IMAGE_NAME}:${TAG}").push() } } From 05efd6e5116c7e376642fced21ef1c8a544b26fa Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Wed, 20 Dec 2023 13:49:47 +0100 Subject: [PATCH 04/20] [#13] Changed credentials id --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8d451e2..c0e9b02 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,7 @@ pipeline { steps { echo 'Pushing image to registry' script { - docker.withRegistry(REGISTRY_URL, 'GITEA_CREDS'){ + docker.withRegistry(REGISTRY_URL, 'AMARILLO-JENKINS-GITEA-USER'){ docker.image("${OWNER}/${IMAGE_NAME}:${TAG}").push() } } From 2be873c0a8784fc3a6845ba5d8f7435de8bcf83e Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Wed, 20 Dec 2023 13:54:20 +0100 Subject: [PATCH 05/20] [#13] Fixed registry URL --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index c0e9b02..2b6ebf7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,7 @@ pipeline { environment { GITEA_CREDS = credentials('AMARILLO-JENKINS-GITEA-USER') TWINE_REPO_URL = "https://git.gerhardt.io/api/packages/amarillo/pypi" - REGISTRY_URL = 'git.gerhardt.io' + REGISTRY_URL = 'https://git.gerhardt.io' OWNER = 'amarillo' IMAGE_NAME = "amarillo" TAG = 'latest' From 9fb3d6d331cefa4a92b65dfecc3fbf8d7e00643a Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Thu, 21 Dec 2023 14:57:20 +0100 Subject: [PATCH 06/20] #13 install plugins in docker image --- Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index 121613c..b76e075 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,8 +22,13 @@ ENV METRICS_PASSWORD='' EXPOSE 80 +ARG PACKAGE_REGISTRY_URL +ARG PLUGINS + COPY requirements.txt /app/requirements.txt RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt +RUN --mount=type=secret,id=AMARILLO_REGISTRY_CREDENTIALS \ + pip install --no-cache-dir --upgrade --extra-index-url https://$(cat /run/secrets/AMARILLO_REGISTRY_CREDENTIALS)@${PACKAGE_REGISTRY_URL} ${PLUGINS} COPY ./amarillo/app /app/amarillo/app COPY ./amarillo/plugins /app/amarillo/plugins From d09868b184831a27684ef9a4715081d99a79cf44 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Tue, 9 Jan 2024 13:53:22 +0100 Subject: [PATCH 07/20] #13 Jenkinsfile docker build arguments --- Jenkinsfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2b6ebf7..5a2a1ba 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,15 +5,17 @@ pipeline { TWINE_REPO_URL = "https://git.gerhardt.io/api/packages/amarillo/pypi" REGISTRY_URL = 'https://git.gerhardt.io' OWNER = 'amarillo' - IMAGE_NAME = "amarillo" + IMAGE_NAME = 'amarillo' TAG = 'latest' + PLUGINS = 'amarillo-metrics amarillo-enhancer' } stages { stage('Build docker image') { steps { echo 'Building image' script { - docker.build("${OWNER}/${IMAGE_NAME}:${TAG}") + docker.build("${OWNER}/${IMAGE_NAME}:${TAG}", + "--build-arg='PACKAGE_REGISTRY_URL=${REGISTRY_URL}' --build-arg='PLUGINS=${PLUGINS}' --secret id=AMARILLO_REGISTRY_CREDENTIALS,env=GITEA_CREDS .") } } } From e8d484d58859790e341ea8c2b0996a0ac123c919 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Tue, 9 Jan 2024 14:30:48 +0100 Subject: [PATCH 08/20] #13 Fixed package registry url --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5a2a1ba..ff5b947 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,7 +2,7 @@ pipeline { agent any environment { GITEA_CREDS = credentials('AMARILLO-JENKINS-GITEA-USER') - TWINE_REPO_URL = "https://git.gerhardt.io/api/packages/amarillo/pypi" + TWINE_REPO_URL = "git.gerhardt.io/api/packages/amarillo/pypi" REGISTRY_URL = 'https://git.gerhardt.io' OWNER = 'amarillo' IMAGE_NAME = 'amarillo' @@ -15,7 +15,7 @@ pipeline { echo 'Building image' script { docker.build("${OWNER}/${IMAGE_NAME}:${TAG}", - "--build-arg='PACKAGE_REGISTRY_URL=${REGISTRY_URL}' --build-arg='PLUGINS=${PLUGINS}' --secret id=AMARILLO_REGISTRY_CREDENTIALS,env=GITEA_CREDS .") + "--build-arg='PACKAGE_REGISTRY_URL=${TWINE_REPO_URL}' --build-arg='PLUGINS=${PLUGINS}' --secret id=AMARILLO_REGISTRY_CREDENTIALS,env=GITEA_CREDS .") } } } From 07f975dc91c5be6544ce2f77c8380d47ee553b71 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Tue, 9 Jan 2024 14:38:44 +0100 Subject: [PATCH 09/20] #13 separated plugins repo url --- Jenkinsfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ff5b947..7104ffa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,8 +2,9 @@ pipeline { agent any environment { GITEA_CREDS = credentials('AMARILLO-JENKINS-GITEA-USER') - TWINE_REPO_URL = "git.gerhardt.io/api/packages/amarillo/pypi" - REGISTRY_URL = 'https://git.gerhardt.io' + TWINE_REPO_URL = "https://git.gerhardt.io/api/packages/amarillo/pypi" + PLUGINS_REPO_URL = "git.gerhardt.io/api/packages/amarillo/pypi/simple" + DOCKER_REGISTRY_URL = 'https://git.gerhardt.io' OWNER = 'amarillo' IMAGE_NAME = 'amarillo' TAG = 'latest' @@ -15,7 +16,7 @@ pipeline { echo 'Building image' script { docker.build("${OWNER}/${IMAGE_NAME}:${TAG}", - "--build-arg='PACKAGE_REGISTRY_URL=${TWINE_REPO_URL}' --build-arg='PLUGINS=${PLUGINS}' --secret id=AMARILLO_REGISTRY_CREDENTIALS,env=GITEA_CREDS .") + "--build-arg='PACKAGE_REGISTRY_URL=${PLUGINS_REPO_URL}' --build-arg='PLUGINS=${PLUGINS}' --secret id=AMARILLO_REGISTRY_CREDENTIALS,env=GITEA_CREDS .") } } } @@ -23,7 +24,7 @@ pipeline { steps { echo 'Pushing image to registry' script { - docker.withRegistry(REGISTRY_URL, 'AMARILLO-JENKINS-GITEA-USER'){ + docker.withRegistry(DOCKER_REGISTRY_URL, 'AMARILLO-JENKINS-GITEA-USER'){ docker.image("${OWNER}/${IMAGE_NAME}:${TAG}").push() } } From 0a783938e75c0b611a2d88ee95ab0b05b8c9db9d Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Thu, 11 Jan 2024 12:59:35 +0100 Subject: [PATCH 10/20] #13 Test running commands inside container --- Jenkinsfile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 7104ffa..78b0b0a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,6 +20,20 @@ pipeline { } } } + stage('Run tests on image'){ + steps{ + docker.image("${OWNER}/${IMAGE_NAME}:${TAG}").inside( + '--rm --name amarillo -p 8000:80 -e MODULE_NAME=amarillo.app.main -e MAX_WORKERS=1 -e ADMIN_TOKEN=test -e RIDE2GO_TOKEN=test -e METRICS_USER=test -e METRICS_PASSWORD=test -e TZ=Europe/Berlin -v $(pwd)/data:/app/data' + ){ + // TODO: wait until the API is up + c -> sh script: """ + sleep 10 + echo Testing... + pytest + """ + } + } + } stage('Push image to container registry') { steps { echo 'Pushing image to registry' From 08daefd6201e1e44ca79f51017f4a89f68296753 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Thu, 11 Jan 2024 13:02:16 +0100 Subject: [PATCH 11/20] #13 wrap docker command in script block --- Jenkinsfile | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 78b0b0a..c2183d5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -22,15 +22,17 @@ pipeline { } stage('Run tests on image'){ steps{ - docker.image("${OWNER}/${IMAGE_NAME}:${TAG}").inside( - '--rm --name amarillo -p 8000:80 -e MODULE_NAME=amarillo.app.main -e MAX_WORKERS=1 -e ADMIN_TOKEN=test -e RIDE2GO_TOKEN=test -e METRICS_USER=test -e METRICS_PASSWORD=test -e TZ=Europe/Berlin -v $(pwd)/data:/app/data' - ){ - // TODO: wait until the API is up - c -> sh script: """ - sleep 10 - echo Testing... - pytest - """ + script { + docker.image("${OWNER}/${IMAGE_NAME}:${TAG}").inside( + '--rm --name amarillo -p 8000:80 -e MODULE_NAME=amarillo.app.main -e MAX_WORKERS=1 -e ADMIN_TOKEN=test -e RIDE2GO_TOKEN=test -e METRICS_USER=test -e METRICS_PASSWORD=test -e TZ=Europe/Berlin -v $(pwd)/data:/app/data' + ){ + // TODO: wait until the API is up + c -> sh script: """ + sleep 10 + echo Testing... + pytest + """ + } } } } From 64fe8b5571413b4133d1d9f341ec94f004f88edb Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Thu, 11 Jan 2024 13:11:24 +0100 Subject: [PATCH 12/20] #13 fix working directory in volume mount --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index c2183d5..6d19c01 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,7 +24,7 @@ pipeline { steps{ script { docker.image("${OWNER}/${IMAGE_NAME}:${TAG}").inside( - '--rm --name amarillo -p 8000:80 -e MODULE_NAME=amarillo.app.main -e MAX_WORKERS=1 -e ADMIN_TOKEN=test -e RIDE2GO_TOKEN=test -e METRICS_USER=test -e METRICS_PASSWORD=test -e TZ=Europe/Berlin -v $(pwd)/data:/app/data' + "--rm --name amarillo -p 8000:80 -e MODULE_NAME=amarillo.app.main -e MAX_WORKERS=1 -e ADMIN_TOKEN=test -e RIDE2GO_TOKEN=test -e METRICS_USER=test -e METRICS_PASSWORD=test -e TZ=Europe/Berlin -v ${pwd()}/data:/app/data" ){ // TODO: wait until the API is up c -> sh script: """ From 45e2426b35307be2d1a90c4815d6c013bfef0832 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Thu, 11 Jan 2024 13:58:05 +0100 Subject: [PATCH 13/20] #13 stops store and trip store tests --- MANIFEST.in | 3 +- amarillo/app/tests/__init__.py | 0 amarillo/app/tests/stops.csv | 5 ++++ amarillo/app/tests/stops.json | 39 ++++++++++++++++++++++++++ amarillo/app/tests/test_stops_store.py | 24 ++++++++++++++++ amarillo/app/tests/test_trip_store.py | 23 +++++++++++++++ pyproject.toml | 3 +- requirements.txt | 3 +- 8 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 amarillo/app/tests/__init__.py create mode 100644 amarillo/app/tests/stops.csv create mode 100644 amarillo/app/tests/stops.json create mode 100644 amarillo/app/tests/test_stops_store.py create mode 100644 amarillo/app/tests/test_trip_store.py diff --git a/MANIFEST.in b/MANIFEST.in index 5aae476..c3190c3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ -recursive-include amarillo/static/ * \ No newline at end of file +recursive-include amarillo/static/ * +recursive-include amarillo/app/tests/ * \ No newline at end of file diff --git a/amarillo/app/tests/__init__.py b/amarillo/app/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/amarillo/app/tests/stops.csv b/amarillo/app/tests/stops.csv new file mode 100644 index 0000000..ed419bb --- /dev/null +++ b/amarillo/app/tests/stops.csv @@ -0,0 +1,5 @@ +stop_id;stop_code;stop_lat;stop_lon;stop_name +mfdz:x;x;52.11901;14.2;Stop x +mfdz:y;y;53.1;14.01;Stop y +mfdz:z;z;54.11;14.0;Stop z +mfdz:Ang001;Ang001;53.11901;14.015776;Mitfahrbank Biesenbrow diff --git a/amarillo/app/tests/stops.json b/amarillo/app/tests/stops.json new file mode 100644 index 0000000..5744c13 --- /dev/null +++ b/amarillo/app/tests/stops.json @@ -0,0 +1,39 @@ +{ + "data": { + "pointsOfInterest": [ + { + "id": "14622", + "externalId": "bbnavi:12073:0001", + "name": "Parkbank", + "description": "Parkbank", + "dataProvider": { + "id": "1", + "name": "Administrator" + }, + "addresses": [ + { + "street": "Hauptstrasse", + "city": "Wittenberge", + "zip": "12345", + "geoLocation": { + "latitude": 52.9932971109789, + "longitude": 11.767383582547 + } + } + ], + "openStreetMap": { + "capacity": 112, + "capacityCharging": "2", + "capacityDisabled": "", + "fee": "No", + "lit": "Yes", + "parking": "", + "shelter": "No", + "surface": "", + "utilization": "", + "website": "" + } + } + ] + } +} \ No newline at end of file diff --git a/amarillo/app/tests/test_stops_store.py b/amarillo/app/tests/test_stops_store.py new file mode 100644 index 0000000..e70f774 --- /dev/null +++ b/amarillo/app/tests/test_stops_store.py @@ -0,0 +1,24 @@ +from amarillo.app.services import stops +from amarillo.app.models.Carpool import StopTime + +def test_load_stops_from_file(): + store = stops.StopsStore([{"url": "amarillo/app/tests/stops.csv", "vicinity": 50}]) + store.load_stop_sources() + assert len(store.stopsDataFrames[0]['stops']) > 0 + +def test_load_csv_stops_from_web_(): + store = stops.StopsStore([{"url": "https://data.mfdz.de/mfdz/stops/custom.csv", "vicinity": 50}]) + store.load_stop_sources() + assert len(store.stopsDataFrames[0]['stops']) > 0 + +def test_load_geojson_stops_from_web_(): + store = stops.StopsStore([{"url": "https://datahub.bbnavi.de/export/rideshare_points.geojson", "vicinity": 50}]) + store.load_stop_sources() + assert len(store.stopsDataFrames[0]['stops']) > 0 + +def test_find_closest_stop(): + store = stops.StopsStore([{"url": "amarillo/app/tests/stops.csv", "vicinity": 50}]) + store.load_stop_sources() + carpool_stop = StopTime(name="start", lat=53.1191, lon=14.01577) + stop = store.find_closest_stop(carpool_stop, 1000) + assert stop.name=='Mitfahrbank Biesenbrow' diff --git a/amarillo/app/tests/test_trip_store.py b/amarillo/app/tests/test_trip_store.py new file mode 100644 index 0000000..64a3665 --- /dev/null +++ b/amarillo/app/tests/test_trip_store.py @@ -0,0 +1,23 @@ +from amarillo.app.tests.sampledata import cp1, carpool_repeating +from amarillo.app.services.trips import TripStore +from amarillo.app.services.stops import StopsStore + + +import logging +logger = logging.getLogger(__name__) + +def test_trip_store_put_one_time_carpool(): + trip_store = TripStore(StopsStore()) + + t = trip_store.put_carpool(cp1) + assert t != None + assert len(t.stop_times) >= 2 + assert t.stop_times[0].stop_id == 'mfdz:12073:001' + assert t.stop_times[-1].stop_id == 'de:12073:900340137::3' + +def test_trip_store_put_repeating_carpool(): + trip_store = TripStore(StopsStore()) + + t = trip_store.put_carpool(carpool_repeating) + assert t != None + assert len(t.stop_times) >= 2 diff --git a/pyproject.toml b/pyproject.toml index a036372..1090010 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "amarillo-core" -version = "0.0.9" +version = "0.0.11" dependencies = [ "fastapi[all]==0.104.0", "geopandas==0.14", @@ -11,6 +11,7 @@ dependencies = [ "requests==2.31.0", "pyproj==3.6.1", "geojson-pydantic==1.0.1", + "pytest", ] [tool.setuptools.packages] diff --git a/requirements.txt b/requirements.txt index 8771f13..84b950e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ protobuf==3.20.3 starlette requests==2.31.0 pyproj==3.6.1 -geojson-pydantic==1.0.1 \ No newline at end of file +geojson-pydantic==1.0.1 +pytest \ No newline at end of file From 47024773a2ad9a9ac589a19cadf8b9cf10bd2f3f Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Thu, 11 Jan 2024 13:59:16 +0100 Subject: [PATCH 14/20] #13 Run pytest in Jenkinsfile --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6d19c01..e4bbe75 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -28,9 +28,9 @@ pipeline { ){ // TODO: wait until the API is up c -> sh script: """ - sleep 10 + sleep 15 echo Testing... - pytest + python -m pytest """ } } From 3965bd575ccc02565908bf9030ffe14853948bee Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Fri, 12 Jan 2024 12:26:33 +0100 Subject: [PATCH 15/20] #13 removed --rm from docker inside command --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index e4bbe75..e8fc9e1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,7 +24,7 @@ pipeline { steps{ script { docker.image("${OWNER}/${IMAGE_NAME}:${TAG}").inside( - "--rm --name amarillo -p 8000:80 -e MODULE_NAME=amarillo.app.main -e MAX_WORKERS=1 -e ADMIN_TOKEN=test -e RIDE2GO_TOKEN=test -e METRICS_USER=test -e METRICS_PASSWORD=test -e TZ=Europe/Berlin -v ${pwd()}/data:/app/data" + "--name amarillo -p 8000:80 -e MODULE_NAME=amarillo.app.main -e MAX_WORKERS=1 -e ADMIN_TOKEN=test -e RIDE2GO_TOKEN=test -e METRICS_USER=test -e METRICS_PASSWORD=test -e TZ=Europe/Berlin -v ${pwd()}/data:/app/data" ){ // TODO: wait until the API is up c -> sh script: """ From cfa05d4fb3a72ec5d89063d19f5547fa3d0e5631 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Tue, 16 Jan 2024 15:11:22 +0100 Subject: [PATCH 16/20] #13 Trigger deploy webhook --- Jenkinsfile | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e8fc9e1..2289bd4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,6 +9,8 @@ pipeline { IMAGE_NAME = 'amarillo' TAG = 'latest' PLUGINS = 'amarillo-metrics amarillo-enhancer' + DEPLOY_WEBHOOK_URL = 'http://amarillo.mfdz.de:8888/mitanand' + DEPLOY_SECRET = credentials('AMARILLO-JENKINS-DEPLOY-SECRET') } stages { stage('Build docker image') { @@ -20,22 +22,22 @@ pipeline { } } } - stage('Run tests on image'){ - steps{ - script { - docker.image("${OWNER}/${IMAGE_NAME}:${TAG}").inside( - "--name amarillo -p 8000:80 -e MODULE_NAME=amarillo.app.main -e MAX_WORKERS=1 -e ADMIN_TOKEN=test -e RIDE2GO_TOKEN=test -e METRICS_USER=test -e METRICS_PASSWORD=test -e TZ=Europe/Berlin -v ${pwd()}/data:/app/data" - ){ - // TODO: wait until the API is up - c -> sh script: """ - sleep 15 - echo Testing... - python -m pytest - """ - } - } - } - } + // stage('Run tests on image'){ + // steps{ + // script { + // docker.image("${OWNER}/${IMAGE_NAME}:${TAG}").inside( + // "--name amarillo -p 8000:80 -e MODULE_NAME=amarillo.app.main -e MAX_WORKERS=1 -e ADMIN_TOKEN=test -e RIDE2GO_TOKEN=test -e METRICS_USER=test -e METRICS_PASSWORD=test -e TZ=Europe/Berlin -v ${pwd()}/data:/app/data" + // ){ + // // TODO: wait until the API is up + // c -> sh script: """ + // sleep 15 + // echo Testing... + // python -m pytest + // """ + // } + // } + // } + // } stage('Push image to container registry') { steps { echo 'Pushing image to registry' @@ -46,6 +48,22 @@ pipeline { } } } + stage('Notify CD script') { + steps { + echo 'Triggering deploy webhook' + script { + def body = """ + {"secret": "${DEPLOY_SECRET}"} + """ + def response = httpRequest contentType: 'APPLICATION_JSON', + httpMode: 'POST', requestBody: body, + url: "${DEPLOY_WEBHOOK_URL}" + + println("Status: ${response.status}") + println("Response: ${response.content}") + } + } + } } post { always { From aa5a7ec80138f2a6f041ef1d5dfaeb4e766f60ff Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Wed, 17 Jan 2024 11:31:22 +0100 Subject: [PATCH 17/20] #13 fixed deploy secret string interpolation --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2289bd4..96aea96 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -52,9 +52,9 @@ pipeline { steps { echo 'Triggering deploy webhook' script { - def body = """ - {"secret": "${DEPLOY_SECRET}"} - """ + def body = ' + {"secret": "$DEPLOY_SECRET"} + ' def response = httpRequest contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: body, url: "${DEPLOY_WEBHOOK_URL}" From 510648cd3776e68ebde89136dc4089eb97365f28 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Wed, 17 Jan 2024 11:34:11 +0100 Subject: [PATCH 18/20] #13 fixed deploy secret string interpolation --- Jenkinsfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 96aea96..0e65a41 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -52,9 +52,7 @@ pipeline { steps { echo 'Triggering deploy webhook' script { - def body = ' - {"secret": "$DEPLOY_SECRET"} - ' + def body = '{"secret": "$DEPLOY_SECRET"}' def response = httpRequest contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: body, url: "${DEPLOY_WEBHOOK_URL}" From 1ea83fbbb9d8c1a5d3c83a8145fed029714deaa4 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Wed, 17 Jan 2024 12:27:47 +0100 Subject: [PATCH 19/20] #13 use HTTP basic auth --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0e65a41..688da14 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -52,9 +52,8 @@ pipeline { steps { echo 'Triggering deploy webhook' script { - def body = '{"secret": "$DEPLOY_SECRET"}' def response = httpRequest contentType: 'APPLICATION_JSON', - httpMode: 'POST', requestBody: body, + httpMode: 'POST', authentication: 'AMARILLO-JENKINS-DEPLOY-SECRET', url: "${DEPLOY_WEBHOOK_URL}" println("Status: ${response.status}") From b5a31c26bcc0ff0d7ea2bcc3617a6f998b9faa03 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Wed, 17 Jan 2024 12:37:56 +0100 Subject: [PATCH 20/20] #13 added empty request body --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 688da14..df134bc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -53,7 +53,7 @@ pipeline { echo 'Triggering deploy webhook' script { def response = httpRequest contentType: 'APPLICATION_JSON', - httpMode: 'POST', authentication: 'AMARILLO-JENKINS-DEPLOY-SECRET', + httpMode: 'POST', requestBody: '{}', authentication: 'AMARILLO-JENKINS-DEPLOY-SECRET', url: "${DEPLOY_WEBHOOK_URL}" println("Status: ${response.status}")