Skip to content

Commit 62f3a3c

Browse files
Add support for PostgreSQL
Fixes #50 * Add golang to the builder build stage * Add a simple handlebars template renderer app; compile it in the build stage and transfer over to the main image * Rebuild the bootstrap.sh script to use a simple HBS renderer built in Golang * Replace all use of xmlstarlet with handlebars * Add an optional PG database to the docker-compose.yml file
1 parent 8b5374d commit 62f3a3c

19 files changed

+473
-259
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ When done using this web server, you can use the shell-standard `^C` to exit out
7272

7373
### Inspecting the database
7474

75-
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`.
75+
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`.
7676

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

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

9494
* Database
95-
* `JDBC_URL` - The JDBC connection URL for your MySQL database.
96-
* `JDBC_USER` - The username for your MySQL database.
97-
* `JDBC_PASSWORD` - The password for your MySQL database.
95+
* `JDBC_URL` - The JDBC connection URL for your MySQL or PostgreSQL database.
96+
* `JDBC_DRIVER` - The JDBC driver class name: `com.mysql.cj.jdbc.Driver` or `org.postgresql.Driver`
97+
* `JDBC_USER` - The username for your database.
98+
* `JDBC_PASSWORD` - The password for your database.
9899
* GTFS (Optional, required only when using `oba_app` independently)
99100
* `GTFS_URL` - The URL to the GTFS feed you want to use.
100101
* GTFS-RT Support (Optional)

docker-compose.prod.yml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ services:
4040
- PAT_TOKEN_FOR_GH=${PAT_TOKEN_FOR_GH}
4141
environment:
4242
- JDBC_URL=jdbc:mysql://oba_database:3306/oba_database
43+
- JDBC_DRIVER=com.mysql.cj.jdbc.Driver
4344
- JDBC_USER=oba_user
4445
- JDBC_PASSWORD=oba_password
4546
- TEST_API_KEY

docker-compose.standalone.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ services:
2626
- PAT_TOKEN_FOR_GH=${PAT_TOKEN_FOR_GH}
2727
environment:
2828
- JDBC_URL=jdbc:mysql://oba_database:3306/oba_database
29+
- JDBC_DRIVER=com.mysql.cj.jdbc.Driver
2930
- JDBC_USER=oba_user
3031
- JDBC_PASSWORD=oba_password
3132
- TEST_API_KEY=test # For test only, remove in production

docker-compose.yml

+20
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,36 @@ services:
2626
target: /var/lib/mysql
2727
restart: always
2828

29+
oba_database_pg:
30+
image: postgres:15
31+
container_name: oba_database_pg
32+
environment:
33+
POSTGRES_USER: oba_user
34+
POSTGRES_PASSWORD: oba_password
35+
POSTGRES_DB: oba_database
36+
ports:
37+
- "5432:5432"
38+
volumes:
39+
- type: volume
40+
source: pg-data
41+
target: /var/lib/postgresql/data
42+
restart: always
43+
2944
oba_app:
3045
container_name: oba_app
3146
depends_on:
3247
- oba_database
48+
# - oba_database_pg
3349
build:
3450
context: ./oba
3551
args:
3652
- PAT_USERNAME_FOR_GH=${PAT_USERNAME_FOR_GH}
3753
- PAT_TOKEN_FOR_GH=${PAT_TOKEN_FOR_GH}
3854
environment:
3955
- JDBC_URL=jdbc:mysql://oba_database:3306/oba_database
56+
- JDBC_DRIVER=com.mysql.cj.jdbc.Driver
57+
# - JDBC_URL=jdbc:postgresql://oba_database_pg:5432/oba_database
58+
# - JDBC_DRIVER=org.postgresql.Driver
4059
- JDBC_USER=oba_user
4160
- JDBC_PASSWORD=oba_password
4261
- TEST_API_KEY=test # For test only, remove in production
@@ -54,3 +73,4 @@ services:
5473

5574
volumes:
5675
mysql-data:
76+
pg-data:

oba/Dockerfile

+50-13
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@ ENV OBA_VERSION=${OBA_VERSION}
99

1010
ARG MYSQL_CONNECTOR_VERSION=8.4.0
1111
ENV MYSQL_CONNECTOR_VERSION=${MYSQL_CONNECTOR_VERSION}
12+
13+
ARG POSTGRESQL_CONNECTOR_VERSION=42.7.4
14+
ENV POSTGRESQL_CONNECTOR_VERSION=${POSTGRESQL_CONNECTOR_VERSION}
15+
1216
ARG PAT_USERNAME_FOR_GH
1317
ARG PAT_TOKEN_FOR_GH
1418

15-
RUN apt-get update && apt-get install -y maven
19+
RUN apt-get update && \
20+
apt-get install -y maven golang
21+
22+
# Build the template renderer, which is called hbs_renderer
23+
WORKDIR /oba/template_renderer
24+
COPY ./config/template_renderer .
25+
RUN go build -o hbs_renderer
1626

1727
# Start configuring OBA
1828
WORKDIR /oba/libs
@@ -50,13 +60,14 @@ RUN apt-get update && apt-get install -y \
5060
supervisor \
5161
tzdata \
5262
unzip \
53-
xmlstarlet \
5463
&& apt-get clean \
5564
&& rm -rf /var/lib/apt/lists/*
5665

5766
RUN pip install supervisord-dependent-startup
5867
RUN apt remove -y python3-pip
5968

69+
COPY --from=builder /oba/template_renderer/hbs_renderer /usr/local/bin/hbs_renderer
70+
6071
# Set the configured time zone
6172
RUN ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
6273

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

90+
##########
91+
# Copy over config files
92+
##########
93+
94+
WORKDIR /oba/config
95+
96+
COPY ./config/context.xml.hbs .
97+
COPY ./config/googlemaps.config.json.hbs .
98+
COPY ./config/onebusaway-api-webapp-data-sources.xml.hbs .
99+
COPY ./config/onebusaway-enterprise-acta-webapp-data-sources.xml.hbs .
100+
COPY ./config/onebusaway-transit-data-federation-webapp-data-sources.xml.hbs .
101+
79102
##########
80103
# Configure OBA Server
81104
##########
@@ -89,15 +112,22 @@ WORKDIR $CATALINA_HOME/webapps
89112
COPY --from=builder \
90113
--chown=oba_user:oba_group \
91114
/oba/libs/onebusaway-api-webapp.war .
115+
92116
RUN mkdir onebusaway-api-webapp && \
93117
cd onebusaway-api-webapp && \
94118
jar xvf ../onebusaway-api-webapp.war && \
95119
rm ../onebusaway-api-webapp.war
120+
96121
COPY --from=builder \
97122
--chown=oba_user:oba_group \
98123
/oba/libs/mysql-connector-j.jar onebusaway-api-webapp/WEB-INF/lib/
99-
COPY ./config/onebusaway-api-webapp-data-sources.xml \
100-
$CATALINA_HOME/webapps/onebusaway-api-webapp/WEB-INF/classes/data-sources.xml.bak
124+
125+
COPY --from=builder \
126+
--chown=oba_user:oba_group \
127+
/oba/libs/postgresql.jar onebusaway-api-webapp/WEB-INF/lib/
128+
129+
COPY ./config/onebusaway-api-webapp-data-sources.xml.hbs \
130+
$CATALINA_HOME/webapps/onebusaway-api-webapp/WEB-INF/classes/data-sources.xml.hbs
101131

102132
##########
103133
# Configure onebusaway-enterprise-acta-webapp as ROOT (i.e. the path `/`)
@@ -117,8 +147,13 @@ COPY --from=builder \
117147
/oba/libs/mysql-connector-j.jar \
118148
$CATALINA_HOME/webapps/ROOT/WEB-INF/lib/
119149

120-
COPY ./config/onebusaway-enterprise-acta-webapp-data-sources.xml \
121-
$CATALINA_HOME/webapps/ROOT/WEB-INF/classes/data-sources.xml.bak
150+
COPY --from=builder \
151+
--chown=oba_user:oba_group \
152+
/oba/libs/postgresql.jar \
153+
$CATALINA_HOME/webapps/ROOT/WEB-INF/lib/
154+
155+
COPY ./config/onebusaway-enterprise-acta-webapp-data-sources.xml.hbs \
156+
$CATALINA_HOME/webapps/ROOT/WEB-INF/classes/data-sources.xml.hbs
122157

123158

124159
# TODO: when/where/why is this needed?
@@ -133,23 +168,24 @@ RUN chmod 755 /opt/oba/logs
133168
COPY --from=builder \
134169
--chown=oba_user:oba_group \
135170
/oba/libs/onebusaway-transit-data-federation-webapp.war .
171+
136172
RUN mkdir onebusaway-transit-data-federation-webapp && \
137173
cd onebusaway-transit-data-federation-webapp && \
138174
jar xvf ../onebusaway-transit-data-federation-webapp.war && \
139175
rm ../onebusaway-transit-data-federation-webapp.war
176+
140177
COPY --from=builder \
141178
--chown=oba_user:oba_group \
142179
/oba/libs/mysql-connector-j.jar \
143180
onebusaway-transit-data-federation-webapp/WEB-INF/lib/
144-
COPY ./config/onebusaway-transit-data-federation-webapp-data-sources.xml \
145-
$CATALINA_HOME/webapps/onebusaway-transit-data-federation-webapp/WEB-INF/classes/data-sources.xml.bak
146181

147-
##########
148-
# Tomcat Configuration
149-
##########
182+
COPY --from=builder \
183+
--chown=oba_user:oba_group \
184+
/oba/libs/postgresql.jar \
185+
onebusaway-transit-data-federation-webapp/WEB-INF/lib/
150186

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

154190
##########
155191
# Clean up
@@ -166,4 +202,5 @@ COPY bootstrap.sh /oba/bootstrap.sh
166202
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
167203
RUN chmod +x /oba/bootstrap.sh
168204

205+
# CMD ["tail", "-f", "/dev/null"]
169206
CMD ["supervisord", "-n"]

0 commit comments

Comments
 (0)