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 diff --git a/Jenkinsfile b/Jenkinsfile index 2a6c710..bbcf000 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,10 +3,14 @@ pipeline { environment { GITEA_CREDS = credentials('AMARILLO-JENKINS-GITEA-USER') TWINE_REPO_URL = "https://git.gerhardt.io/api/packages/amarillo/pypi" - REGISTRY_URL = 'https://git.gerhardt.io' + PLUGINS_REPO_URL = "git.gerhardt.io/api/packages/amarillo/pypi/simple" + DOCKER_REGISTRY_URL = 'https://git.gerhardt.io' OWNER = 'amarillo' - IMAGE_NAME = "amarillo" + IMAGE_NAME = 'amarillo' TAG = "${BUILD_NUMBER}" + PLUGINS = 'amarillo-metrics amarillo-enhancer' + DEPLOY_WEBHOOK_URL = 'https://amarillo.mfdz.de:8888/mitanand' + DEPLOY_SECRET = credentials('AMARILLO-JENKINS-DEPLOY-SECRET') } stages { stage('Create virtual environment') { @@ -20,14 +24,9 @@ pipeline { stage('Installing requirements') { steps { echo 'Installing packages' - sh 'python3 -m pip install -r requirements.txt' - sh 'python3 -m pip install --upgrade build' - sh 'python3 -m pip install --upgrade twine' - } - } - stage('Test') { - steps { - echo 'Testing' + sh 'pip install -r requirements.txt' + sh 'pip install --upgrade build' + sh 'pip install --upgrade twine' } } stage('Build package') { @@ -45,7 +44,8 @@ pipeline { steps { echo 'Building image' script { - docker.build("${OWNER}/${IMAGE_NAME}:${TAG}") + docker.build("${OWNER}/${IMAGE_NAME}:${TAG}", + "--build-arg='PACKAGE_REGISTRY_URL=${PLUGINS_REPO_URL}' --build-arg='PLUGINS=${PLUGINS}' --secret id=AMARILLO_REGISTRY_CREDENTIALS,env=GITEA_CREDS .") } } } @@ -53,7 +53,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'){ def image = docker.image("${OWNER}/${IMAGE_NAME}:${TAG}") image.push() image.push('latest') @@ -61,6 +61,16 @@ pipeline { } } } + stage('Notify CD script') { + steps { + echo 'Triggering deploy webhook' + script { + def response = httpRequest contentType: 'APPLICATION_JSON', + httpMode: 'POST', requestBody: '{}', authentication: 'AMARILLO-JENKINS-DEPLOY-SECRET', + url: "${DEPLOY_WEBHOOK_URL}" + } + } + } } post { always { 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 d604c56..5a140e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "amarillo-core" -version = "0.0.10" +version = "0.0.12" 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