Skip to content

Commit

Permalink
Merge pull request #103 from OneBusAway/databases
Browse files Browse the repository at this point in the history
Add support for PostgreSQL
  • Loading branch information
aaronbrethorst authored Sep 18, 2024
2 parents 86226a1 + 62f3a3c commit cce791f
Show file tree
Hide file tree
Showing 20 changed files with 477 additions and 263 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ When done using this web server, you can use the shell-standard `^C` to exit out

### Inspecting the database

The MySQL database Docker Compose service should remain up after a call of `docker compose up oba_app`. Otherwise, you can always invoke it using `docker compose up oba_database`.
The Docker Compose database service should remain up after a call of `docker compose up oba_app`. Otherwise, you can always invoke it using `docker compose up oba_database`.

A database port is open to your host machine, so you can connect to it programmatically using `mysql`:

Expand All @@ -92,9 +92,10 @@ You can find the latest published Docker images on Docker Hub:
### Deployment Parameters

* Database
* `JDBC_URL` - The JDBC connection URL for your MySQL database.
* `JDBC_USER` - The username for your MySQL database.
* `JDBC_PASSWORD` - The password for your MySQL database.
* `JDBC_URL` - The JDBC connection URL for your MySQL or PostgreSQL database.
* `JDBC_DRIVER` - The JDBC driver class name: `com.mysql.cj.jdbc.Driver` or `org.postgresql.Driver`
* `JDBC_USER` - The username for your database.
* `JDBC_PASSWORD` - The password for your database.
* GTFS (Optional, required only when using `oba_app` independently)
* `GTFS_URL` - The URL to the GTFS feed you want to use.
* GTFS-RT Support (Optional)
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- GTFS_URL

oba_database:
image: mysql:8.3
image: mysql:8.4
container_name: oba_database
environment:
MYSQL_ROOT_PASSWORD: Ins3cure!
Expand All @@ -40,6 +40,7 @@ services:
- PAT_TOKEN_FOR_GH=${PAT_TOKEN_FOR_GH}
environment:
- JDBC_URL=jdbc:mysql://oba_database:3306/oba_database
- JDBC_DRIVER=com.mysql.cj.jdbc.Driver
- JDBC_USER=oba_user
- JDBC_PASSWORD=oba_password
- TEST_API_KEY
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.standalone.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
oba_database:
image: mysql:8.3
image: mysql:8.4
container_name: oba_database
environment:
MYSQL_ROOT_PASSWORD: Ins3cure!
Expand All @@ -26,6 +26,7 @@ services:
- PAT_TOKEN_FOR_GH=${PAT_TOKEN_FOR_GH}
environment:
- JDBC_URL=jdbc:mysql://oba_database:3306/oba_database
- JDBC_DRIVER=com.mysql.cj.jdbc.Driver
- JDBC_USER=oba_user
- JDBC_PASSWORD=oba_password
- TEST_API_KEY=test # For test only, remove in production
Expand Down
22 changes: 21 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
- GTFS_URL

oba_database:
image: mysql:8.3
image: mysql:8.4
container_name: oba_database
environment:
MYSQL_ROOT_PASSWORD: Ins3cure!
Expand All @@ -26,17 +26,36 @@ services:
target: /var/lib/mysql
restart: always

oba_database_pg:
image: postgres:15
container_name: oba_database_pg
environment:
POSTGRES_USER: oba_user
POSTGRES_PASSWORD: oba_password
POSTGRES_DB: oba_database
ports:
- "5432:5432"
volumes:
- type: volume
source: pg-data
target: /var/lib/postgresql/data
restart: always

oba_app:
container_name: oba_app
depends_on:
- oba_database
# - oba_database_pg
build:
context: ./oba
args:
- PAT_USERNAME_FOR_GH=${PAT_USERNAME_FOR_GH}
- PAT_TOKEN_FOR_GH=${PAT_TOKEN_FOR_GH}
environment:
- JDBC_URL=jdbc:mysql://oba_database:3306/oba_database
- JDBC_DRIVER=com.mysql.cj.jdbc.Driver
# - JDBC_URL=jdbc:postgresql://oba_database_pg:5432/oba_database
# - JDBC_DRIVER=org.postgresql.Driver
- JDBC_USER=oba_user
- JDBC_PASSWORD=oba_password
- TEST_API_KEY=test # For test only, remove in production
Expand All @@ -54,3 +73,4 @@ services:

volumes:
mysql-data:
pg-data:
2 changes: 1 addition & 1 deletion oba.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
spec:
containers:
- name: oba-database
image: mysql:8.3
image: mysql:8.4
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
Expand Down
63 changes: 50 additions & 13 deletions oba/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ ENV OBA_VERSION=${OBA_VERSION}

ARG MYSQL_CONNECTOR_VERSION=8.4.0
ENV MYSQL_CONNECTOR_VERSION=${MYSQL_CONNECTOR_VERSION}

ARG POSTGRESQL_CONNECTOR_VERSION=42.7.4
ENV POSTGRESQL_CONNECTOR_VERSION=${POSTGRESQL_CONNECTOR_VERSION}

ARG PAT_USERNAME_FOR_GH
ARG PAT_TOKEN_FOR_GH

RUN apt-get update && apt-get install -y maven
RUN apt-get update && \
apt-get install -y maven golang

# Build the template renderer, which is called hbs_renderer
WORKDIR /oba/template_renderer
COPY ./config/template_renderer .
RUN go build -o hbs_renderer

# Start configuring OBA
WORKDIR /oba/libs
Expand Down Expand Up @@ -50,13 +60,14 @@ RUN apt-get update && apt-get install -y \
supervisor \
tzdata \
unzip \
xmlstarlet \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN pip install supervisord-dependent-startup
RUN apt remove -y python3-pip

COPY --from=builder /oba/template_renderer/hbs_renderer /usr/local/bin/hbs_renderer

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

Expand All @@ -76,6 +87,18 @@ COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/onebusaway-transit-data-federation-builder-withAllDependencies.jar .

##########
# Copy over config files
##########

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 .

##########
# Configure OBA Server
##########
Expand All @@ -89,15 +112,22 @@ WORKDIR $CATALINA_HOME/webapps
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 ./config/onebusaway-api-webapp-data-sources.xml \
$CATALINA_HOME/webapps/onebusaway-api-webapp/WEB-INF/classes/data-sources.xml.bak

COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/postgresql.jar onebusaway-api-webapp/WEB-INF/lib/

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 `/`)
Expand All @@ -117,8 +147,13 @@ COPY --from=builder \
/oba/libs/mysql-connector-j.jar \
$CATALINA_HOME/webapps/ROOT/WEB-INF/lib/

COPY ./config/onebusaway-enterprise-acta-webapp-data-sources.xml \
$CATALINA_HOME/webapps/ROOT/WEB-INF/classes/data-sources.xml.bak
COPY --from=builder \
--chown=oba_user:oba_group \
/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


# TODO: when/where/why is this needed?
Expand All @@ -133,23 +168,24 @@ RUN chmod 755 /opt/oba/logs
COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/onebusaway-transit-data-federation-webapp.war .

RUN mkdir onebusaway-transit-data-federation-webapp && \
cd onebusaway-transit-data-federation-webapp && \
jar xvf ../onebusaway-transit-data-federation-webapp.war && \
rm ../onebusaway-transit-data-federation-webapp.war

COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/mysql-connector-j.jar \
onebusaway-transit-data-federation-webapp/WEB-INF/lib/
COPY ./config/onebusaway-transit-data-federation-webapp-data-sources.xml \
$CATALINA_HOME/webapps/onebusaway-transit-data-federation-webapp/WEB-INF/classes/data-sources.xml.bak

##########
# Tomcat Configuration
##########
COPY --from=builder \
--chown=oba_user:oba_group \
/oba/libs/postgresql.jar \
onebusaway-transit-data-federation-webapp/WEB-INF/lib/

WORKDIR $CATALINA_HOME
COPY --chown=oba_user:oba_group ./config/context.xml ./conf/
COPY ./config/onebusaway-transit-data-federation-webapp-data-sources.xml.hbs \
$CATALINA_HOME/webapps/onebusaway-transit-data-federation-webapp/WEB-INF/classes/data-sources.xml.hbs

##########
# Clean up
Expand All @@ -166,4 +202,5 @@ COPY bootstrap.sh /oba/bootstrap.sh
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN chmod +x /oba/bootstrap.sh

# CMD ["tail", "-f", "/dev/null"]
CMD ["supervisord", "-n"]
Loading

0 comments on commit cce791f

Please sign in to comment.