Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove oba-enterprise-acta-webapp from docker image #106

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ jobs:
services_standalone:
name: Services standalone
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -90,6 +93,13 @@ jobs:
chmod +x ./bin/validate.sh
./bin/validate.sh

# - name: Breakpoint if tests failed
# if: failure()
# uses: namespacelabs/breakpoint-action@v0
# with:
# duration: 30m
# authorized-users: aaronbrethorst

- name: Docker Compose down
if: always()
run: docker compose down
49 changes: 6 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ To build bundles and run the webapp server with your own GTFS feed, use the [Doc
The app server and bundle builder use Maven artifacts from GitHub's Maven package registry, which unfortunately requires authentication. This is provided in the form of a pair of environment variables that must be supplied when building the app server image:

```bash
PAT_USERNAME_FOR_GH=GITHUB_USERNAME \ PAT_TOKEN_FOR_GH=GITHUB_PERSONAL_ACCESS_TOKEN \
PAT_USERNAME_FOR_GH=GITHUB_USERNAME \
PAT_TOKEN_FOR_GH=GITHUB_PERSONAL_ACCESS_TOKEN \
docker compose build oba_app
```

Expand All @@ -41,7 +42,8 @@ To build a bundle, use the `oba_bundler` service:

```bash
GTFS_URL=https://www.soundtransit.org/GTFS-rail/40_gtfs.zip \
PAT_USERNAME_FOR_GH=GITHUB_USERNAME \ PAT_TOKEN_FOR_GH=GITHUB_PERSONAL_ACCESS_TOKEN \
PAT_USERNAME_FOR_GH=GITHUB_USERNAME \
PAT_TOKEN_FOR_GH=GITHUB_PERSONAL_ACCESS_TOKEN \
docker compose up oba_bundler
```

Expand All @@ -61,11 +63,10 @@ Once you have built an OBA bundle inside `./bundle`, you can run the OBA server
docker compose up oba_app
```

You will then have three web apps available:
You will then have two web apps available:

* onebusaway-api-webapp, hosted at http://localhost:8080/onebusaway-api-webapp
* Example API call: http://localhost:8080/onebusaway-api-webapp/api/where/agencies-with-coverage.json?key=TEST
* onebusaway-enterprise-acta-webapp, a user-facing web app: http://localhost:8080
* onebusaway-transit-data-federation-webapp, which does the heavy lifting of exposing the transit data bundle to other services: http://localhost:8080/onebusaway-transit-data-federation-webapp

When done using this web server, you can use the shell-standard `^C` to exit out and turn it off. If issues persist across runs, you can try using `docker compose down -v` and then `docker compose up oba_app` to refresh the Docker containers and services.
Expand Down Expand Up @@ -112,7 +113,7 @@ You can find the latest published Docker images on Docker Hub:



The `GTFS-RT` and `Google Map` related variables will be handled by the `oba/bootstrap.sh` script, which will set the config files for the OBA API webapp. If you want to use your own config files, you could set `USER_CONFIGURED=1` in the `oba_app` service in `docker-compose.yml` to skip `bootstrap.sh` and write your config file in the container.
The `GTFS-RT` related variables will be handled by the `oba/bootstrap.sh` script, which will set the config files for the OBA API webapp. If you want to use your own config files, you could set `USER_CONFIGURED=1` in the `oba_app` service in `docker-compose.yml` to skip `bootstrap.sh` and write your config file in the container.
```yaml
oba_app:
container_name: oba_app
Expand All @@ -130,41 +131,3 @@ The `GTFS-RT` and `Google Map` related variables will be handled by the `oba/boo
# skip bootstrap.sh and use user-configured config files
- USER_CONFIGURED=1
```

### Using Google Maps

#### Prerequisites

- Have a valid Google Cloud Platform (GCP) account.
- Create a project on GCP and enable the Maps JavaScript API for it.
- Create an API key for your project. [See how to create an API key](https://cloud.google.com/docs/authentication/api-keys).
- If there is a rate limit error while using the test API key, it means you have reached the maximum usage limit for that key, you need to generate a new API key.

#### Configuring Google Maps

You'll need to set the following environment variables:

- `GOOGLE_MAPS_API_KEY`: Your Google Maps API key.
- `GOOGLE_MAPS_CLIENT_ID`: (Optional) Required if you are using the Google Maps Premium Plan.
- `GOOGLE_MAPS_CHANNEL_ID`: (Optional) A channel ID that helps identify the source of API requests for analytics and reporting purposes.

#### Docker Configuration

If using Docker Compose:

1.Modify the 'docker-compose.yml' file like this:

```yaml
services:
oba-app:
environment:
- GOOGLE_MAPS_API_KEY=<YOUR_KEY_HERE>
- GOOGLE_MAPS_CHANNEL_ID=<YOUR_CHANNEL_ID_HERE>
- GOOGLE_MAPS_CLIENT_ID=<YOUR_CLIENT_ID_HERE>
```

2.Use the following command to start the oba-app service:

```bash
docker compose up -d oba-app
```
21 changes: 6 additions & 15 deletions bin/validate.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

output=$(curl -s "http://localhost:8080/onebusaway-api-webapp/api/where/current-time.json?key=test" | jq '.data.entry.time')
output=$(curl -s "http://localhost:8080/api/where/current-time.json?key=test" | jq '.data.entry.time')

if [[ ! -z "$output" && "$output" =~ ^[0-9]+$ ]]; then
echo "current-time.json endpoint works."
Expand All @@ -9,7 +9,7 @@ else
exit 1
fi

output=$(curl -s "http://localhost:8080/onebusaway-api-webapp/api/where/agencies-with-coverage.json?key=test" | jq '.data.list[0].agencyId')
output=$(curl -s "http://localhost:8080/api/where/agencies-with-coverage.json?key=test" | jq '.data.list[0].agencyId')

if [[ ! -z "$output" && "$output" == "\"unitrans\"" ]]; then
echo "agencies-with-coverage.json endpoint works."
Expand All @@ -18,47 +18,38 @@ else
exit 1
fi

output=$(curl -s "http://localhost:8080/onebusaway-api-webapp/api/where/routes-for-agency/unitrans.json?key=test" | jq '.data.list | length')
output=$(curl -s "http://localhost:8080/api/where/routes-for-agency/unitrans.json?key=test" | jq '.data.list | length')
if [[ $output -gt 10 ]]; then
echo "routes-for-agency/unitrans.json endpoint works."
else
echo "Error: routes-for-agency/unitrans.json is not working: $output"
exit 1
fi

output=$(curl -s "http://localhost:8080/onebusaway-api-webapp/api/where/stops-for-route/unitrans_C.json?key=test" | jq '.data.entry.routeId')
output=$(curl -s "http://localhost:8080/api/where/stops-for-route/unitrans_C.json?key=test" | jq '.data.entry.routeId')
if [[ ! -z "$output" && "$output" == "\"unitrans_C\"" ]]; then
echo "stops-for-route/unitrans_C.json endpoint works."
else
echo "Error: stops-for-route/unitrans_C.json endpoint is not working: $output"
exit 1
fi

output=$(curl -s "http://localhost:8080/onebusaway-api-webapp/api/where/stop/unitrans_22182.json?key=test" | jq '.data.entry.code')
output=$(curl -s "http://localhost:8080/api/where/stop/unitrans_22182.json?key=test" | jq '.data.entry.code')
if [[ ! -z "$output" && "$output" == "\"22182\"" ]]; then
echo "stop/unitrans_22182.json endpoint works."
else
echo "Error: stop/unitrans_22182.json endpoint is not working: $output"
exit 1
fi

output=$(curl -s "http://localhost:8080/onebusaway-api-webapp/api/where/stops-for-location.json?lat=38.555308&lon=-121.735991&key=test" | jq '.data.outOfRange')
output=$(curl -s "http://localhost:8080/api/where/stops-for-location.json?lat=38.555308&lon=-121.735991&key=test" | jq '.data.outOfRange')
if [[ ! -z "$output" && "$output" == "false" ]]; then
echo "stops-for-location/unitrans_false.json endpoint works."
else
echo "Error: stops-for-location/unitrans_false.json endpoint is not working: $output"
exit 1
fi

output=$(curl -s "http://localhost:8080/")
if echo "$output" | grep -qi "onebusaway enterprise"; then
echo "Success: webapp found on http://localhost:8080"
else
echo "Error: webapp NOT found on http://localhost:8080"
echo $output
exit 1
fi

# todo: add support for arrivals-and-departures-for-stop endpoint.
# however, it doesn't seem that the unitrans_22182 stop has arrivals and departures on the weekend, so we'll need
# something else to test with. However, for now, this is still a great step forward.
1 change: 0 additions & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ services:
- ALERTS_URL
- REFRESH_INTERVAL=30
- AGENCY_ID
- GOOGLE_MAPS_API_KEY

volumes:
# Share the host"s `bundle` directory
Expand Down
20 changes: 0 additions & 20 deletions k8s-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,3 @@ Then you can connect to it programmatically using `mysql`:
```bash
mysql -u oba_user -p -h localhost:3306
```

#### Google Maps


If deployed in Kubernetes environment:

1. Use the kubectl set env command to set new environment variables,
make sure you replace deployment/oba-app with the actual name of your deployment:

```bash
kubectl set env deployment/oba-app GOOGLE_MAPS_API_KEY=<YOUR_KEY_HERE> \
GOOGLE_MAPS_CHANNEL_ID=<YOUR_CHANNEL_ID_HERE> \
GOOGLE_MAPS_CLIENT_ID=<YOUR_CLIENT_ID_HERE>
```

2. Use the following command to rebuild and start the oba app service:

```bash
kubectl rollout restart deployment/oba-app
```
43 changes: 12 additions & 31 deletions oba/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ COPY --from=builder \
WORKDIR /oba/config

COPY ./config/context.xml.hbs .
COPY ./config/googlemaps.config.json.hbs .
COPY ./config/onebusaway-api-webapp-data-sources.xml.hbs .
COPY ./config/onebusaway-enterprise-acta-webapp-data-sources.xml.hbs .
COPY ./config/onebusaway-transit-data-federation-webapp-data-sources.xml.hbs .

##########
Expand All @@ -105,42 +103,27 @@ COPY ./config/onebusaway-transit-data-federation-webapp-data-sources.xml.hbs .

WORKDIR $CATALINA_HOME/webapps

##########
# Configure onebusaway-api-webapp
##########

COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/onebusaway-api-webapp.war .

RUN mkdir onebusaway-api-webapp && \
cd onebusaway-api-webapp && \
jar xvf ../onebusaway-api-webapp.war && \
rm ../onebusaway-api-webapp.war

COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/mysql-connector-j.jar onebusaway-api-webapp/WEB-INF/lib/
# COPY --from=builder \
# --chown=oba_user:oba_group \
# /oba/libs/postgresql.jar \
# $CATALINA_HOME/webapps/ROOT/WEB-INF/lib/

COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/postgresql.jar onebusaway-api-webapp/WEB-INF/lib/
# COPY ./config/onebusaway-enterprise-acta-webapp-data-sources.xml.hbs \
# $CATALINA_HOME/webapps/ROOT/WEB-INF/classes/data-sources.xml.hbs

COPY ./config/onebusaway-api-webapp-data-sources.xml.hbs \
$CATALINA_HOME/webapps/onebusaway-api-webapp/WEB-INF/classes/data-sources.xml.hbs

##########
# Configure onebusaway-enterprise-acta-webapp as ROOT (i.e. the path `/`)
# Configure onebusaway-api-webapp
##########

COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/onebusaway-enterprise-acta-webapp.war .
/oba/libs/onebusaway-api-webapp.war .

RUN mkdir ROOT && \
cd ROOT && \
jar xvf ../onebusaway-enterprise-acta-webapp.war && \
rm ../onebusaway-enterprise-acta-webapp.war
jar xvf ../onebusaway-api-webapp.war && \
rm ../onebusaway-api-webapp.war

COPY --from=builder \
--chown=oba_user:oba_group \
Expand All @@ -152,11 +135,9 @@ COPY --from=builder \
/oba/libs/postgresql.jar \
$CATALINA_HOME/webapps/ROOT/WEB-INF/lib/

COPY ./config/onebusaway-enterprise-acta-webapp-data-sources.xml.hbs \
$CATALINA_HOME/webapps/ROOT/WEB-INF/classes/data-sources.xml.hbs

COPY ./config/onebusaway-api-webapp-data-sources.xml.hbs \
$CATALINA_HOME/webapps/onebusaway-api-webapp/WEB-INF/classes/data-sources.xml.hbs

# TODO: when/where/why is this needed?
RUN mkdir -p /opt/oba/logs
RUN chown -R oba_user:oba_group /opt/oba/logs
RUN chmod 755 /opt/oba/logs
Expand Down
31 changes: 1 addition & 30 deletions oba/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fi
#####

API_XML_SOURCE="/oba/config/onebusaway-api-webapp-data-sources.xml.hbs"
API_XML_DESTINATION="$CATALINA_HOME/webapps/onebusaway-api-webapp/WEB-INF/classes/data-sources.xml"
API_XML_DESTINATION="$CATALINA_HOME/webapps/ROOT/WEB-INF/classes/data-sources.xml"

hbs_renderer -input "$API_XML_SOURCE" \
-json '{"TEST_API_KEY": "'$TEST_API_KEY'", "JDBC_DRIVER": "'$JDBC_DRIVER'"}' \
Expand Down Expand Up @@ -58,35 +58,6 @@ hbs_renderer -input "$FEDERATION_XML_SOURCE" \
-json '{"GTFS_RT_AVAILABLE": "'$GTFS_RT_AVAILABLE'", "TRIP_UPDATES_URL": "'$TRIP_UPDATES_URL'", "VEHICLE_POSITIONS_URL": "'$VEHICLE_POSITIONS_URL'", "ALERTS_URL": "'$ALERTS_URL'", "REFRESH_INTERVAL": "'$REFRESH_INTERVAL'", "AGENCY_ID": "'$AGENCY_ID'", "HAS_API_KEY": "'$HAS_API_KEY'", "FEED_API_KEY": "'$FEED_API_KEY'", "FEED_API_VALUE": "'$FEED_API_VALUE'"}' \
-output "$FEDERATION_XML_DESTINATION"

#####
# onebusaway-enterprise-acta-webapp
#####

# Google map related environment variables
WEBAPP_XML_SOURCE="/oba/config/onebusaway-enterprise-acta-webapp-data-sources.xml.hbs"
WEBAPP_XML_DESTINATION="$CATALINA_HOME/webapps/ROOT/WEB-INF/classes/data-sources.xml"

if [ -z "$GOOGLE_MAPS_API_KEY" ] && [ -z "$GOOGLE_MAPS_CLIENT_ID" ] && [ -z "$GOOGLE_MAPS_CHANNEL_ID" ]; then
echo "No Google Maps related environment variables are set. Removing element from data-sources.xml"
GOOGLE_MAPS_CONFIGURED=""
else
echo "Google Maps related environment variables are set. Setting them in data-sources.xml"
GOOGLE_MAPS_CONFIGURED="1"

MAP_CONFIG_SOURCE="/oba/config/googlemaps.config.json.hbs"
MAP_CONFIG_DESTINATION="/var/lib/oba/config.json"

mkdir -p $(dirname "$MAP_CONFIG_DESTINATION")

hbs_renderer -input "$MAP_CONFIG_SOURCE" \
-json '{"GOOGLE_MAPS_CONFIGURED": "'$GOOGLE_MAPS_CONFIGURED'", "GOOGLE_MAPS_API_KEY": "'$GOOGLE_MAPS_API_KEY'", "GOOGLE_MAPS_CLIENT_ID": "'$GOOGLE_MAPS_CLIENT_ID'", "GOOGLE_MAPS_CHANNEL_ID": "'$GOOGLE_MAPS_CHANNEL_ID'"}' \
-output "$MAP_CONFIG_DESTINATION"
fi

hbs_renderer -input "$WEBAPP_XML_SOURCE" \
-json '{"GOOGLE_MAPS_CONFIGURED": "'$GOOGLE_MAPS_CONFIGURED'"}' \
-output "$WEBAPP_XML_DESTINATION"

#####
# Tomcat context.xml
#####
Expand Down
9 changes: 0 additions & 9 deletions oba/config/googlemaps.config.json.hbs

This file was deleted.

Loading
Loading