OneBusAway / onebusaway-docker

Docker configuration for the OneBusAway Application Modules (https://github.com/OneBusAway/onebusaway-application-modules)
Apache License 2.0
18 stars 32 forks source link

OBA 2.x: Parameterize Database Credentials #26

Closed aaronbrethorst closed 7 months ago

aaronbrethorst commented 8 months ago

The feature branch feature/oba-2x has three data-sources.xml files that need to have their database credentials parameterized and loaded from the environment variables injected from the docker-compose.yml file.

Here are the particulars:

1. Parameterize DB configuration in data-sources.xml

Locate all DB credential/url/driver declarations in the three data-sources.xml files (e.g. see lines 22-25 here) and replace the hardcoded values with substitutable placeholders. For instance, update:

  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://oba_database:3306/oba_database" />
    <property name="username" value="oba_user" />
    <property name="password" value="oba_password" />
  </bean>

to:

  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${JDBC_DRIVER}" />
    <property name="url" value="${JDBC_URL}" />
    <property name="username" value="${JDBC_USERNAME}" />
    <property name="password" value="${JDBC_PASSWORD}" />
  </bean> 

The parameter names JDBC_DRIVER, JDBC_URL, JDBC_USERNAME, and JDBC_PASSWORD all come from the docker-compose.yml file, and the values are currently matched up between the configuration for the MySQL server and OBA app server in the docker-compose.yml file.

Perform substitution at container launch

Add a new shell script to the OBA Docker image that will supplement the existing Tomcat image's CMD. This new CMD shell script will do a find and replace with sed or another similar tool of the placeholders in the three data-sources.xml files.

aaronbrethorst commented 7 months ago

fixed