Skip to content

Commit

Permalink
Merge pull request #58 from Altonhe/feature/docker-gtfsRT
Browse files Browse the repository at this point in the history
feat: add support to GTFS-RT
  • Loading branch information
aaronbrethorst authored Mar 12, 2024
2 parents fd5f6d5 + ec41718 commit cfffb6b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
18 changes: 17 additions & 1 deletion oba/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ FROM alpine:latest as builder
ARG TEST_API_KEY
ENV TEST_API_KEY=${TEST_API_KEY}

# GTFS Realtime URLs
ARG TRIP_UPDATES_URL
ENV TRIP_UPDATES_URL=${TRIP_UPDATES_URL}

ARG VEHICLE_POSITIONS_URL
ENV VEHICLE_POSITIONS_URL=${VEHICLE_POSITIONS_URL}

ARG ALERTS_URL
ENV ALERTS_URL=${ALERTS_URL}

ARG REFRESH_INTERVAL
ENV REFRESH_INTERVAL=${REFRESH_INTERVAL}

ARG AGENCY_ID
ENV AGENCY_ID=${AGENCY_ID}

WORKDIR /oba
COPY bootstrap.sh .
COPY ./config ./config
Expand Down Expand Up @@ -50,7 +66,7 @@ WORKDIR /oba/webapps/onebusaway-transit-data-federation-webapp
RUN cp /oba/libs/onebusaway-transit-data-federation-webapp-${OBA_VERSION}.war .
RUN jar xvf onebusaway-transit-data-federation-webapp-${OBA_VERSION}.war
RUN rm onebusaway-transit-data-federation-webapp-${OBA_VERSION}.war
COPY ./config/onebusaway-transit-data-federation-webapp-data-sources.xml ./WEB-INF/classes/data-sources.xml
COPY --from=builder /oba/config/onebusaway-transit-data-federation-webapp-data-sources.xml ./WEB-INF/classes/data-sources.xml
RUN cp $CATALINA_HOME/lib/mysql-connector-j-8.3.0.jar ./WEB-INF/lib
RUN mv /oba/webapps/onebusaway-transit-data-federation-webapp $CATALINA_HOME/webapps

Expand Down
60 changes: 57 additions & 3 deletions oba/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

XML_FILE="./config/onebusaway-api-webapp-data-sources.xml"
WEBAPP_API_XML_FILE="./config/onebusaway-api-webapp-data-sources.xml"
NAMESPACE_PREFIX="x"
NAMESPACE_URI="http://www.springframework.org/schema/beans"
BEAN_ID="testAPIKey"
Expand All @@ -13,11 +13,65 @@ if [ -n "$TEST_API_KEY" ]; then
-s "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']" -t elem -n "property" -v "" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[not(@name)]" -t attr -n "name" -v "key" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[@name='key']" -t attr -n "value" -v "${TEST_API_KEY}" \
${XML_FILE}
${WEBAPP_API_XML_FILE}
else
# If it is not set, then remove the element from the data-sources.xml file
echo "TEST_API_KEY environment variable is not set. Removing element from data-sources.xml"
xmlstarlet ed -L -N ${NAMESPACE_PREFIX}=${NAMESPACE_URI} \
-d "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']" \
${XML_FILE}
${WEBAPP_API_XML_FILE}
fi

DATA_FEDERATION_XML_FILE="./config/onebusaway-transit-data-federation-webapp-data-sources.xml"
BEAN_ID="gtfsRT"
# Check if GTFS-Rt related environment variables are set
if [ -z "$TRIP_UPDATES_URL" ] && [ -z "$VEHICLE_POSITIONS_URL" ] && [ -z "$ALERTS_URL" ]; then
echo "No GTFS-RT related environment variables are set. Removing element from data-sources.xml"
xmlstarlet ed -L -N ${NAMESPACE_PREFIX}=${NAMESPACE_URI} \
-d "//${NAMESPACE_PREFIX}:bean[@class=${DATA_SOURCE_CLASS}]" \
${DATA_FEDERATION_XML_FILE}
exit 0
fi

if [ -n "$TRIP_UPDATES_URL" ]; then
echo "TRIP_UPDATES_URL set to $TRIP_UPDATES_URL, setting trip updates URL in data-sources.xml"
xmlstarlet ed -L -N ${NAMESPACE_PREFIX}=${NAMESPACE_URI} \
-s "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']" -t elem -n "property" -v "" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[not(@name)]" -t attr -n "name" -v "tripUpdatesUrl" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[@name='tripUpdatesUrl']" -t attr -n "value" -v "${TRIP_UPDATES_URL}" \
${DATA_FEDERATION_XML_FILE}
fi
if [ -n "$VEHICLE_POSITIONS_URL" ]; then
echo "VEHICLE_POSITIONS_URL set to $VEHICLE_POSITIONS_URL, setting vehicle positions URL in data-sources.xml"
xmlstarlet ed -L -N ${NAMESPACE_PREFIX}=${NAMESPACE_URI} \
-s "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']" -t elem -n "property" -v "" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[not(@name)]" -t attr -n "name" -v "vehiclePositionsUrl" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[@name='vehiclePositionsUrl']" -t attr -n "value" -v "${VEHICLE_POSITIONS_URL}" \
${DATA_FEDERATION_XML_FILE}
fi
if [ -n "$ALERTS_URL" ]; then
echo "ALERTS_URL set to $ALERTS_URL, setting alerts URL in data-sources.xml"
xmlstarlet ed -L -N ${NAMESPACE_PREFIX}=${NAMESPACE_URI} \
-s "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']" -t elem -n "property" -v "" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[not(@name)]" -t attr -n "name" -v "alertsUrl" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[@name='alertsUrl']" -t attr -n "value" -v "${ALERTS_URL}" \
${DATA_FEDERATION_XML_FILE}
fi
if [ -n "$REFRESH_INTERVAL" ]; then
echo "REFRESH_INTERVAL set to $REFRESH_INTERVAL, setting refresh interval in data-sources.xml"
xmlstarlet ed -L -N ${NAMESPACE_PREFIX}=${NAMESPACE_URI} \
-s "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']" -t elem -n "property" -v "" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[not(@name)]" -t attr -n "name" -v "refreshInterval" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[@name='refreshInterval']" -t attr -n "value" -v "${REFRESH_INTERVAL}" \
${DATA_FEDERATION_XML_FILE}
fi
if [ -n "$AGENCY_ID" ]; then
echo "AGENCY_ID set to $AGENCY_ID, setting agency ID in data-sources.xml"
xmlstarlet ed -L -N ${NAMESPACE_PREFIX}=${NAMESPACE_URI} \
-s "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']" -t elem -n "property" -v "" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[not(@name)]" -t attr -n "name" -v "agencyId" \
-i "//${NAMESPACE_PREFIX}:bean[@id='${BEAN_ID}']/property[@name='agencyId']" -t attr -n "value" -v "${AGENCY_ID}" \
${DATA_FEDERATION_XML_FILE}
fi


Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<constructor-arg type="java.lang.String" value="/onebusaway-admin-webapp/api/" />
</bean>

<!-- GTFS-RT related beans, automatically generated by the `bootstrap.sh`-->
<bean id="gtfsRT" class="org.onebusaway.transit_data_federation.impl.realtime.gtfs_realtime.GtfsRealtimeSource">
</bean>

<bean id="bundleManagementService" class="org.onebusaway.transit_data_federation.impl.bundle.BundleManagementServiceImpl">
<property name="bundleStoreRoot" value="/bundle" />
<property name="standaloneMode" value="true" />
Expand Down

0 comments on commit cfffb6b

Please sign in to comment.