Postgresql running in a Docker container.
github.com/jackc/pgx/v4
with the stblib
package so the interface is plain ol' database/sql
.
Gorilla mux but otherwise http
and httptest
.
Probably missing some tricks and best practices to make to code smaller/simpler.
Standard library.
Database tests require an env var set to some psql DB.
Just putting sqlite in a t.TmpDir()
would be much simpler.
httptest
for endpoint tests. Low coverage due to lack of time.
Is there a good way of comparing expected vs. actual response vs. actual db change?
- Use anon. struct with json tags for API?
- Validate incoming Content Type.
- HTTPS.
- Log stmts across handlers and db.
- k8s secrets.
- k8s persistence.
- Better "Update" API.
Use images built locally under minikube for simplicity (skips any registry). Pre-load the DB image with an init-file containing the schema.
minikube start
alias 'kubectl' 'minikube kubectl --'
kubectl get all
kubectl logs -fl app=krud-http-deployment
kubectl port-forward service/krud-psql-service 2345:2345
kubectl port-forward service/krud-http-service 8080:8080
minikube service --url service-name krud-http-service
kubectl delete deployment --all
Pulling down images proved to be quite tricky.
If docker login
works that can be made into a k8s secret:
kubectl create secret generic regcred \
--from-file=.dockerconfigjson=$HOME/.docker/config.json \
--type=kubernetes.io/dockerconfigjson
kubectl patch serviceaccount default \
-p '{"imagePullSecrets": [{"name": "regcred"}]}'
kubectl get serviceaccount default -o yaml
More or less: https://cloud.google.com/kubernetes-engine/docs/deploy-app-cluster . After provisioning resources deplyoment is just:
make images
gcloud container clusters get-credentials kube-cluster
kubectl apply -f deploy