Skip to content

Commit

Permalink
Migrate manifests files over to RL repo (#29)
Browse files Browse the repository at this point in the history
## Description
just a code migration

## Related Issues
closes #21 

## Additional Notes
[Add any additional context or notes that reviewers should know about.]

## Checklist
Please review and complete the following checklist before submitting
your pull request:

- [x] I have ensured that the pull request is of a manageable size,
allowing it to be reviewed within a single session.
- [x] I have reviewed my changes to ensure they are clear, concise, and
well-documented.
- [x] I have updated the documentation, if applicable.
- [x] I have added or updated test cases to cover my changes, if
applicable.
- [x] I have minimized the number of reviewers to include only those
essential for the review.
- [x] I have notified teammates in the review thread to build awareness.

## Checklist for Reviewers
Please review and complete the following checklist during the review
process:

- [x] The code follows best practices and conventions.
- [x] The changes implement the desired functionality or fix the
reported issue.
- [x] The tests cover the new changes and pass successfully.
- [x] Any potential edge cases or error scenarios have been considered.

Co-authored-by: Administrator <[email protected]>
  • Loading branch information
derekadombek and Administrator authored Sep 19, 2024
1 parent f9f3bb3 commit 120165d
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ops/manifests/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Local Minikube Record Linkage

The intention for using minikube is to have the ability to use an environment during development that is aimed to pair as close as possible to production-like environments, locally before promoting container versions. The added benefits to this approach is to add more advanced experimentation with system scalability and networking in the future.

## Prerequisites

Before getting started, ensure you have the following installed:

- [Docker](https://docs.docker.com/engine/install/)
- [Minikube](https://minikube.sigs.k8s.io/docs/start/)
- [Kubernetes](https://kubernetes.io/releases/download/)

## Setup

1. Run the `minikube-start.sh` script:

```bash
sh scripts/minikube-start.sh
```

This script will remove any existing minikube instances with a profile of `minikube` and create a new instance with all services running and configured loadbalancers for ease of access.

2. Once the environment is up and running, you can verify that it worked by running `curl -X GET localhost:8080/` and connecting to a databases client with `localhost:5432`. Then run a POST with the `/link-record` endpoint to check the database is working with the api(If you need help with any of this please reach out to someone on the team).


This setup is intented for locally built container images but if you want to run the GH registered image i.e. `ghcr.io/cdcgov/phdi/record-linkage`, Just pass the image as a variable to the script like so:

```bash
sh scripts/minikube-start.sh ghcr.io/cdcgov/phdi/record-linkage
```

**NOTE**: If your local machine is something other than amd64(like arm64), then the registered image may not work for you because Minikube typically runs with whatever architecture your machine is and isn't supplied with rosetta. I have tried using an amd64 Minikube version and still had no luck. Maybe in the future we will have images built for different architectures..

## Cleanup

After you've finished running Minikube, remove the it by running:

```bash
minikube delete
```
144 changes: 144 additions & 0 deletions ops/manifests/record-linkage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-db-config
labels:
app: postgresql-db
data:
POSTGRES_DB: testdb
POSTGRES_USER: postgres
POSTGRES_PASSWORD: pw
PGUSER: postgres
PGDATA: /data/pgdata
---
apiVersion: v1
kind: Service
metadata:
name: postgres-db-lb
spec:
selector:
app: postgresql-db
type: LoadBalancer
ports:
- port: 5432
targetPort: 5432
---
apiVersion: v1
kind: ConfigMap
metadata:
name: record-linkage-config
labels:
app: record-linkage
data:
MPI_DB_TYPE: postgres
MPI_DBNAME: testdb
MPI_PORT: '5432'
MPI_USER: postgres
MPI_PASSWORD: pw
MPI_PATIENT_TABLE: patient
MPI_PERSON_TABLE: person
---
apiVersion: v1
kind: Service
metadata:
name: record-linkage-service
spec:
selector:
app: record-linkage
type: LoadBalancer
ports:
- port: 8080
targetPort: 8080
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgresql-db
spec:
serviceName: postgresql-db-service
replicas: 1
selector:
matchLabels:
app: postgresql-db
template:
metadata:
labels:
app: postgresql-db
spec:
containers:
- name: postgresql-db
image: postgres:latest
volumeMounts:
- name: postgresql-db-disk
mountPath: /data
envFrom:
- configMapRef:
name: postgres-db-config
livenessProbe:
exec:
command:
- pg_isready
failureThreshold: 20
periodSeconds: 2
timeoutSeconds: 5
ports:
- containerPort: 5432
name: "http"
volumeClaimTemplates:
- metadata:
name: postgresql-db-disk
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 25Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: record-linkage
labels:
app: record-linkage
spec:
selector:
matchLabels:
app: record-linkage
replicas: 1
template:
metadata:
labels:
app: record-linkage
spec:
containers:
- name: record-linkage
image: ${IMAGE}
ports:
- containerPort: 8080
name: "http"
volumeMounts:
- mountPath: "/app"
name: record-linkage-source-code-storage
envFrom:
- configMapRef:
name: record-linkage-config
- configMapRef:
name: postgres-db-config
env:
- name: CUSTOMCONNSTR_RecordLinkageContext
value: Host=$(POSTGRES_DB_LB_SERVICE_HOST);Database=$(POSTGRES_DB);Username=$(POSTGRES_USER);Password=$(POSTGRES_PASSWORD)
- name: MPI_HOST
value: $(POSTGRES_DB_LB_SERVICE_HOST)
imagePullPolicy: IfNotPresent
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 15
periodSeconds: 10
resources:
limits:
memory: 2Gi
cpu: "1"
volumes:
- name: record-linkage-source-code-storage
emptyDir: {}
23 changes: 23 additions & 0 deletions ops/manifests/scripts/minikube-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cd $(dirname $0)
minikube delete
minikube start
eval $(minikube docker-env)

if [ -z $1 ];
then
docker build -t phdi/record-linkage ../../
export IMAGE=phdi/record-linkage
envsubst < ../record-linkage.yml | kubectl apply -f -
else
docker pull --platform linux/amd64 $1
export IMAGE=$1
envsubst < ../record-linkage.yml | kubectl apply -f -
fi

echo "\n"
echo "waiting for cluster to reconcile..."
sleep 20

minikube tunnel &> /dev/null &
sleep 5
kubectl get all

0 comments on commit 120165d

Please sign in to comment.