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

Bootstrapping helm charts #97

Closed
wants to merge 13 commits into from
49 changes: 49 additions & 0 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Lint and Test Charts

on: pull_request

jobs:
lint-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install Helm
uses: azure/setup-helm@v4
with:
version: "v3.9.4"

- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Install chart-testing
uses: helm/chart-testing-action@v2.6.0

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch main)
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi

- name: Run chart-testing (lint)
run: ct lint --target-branch main

- name: Create kind cluster
uses: helm/kind-action@v1.8.0
if: steps.list-changed.outputs.changed == 'true'

- name: Run chart-testing (install)
run: |
# Create namespace
kubectl create ns oba

# Create necessary secret
kubectl create secret generic oba-secrets --from-literal=MYSQL_ROOT_PASSWORD=root_password --from-literal=JDBC_PASSWORD=oba_password -n oba

ct install --target-branch main --namespace oba
31 changes: 31 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release Charts

on:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"

- name: Install Helm
uses: azure/setup-helm@v4
with:
version: "v3.9.4"

- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.6.0
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
CR_GENERATE_RELEASE_NOTES: true
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ You will also need to create a transit data bundle from a GTFS Zip file. This ne

[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/oneBusAway/onebusaway-docker/)

### Running in Kubernetes
## Running in Kubernetes

### a) Using kubernetes resource yaml files (and locally built images):

#### Creating the docker images

Expand Down Expand Up @@ -156,7 +158,49 @@ Then you can connect to it programmatically using `mysql`:
mysql -u oba_user -p -h localhost:3306
```

### Using Google Maps
### b) Using helm charts:

#### Installation

1. Create a namespace for the OneBusAway deployment:
```bash
kubectl create namespace oba
```
2. Create a secret for sensitive data:
```bash
kubectl create secret generic oba-secrets --from-literal=MYSQL_ROOT_PASSWORD=root_password --from-literal=JDBC_PASSWORD=oba_password -n oba
```
_Note: Additional keys may be required if using Google Maps._
3. Create a file (eg: `oba-values.yaml`) containing your configurations:
```yaml
gtfsURL: "https://unitrans.ucdavis.edu/media/gtfs/Unitrans_GTFS.zip"
```
4. Install the OneBusAway helm chart:
```bash
helm install oba-server ./helm/one-bus-away -n oba -f oba-values.yaml
```

#### Using oba app on localhost

You can portforward the oba app to your localhost using:
```bash
kubectl port-forward deploy/oba-app-deployment -n oba 8080:8080
```
_Note: Sample apis can be found in `bin/validate.sh`_

#### Inspecting the database

1. You can portforward the service to your localhost using:
```bash
kubectl port-forward service/oba-database -n oba 3306:3306
```
2. Then you can connect to it programmatically using `mysql`:
```bash
mysql -u oba_user -p -h localhost:3306
```
_Note: If the above command fails, try `mysql -u oba_user -p --host=127.0.0.1 --port=3306` instead._

## Using Google Maps

#### Prerequisites

Expand Down
15 changes: 15 additions & 0 deletions charts/one-bus-away/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v2
name: one-bus-away
description: A Helm chart for installing OneBusAway
home: https://onebusaway.org
icon: https://developer.onebusaway.org/images/oba-logo.png

type: application

version: 0.1.0

appVersion: "2.5.12"

maintainers:
- name: Altonhe
- name: aaronbrethorst
1 change: 1 addition & 0 deletions charts/one-bus-away/ci/basic-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gtfsURL: "https://unitrans.ucdavis.edu/media/gtfs/Unitrans_GTFS.zip"
7 changes: 7 additions & 0 deletions charts/one-bus-away/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: oba-configs
namespace: {{ .Release.Namespace }}
data:
GTFS_URL: {{ .Values.gtfsURL | required "gtfsURL is required !!!" | quote }}
42 changes: 42 additions & 0 deletions charts/one-bus-away/templates/database-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: oba-database-deployment
namespace: {{ .Release.Namespace }}
spec:
replicas: 1
selector:
matchLabels:
app: oba-database
template:
metadata:
labels:
app: oba-database
spec:
containers:
- name: oba-database
image: {{ .Values.database.image }}
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: oba-secrets
key: MYSQL_ROOT_PASSWORD
- name: MYSQL_DATABASE
value: {{ .Values.database.databaseName }}
- name: MYSQL_USER
value: {{ .Values.database.user }}
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: oba-secrets
key: JDBC_PASSWORD
ports:
- containerPort: {{ .Values.database.port }}
volumeMounts:
- mountPath: /var/lib/mysql
name: mysql-data
volumes:
- name: mysql-data
hostPath:
path: /var/lib/oba/mysql
12 changes: 12 additions & 0 deletions charts/one-bus-away/templates/database-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: oba-database
namespace: {{ .Release.Namespace }}
spec:
selector:
app: oba-database
ports:
- protocol: TCP
port: {{ .Values.database.port }}
targetPort: {{ .Values.database.port }}
67 changes: 67 additions & 0 deletions charts/one-bus-away/templates/oba-app-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: oba-app-deployment
namespace: {{ .Release.Namespace }}
spec:
replicas: 1
selector:
matchLabels:
app: oba-app
template:
metadata:
labels:
app: oba-app
spec:
initContainers:
- name: oba-bundler
image: {{ .Values.app.bundlerImage }}
env:
- name: GTFS_URL
valueFrom:
configMapKeyRef:
name: oba-configs
key: GTFS_URL
volumeMounts:
- mountPath: /bundle
name: bundle-volume
containers:
- name: oba-app
image: {{ .Values.app.appImage }}
env:
- name: JDBC_URL
value: jdbc:mysql://oba-database.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.database.port }}/{{ .Values.database.databaseName }}
- name: JDBC_USER
value: {{ .Values.database.user }}
- name: JDBC_PASSWORD
valueFrom:
secretKeyRef:
name: oba-secrets
key: JDBC_PASSWORD
{{ if .Values.app.googleMaps.enabled }}
- name: GOOGLE_MAPS_API_KEY
valueFrom:
secretKeyRef:
name: oba-secrets
key: GOOGLE_MAPS_API_KEY
- name: GOOGLE_MAPS_CHANNEL_ID
valueFrom:
secretKeyRef:
name: oba-secrets
key: GOOGLE_MAPS_CHANNEL_ID
optional: true
- name: GOOGLE_MAPS_CLIENT_ID
valueFrom:
secretKeyRef:
name: oba-secrets
key: GOOGLE_MAPS_CLIENT_ID
optional: true
{{ end }}
ports:
- containerPort: {{ .Values.app.port }}
volumeMounts:
- mountPath: /bundle
name: bundle-volume
volumes:
- name: bundle-volume
emptyDir: {}
17 changes: 17 additions & 0 deletions charts/one-bus-away/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Database configuration
database:
image: mysql:8.3
databaseName: oba_database
user: oba_user
port: 3306

# Application configuration
app:
bundlerImage: opentransitsoftwarefoundation/onebusaway-bundle-builder:2.5.12-cs-v1.0.0
appImage: opentransitsoftwarefoundation/onebusaway-api-webapp:2.5.12-cs-v1.0.0
port: 8080
googleMaps:
enabled: false

# GTFS URL
gtfsURL:
4 changes: 4 additions & 0 deletions ct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# See https://github.com/helm/chart-testing#configuration
remote: origin
chart-dirs:
- charts
Loading