diff --git a/.github/workflows/dev-pipeline.yml b/.github/workflows/dev-pipeline.yml new file mode 100644 index 0000000..4c7c2ba --- /dev/null +++ b/.github/workflows/dev-pipeline.yml @@ -0,0 +1,21 @@ +name: Process master push or pr +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + docker-push: + if: github.ref == 'refs/heads/master' + runs-on: ubuntu-18.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Build docker image from master and push it + run: ./.github/workflows/scripts/build_and_push_dev.sh + env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_AUTH: ${{ secrets.DOCKER_AUTH }} + DOCKER_BASE_TAG: latest diff --git a/.github/workflows/prod-pipeline.yml b/.github/workflows/prod-pipeline.yml new file mode 100644 index 0000000..13cbe54 --- /dev/null +++ b/.github/workflows/prod-pipeline.yml @@ -0,0 +1,25 @@ +name: Build prod from release +on: + release: + types: + - published +jobs: + prod-push: + runs-on: ubuntu-18.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Check Tag + id: check-tag + run: | + if [[ ${GITHUB_REF##*/} =~ ^202[0-9][0-1][0-9][0-3][0-9]$ ]]; then + echo ::set-output name=match::true + fi + - name: Push latest image as prod + if: steps.check-tag.outputs.match == 'true' + run: ./.github/workflows/scripts/push_prod.sh + env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_AUTH: ${{ secrets.DOCKER_AUTH }} + DOCKER_BASE_TAG: prod + DOCKER_DEV_TAG: latest diff --git a/.github/workflows/scripts/build_and_push_dev.sh b/.github/workflows/scripts/build_and_push_dev.sh new file mode 100755 index 0000000..d9f976a --- /dev/null +++ b/.github/workflows/scripts/build_and_push_dev.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +DOCKER_IMAGE="hsldevcom/gtfsrthttp2mqtt" +DOCKER_TAG=${DOCKER_BASE_TAG:-latest} + +COMMIT_HASH=$(git rev-parse --short "$GITHUB_SHA") + +DOCKER_TAG_LONG=$DOCKER_TAG-$(date +"%Y-%m-%dT%H.%M.%S")-$COMMIT_HASH +DOCKER_IMAGE_TAG=$DOCKER_IMAGE:$DOCKER_TAG +DOCKER_IMAGE_TAG_LONG=$DOCKER_IMAGE:$DOCKER_TAG_LONG + +# Build image +echo "Building gtfsrthttp2mqtt" +docker build --tag=$DOCKER_IMAGE_TAG_LONG . + +docker login -u $DOCKER_USER -p $DOCKER_AUTH +echo "Pushing $DOCKER_TAG image" +docker push $DOCKER_IMAGE_TAG_LONG +docker tag $DOCKER_IMAGE_TAG_LONG $DOCKER_IMAGE_TAG +docker push $DOCKER_IMAGE_TAG + +echo Build completed diff --git a/.github/workflows/scripts/push_prod.sh b/.github/workflows/scripts/push_prod.sh new file mode 100755 index 0000000..898202a --- /dev/null +++ b/.github/workflows/scripts/push_prod.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -e + +DOCKER_IMAGE="hsldevcom/gtfsrthttp2mqtt" +DOCKER_TAG=${DOCKER_BASE_TAG:-prod} +DOCKER_DEV_TAG=${DOCKER_DEV_TAG:-latest} + +COMMIT_HASH=$(git rev-parse --short "$GITHUB_SHA") + +DOCKER_TAG_LONG=$DOCKER_TAG-$(date +"%Y-%m-%dT%H.%M.%S")-$COMMIT_HASH +DOCKER_IMAGE_TAG=$DOCKER_IMAGE:$DOCKER_TAG +DOCKER_IMAGE_TAG_LONG=$DOCKER_IMAGE:$DOCKER_TAG_LONG +DOCKER_IMAGE_DEV=$DOCKER_IMAGE:$DOCKER_DEV_TAG + +docker login -u $DOCKER_USER -p $DOCKER_AUTH + +echo "processing prod release" +docker pull $DOCKER_IMAGE_DEV +docker tag $DOCKER_IMAGE_DEV $DOCKER_IMAGE_TAG +docker tag $DOCKER_IMAGE_DEV $DOCKER_IMAGE_TAG_LONG +docker push $DOCKER_IMAGE_TAG +docker push $DOCKER_IMAGE_TAG_LONG + +echo Build completed diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 256b718..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -sudo: required - -branches: - only: - - master - - /20(1[7-9]|2[0-9])[0-1][0-9][0-3][0-9]/ - -services: docker - -language: bash - -script: - - ./build-docker-image.sh diff --git a/build-docker-image.sh b/build-docker-image.sh deleted file mode 100755 index 53fc96f..0000000 --- a/build-docker-image.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -ORG=${ORG:-hsldevcom} -DOCKER_IMAGE=gtfsrthttp2mqtt - -DOCKER_TAG="ci-${TRAVIS_COMMIT}" -# Set these environment variables -#DOCKER_USER= -#DOCKER_AUTH= - -function tagandpush { - docker tag $ORG/$DOCKER_IMAGE:$DOCKER_TAG $ORG/$DOCKER_IMAGE:$1 - docker push $ORG/$DOCKER_IMAGE:$1 -} - -if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then - - docker login -u $DOCKER_USER -p $DOCKER_AUTH - if [ "$TRAVIS_TAG" ];then - echo "processing release $TRAVIS_TAG" - #release do not rebuild, just tag - docker pull $ORG/$DOCKER_IMAGE:$DOCKER_TAG - tagandpush "prod" - else - if [ "$TRAVIS_BRANCH" = "master" ]; then - echo "processing master build $TRAVIS_COMMIT" - #master branch, build and tag as latest - docker build --tag="$ORG/$DOCKER_IMAGE:$DOCKER_TAG" . - docker push $ORG/$DOCKER_IMAGE:$DOCKER_TAG - tagandpush "latest" - else - exit 0 - fi - fi -else - echo "processing pr $TRAVIS_PULL_REQUEST" - docker build --tag="$ORG/$DOCKER_IMAGE:$DOCKER_TAG" . -fi \ No newline at end of file diff --git a/gtfsrthttp2mqtt.py b/gtfsrthttp2mqtt.py index 3b37e00..e3238ad 100644 --- a/gtfsrthttp2mqtt.py +++ b/gtfsrthttp2mqtt.py @@ -95,6 +95,9 @@ def doGTFSRTPolling(self): route_id = utils.parse_route_id(self.feedName, entity.vehicle.trip.route_id, trip_id, self.OTPData) direction_id = utils.parse_direction_id(self.feedName, entity.vehicle.trip.direction_id, trip_id, self.OTPData) trip_headsign = entity.vehicle.vehicle.label + # headsigns with / cause problems in topics + if '/' in trip_headsign: + trip_headsign = '' latitude = "{:.6f}".format(entity.vehicle.position.latitude) # Force coordinates to have 6 numbers latitude_head = latitude[:2] longitude = "{:.6f}".format(entity.vehicle.position.longitude) diff --git a/requirements.txt b/requirements.txt index 25157a5..b44a223 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,10 @@ certifi==2018.11.29 chardet==3.0.4 -get==2018.11.19 idna==2.8 paho-mqtt==1.4.0 -post==2018.11.20 protobuf==3.6.1 public==2018.11.20 query-string==2018.11.20 -request==2018.11.20 requests==2.22.0 six==1.12.0 urllib3==1.25.6