sortalon.co
This is the code that runs my personal site. It uses the
Yesod framework using the default
site template, builds with
Stack, and deploys Docker.
Development
Stack is the build tool that automates most of the building commands you need:
$ stack build
$ stack test
$ stack ghci
$ stack exec -- $COMMANDThese are all quite useful, and do what you'd expect. The latter two perform
their respective tasks using the dependencies declared in the cabal file. The
tool is also well-documented:
$ stack --helpYesod has a convenient development mode that automatically recompiles the code
when you make changes to it. I haven't yet been able to get this working in the
Dockerized container, so you have to tell Stack to run it directly on your
machine:
$ stack --no-docker exec -- yesod develNote: This will likely require rebuilding all of the app's dependencies,
since the Docker container seems to keep a separate cache of built artifacts.
Deployment
I did all my work from OS X, so I assume that environment.
Ensure you have Docker set up:
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default - virtualbox Running tcp://192.168.99.100:2376 v1.10.3
$ docker-machine start default # if the VM isn't running.
$ eval $(docker-machine env default) # set up ENV for docker CLI
$ docker ps # just check things are set up right
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESBuild a Docker image:
$ stack image containerRun the image:
$ docker run sortalongo/sortalonco-webserverMake sure it works:
$ docker exec `docker ps --format="{{.ID}}" -l` curl http://localhost:3000/To keep the image for posterity:
$ docker tag sortalongo/sortalonco-webserver sortalongo/sortalonco-webserver:VERSIONOnce that's done, we need to get the image to Google Cloud. I'll omit details
specific to my setup. Setup is pretty straightforward. Just follow the standard
flow for a Google Container Engine cluster and Google Container Repository. By
the end, you'll have the gcloud and kubectl tools set up to talk to your
G.E accounts & projects.
- Push the image to GCR:
$ docker tag sortalongo/sortalonco-webserver us.gcr.io/PROJECT/webserver:VERSION
$ gcloud docker push us.gcr.io/PROJECT/webserver:VERSION- Go into
k8s.rc.yaml, and update the resource names, labels, and
image name to the respective version. - Do a rolling update using Kubernetes:
$ kubectl rolling-update webserver-rc-OLD_VERSION -f k8s.rc.yaml
Created webserver-rc-v2
Scaling up webserver-rc-v2 from 0 to 3, scaling down webserver-rc from 3 to 0 (keep 3 pods available, don\'t exceed 4 pods)
Scaling webserver-rc-v2 up to 1
Scaling webserver-rc down to 2
Scaling webserver-rc-v2 up to 2
Scaling webserver-rc down to 1
Scaling webserver-rc-v2 up to 3
Scaling webserver-rc down to 0
Update succeeded. Deleting webserver-rc
replicationcontroller "webserver-rc" rolling updated to "webserver-rc-v2"You can get OLD_VERSION by looking at the name of the running replication
controller (kubectl get rcs).
You can monitor the state of the pods by looping over kubectl get pods.