Skip to content

Commit

Permalink
Merge pull request #372 from OneBusAway/docker-app-server
Browse files Browse the repository at this point in the history
Get OBA working in Docker
  • Loading branch information
aaronbrethorst authored Sep 8, 2024
2 parents 991fa8b + e375534 commit 1801c4b
Show file tree
Hide file tree
Showing 18 changed files with 806 additions and 29 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ onebusaway-enterprise-acta-webapp/overlays/
onebusaway-enterprise-webapp/overlays/

build/*
!build/.gitkeep
!build/.gitkeep

docker_app_server/bundle/*
!docker_app_server/bundle/.gitkeep
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2012 Brian Ferris <bdferris@onebusaway.org>
# Copyright (C) 2024 Open Transit Software Foundation <info@onebusaway.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,7 @@ RUN apt-get update && apt-get install -y \
vim \
&& rm -rf /var/lib/apt/lists/*

mkdir -p /root/.m2/repository
RUN mkdir -p /root/.m2/repository

WORKDIR /src

Expand Down
61 changes: 37 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,50 @@ There are two options for setting up your own OneBusAway instance:
* [Configuration and Deployment Guide for v2.x](https://github.com/OneBusAway/onebusaway/wiki/Configuration-and-Deployment-Guide-for-v2.x) - Designed to provide a comprehensive deployment method for users who wish to set up a simple OneBusAway application with minimal configurations.
* [onebusaway-docker (Under development)](https://github.com/OneBusAway/onebusaway-docker) - A community-supported Docker configuration for OneBusAway v2.x is currently under development.

## Docker Development Instructions
## Development Instructions with Docker

Build the image:
```sh
docker compose up builder
docker compose exec builder bash # in another shell, for now
./build.sh --help # acquaint yourself with the build.sh options
./build.sh --clean --check-updates --test

```
docker build -t oba-app-modules .
docker exec -it onebusaway-application-modules-builder-1 /bin/bash
./build-and-test.sh
# now you have built all of the OBA artifacts:
ls build/org/onebusaway/onebusaway-application-modules

# Download GTFS data and build an OBA transit data bundle from it
docker compose up bundle_builder

# verify that the bundle built as expected
ls docker_app_server/bundle

# Start up the app server
docker compose up appserver

# enter the app server
docker compose exec appserver bash

# run the copy_resources.sh script (it's on your path)
# to copy the necessary WAR files into /usr/local/tomcat
copy_resources.sh

# wait a few seconds for everything to spin up...
```

Finally, verify that everything works as expected!

* Check out the Tomcat Web App Manager at http://localhost:8080/manager/html (user/pass: admin/admin) to verify that your OBA WARs deployed correctly
* Check out the config.json API endpoint to verify that everything built correctly: http://localhost:8080/onebusaway-api-webapp/api/where/config.json?key=test


## Status

* Latest Stable Release - `2.4.18-cs`:
* [onebusaway-transit-data-federation-webapp](https://repo.camsys-apps.com/releases/org/onebusaway/onebusaway-transit-data-federation-webapp/2.4.18-cs/onebusaway-transit-data-federation-webapp-2.4.18-cs.war)
* [onebusaway-api-webapp](https://repo.camsys-apps.com/releases/org/onebusaway/onebusaway-api-webapp/2.4.18-cs/onebusaway-api-webapp-2.4.18-cs.war)
* [onebusaway-enterprise-acta-webapp](https://repo.camsys-apps.com/releases/org/onebusaway/onebusaway-enterprise-acta-webapp/2.4.18-cs/onebusaway-enterprise-acta-webapp-2.4.18-cs.war)
* [Previous releases](https://developer.onebusaway.org/release-notes)
* Download pre-built JARs and WARs: https://developer.onebusaway.org/downloads
* Terraform/Open Tofu/Infrastructure as Code: https://github.com/onebusaway/onebusaway-deployment
* Docker
* Pre-built images: https://hub.docker.com/r/opentransitsoftwarefoundation/
* Instructions: https://github.com/onebusAway/onebusaway-docker


## Deployments

Expand All @@ -79,14 +104,6 @@ Check out the full list on the [OneBusAway Deployments page](https://github.com/

* [Latest Stable Release](https://developer.onebusaway.org/downloads)

## Code Repository

To browse the source online visit https://github.com/OneBusAway/onebusaway-application-modules.

To create a local copy of the repository, use the following command:

`$ git clone https://github.com/OneBusAway/onebusaway-application-modules.git`


## Developer Information

Expand All @@ -101,11 +118,7 @@ To create a local copy of the repository, use the following command:
* Mailing lists:
- [Developer discussion list](https://groups.google.com/group/onebusaway-developers)
- [User discussion list](https://groups.google.com/group/onebusaway-users)
* IRC channel:
- `#onebusaway` on Freenode
- You can connect using your favorite IRC client or [chat through the web](http://webchat.freenode.net/?channels=onebusaway) (just enter a username and click *Connect*)


## Contact Info

There are [lots of ways to get in touch with us](https://github.com/OneBusAway/onebusaway/wiki/Contact-Us).
There are [lots of ways to get in touch with us](https://developer.onebusaway.org/getting-help).
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# Copyright (C) 2012 Brian Ferris <bdferris@onebusaway.org>
# Copyright (C) 2024 Open Transit Software Foundation <info@onebusaway.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
48 changes: 47 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,50 @@ services:
- ./build:/root/.m2/repository
- .:/src
stdin_open: true
tty: true
tty: true

bundle_builder:
build:
context: ./docker_app_server/bundle_builder
volumes:
- ./build:/root/.m2/repository
- ./docker_app_server/bundle:/bundle
stdin_open: true
tty: true

database:
image: mysql:8.3
container_name: database
environment:
MYSQL_ROOT_PASSWORD: Ins3cure!
MYSQL_DATABASE: oba_database
MYSQL_USER: oba_user
MYSQL_PASSWORD: oba_password
ports:
- "3306:3306"
volumes:
- type: volume
source: mysql-data
target: /var/lib/mysql
restart: always

appserver:
build:
context: docker_app_server
depends_on:
- database
ports:
- "8080:8080"
volumes:
- type: bind
source: ./docker_app_server/config/server.xml
target: /usr/local/tomcat/conf/server.xml
- type: bind
source: ./docker_app_server/config/context.xml
target: /usr/local/tomcat/conf/context.xml
- ./docker_app_server/config:/oba_config_files
- ./build:/root/.m2/repository
- ./docker_app_server/bundle:/bundle

volumes:
mysql-data:
58 changes: 58 additions & 0 deletions docker_app_server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# Copyright (C) 2024 Open Transit Software Foundation <info@onebusaway.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM tomcat:8.5.98-jdk11-temurin

ENV CATALINA_HOME /usr/local/tomcat
ENV TZ=America/Los_Angeles
ARG OBA_VERSION=2.5.13-otsf
ENV OBA_VERSION=$OBA_VERSION

RUN apt-get update && apt-get install -y \
jq \
supervisor \
tzdata \
unzip \
xmlstarlet \
python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Set the configured time zone
RUN ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && dpkg-reconfigure -f noninteractive tzdata

# Set up the host-manager and manager webapps
RUN rm -rf $CATALINA_HOME/webapps
RUN mv $CATALINA_HOME/webapps.dist $CATALINA_HOME/webapps

COPY ./config/tomcat-users.xml $CATALINA_HOME/conf/

COPY ./config/host-manager_context.xml $CATALINA_HOME/webapps/docs/META-INF/context.xml
COPY ./config/host-manager_context.xml $CATALINA_HOME/webapps/examples/META-INF/context.xml
COPY ./config/host-manager_context.xml $CATALINA_HOME/webapps/host-manager/META-INF/context.xml
COPY ./config/host-manager_context.xml $CATALINA_HOME/webapps/manager/META-INF/context.xml
COPY ./config/host-manager_context.xml $CATALINA_HOME/webapps/ROOT/META-INF/context.xml

# MySQL Connector
WORKDIR $CATALINA_HOME/lib
RUN wget "https://cdn.mysql.com/Downloads/Connector-J/mysql-connector-j-8.4.0.tar.gz" \
&& tar -zxvf mysql-connector-j-8.4.0.tar.gz \
&& mv mysql-connector-j-8.4.0/mysql-connector-j-8.4.0.jar . \
&& rm mysql-connector-j-8.4.0.tar.gz \
&& rm -rf mysql-connector-j-8.4.0

COPY ./copy_resources.sh /usr/local/bin/copy_resources.sh
RUN chmod +x /usr/local/bin/copy_resources.sh
Empty file.
30 changes: 30 additions & 0 deletions docker_app_server/bundle_builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Copyright (C) 2024 Open Transit Software Foundation <info@onebusaway.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM tomcat:8.5.98-jdk11-temurin

ARG OBA_VERSION=2.5.13-otsf
ENV OBA_VERSION_ENV=$OBA_VERSION

# Start configuring OBA
WORKDIR /oba

COPY ./build_bundle.sh .

CMD /oba/build_bundle.sh ${OBA_VERSION_ENV}

# for debugging
# CMD ["tail", "-f", "/dev/null"]
40 changes: 40 additions & 0 deletions docker_app_server/bundle_builder/build_bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

#
# Copyright (C) 2024 Open Transit Software Foundation <info@onebusaway.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

OBA_VERSION="$@"

# If GTFS_URL is not set or is empty, then use a default value:
RESOLVED_GTFS_URL=${GTFS_URL:-https://unitrans.ucdavis.edu/media/gtfs/Unitrans_GTFS.zip}

echo "OBA Bundle Builder Starting"
echo "GTFS_URL: $GTFS_URL"
echo "Resolved GTFS_URL: $RESOLVED_GTFS_URL"
echo "OBA Version: $OBA_VERSION"

wget -O /bundle/gtfs.zip ${RESOLVED_GTFS_URL}

# The JAR must be executed from within the same directory
# as the bundle, or else some necessary files are not generated.

cp /root/.m2/repository/org/onebusaway/onebusaway-transit-data-federation-builder/$OBA_VERSION/onebusaway-transit-data-federation-builder-$OBA_VERSION-withAllDependencies.jar /oba/builder.jar

cd /bundle \
&& java -Xss4m -Xmx3g \
-jar /oba/builder.jar \
./gtfs.zip \
.
41 changes: 41 additions & 0 deletions docker_app_server/config/context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2012 Brian Ferris <bdferris@onebusaway.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>

<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>/usr/local/tomcat/conf/web.xml</WatchedResource>

<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<Resource name="jdbc/appDB"
auth="Container"
type="javax.sql.DataSource"
maxTotal="100"
maxIdle="30"
maxWaitMillis="10000"
username="oba_user"
password="oba_password"
driverClassName="com.mysql.cj.jdbc.Driver"
url="jdbc:mysql://database:3306/oba_database"/>
</Context>
23 changes: 23 additions & 0 deletions docker_app_server/config/host-manager_context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2012 Brian Ferris <bdferris@onebusaway.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<Context antiResourceLocking="false" privileged="true" >
<CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
sameSiteCookies="strict" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
Loading

0 comments on commit 1801c4b

Please sign in to comment.