c6106f7884
I'm particularly excited about this idea. As I was reading Graham's "Erase your darlings" blog post, I had an idea: I should have playbooks at the root of my monorepo. I can have playbooks for the following: - How to install NixOS - How to build GCR images from Nix expressions - A collection of miscellaneous shell commands (e.g. "how to kill a process by name") - What series of steps should I follow when I receive a paycheck I already keep README's at the root of each package, which I think is where many of these instructions belong. Other tutorials that I write for myself that do not belong to any package can go in //playbooks. I also will host my personal habits in //playbooks since habits are a bit like playbooks for life. Let's see how this idea ages as the caffeine wears off... |
||
---|---|---|
.. | ||
cloud_run.nix | ||
config.lisp | ||
README.md |
Nix + Google Cloud Run (i.e. GCR)
I'm documenting how I currently deploy projects that I package with Nix on Google Cloud Run.
I'd like to automate this workflow as much as possible, and I intend to do just that. For now, I'm running things manually until I can design an generalization that appeals to me.
Dependencies
nix-build
docker
gcloud
Step-by-step
- Use
nix-build
to create our Docker image for Cloud Run.
> nix-build ./cloud_run.nix
This outputs a Docker image at ./result
.
- Load the built image (i.e.
./result
) intodocker
so that we can tag it and push it to the Google Container Registry (i.e. GCR).
> sudo docker load <./result
- (Optionally) Run the image locally to verify its integrity.
> sudo docker run -d -p 8080:4242 <name>:<tag>
- Tag and push the image to GCR.
> sudo docker tag <name>:<label> gcr.io/<google-cloud-project-id>/<name>:<latest>
- Visit Google Cloud Run; create a new service with "Create Service"; select the uploaded Docker image from the "Container Image URL" field; click "Create" to deploy.
Notes
You may need to authorize gcloud
by running the following:
> sudo gcloud auth login --no-launch-browser
You must use sudo
here since the docker
invocations are prefixed with sudo
as well.
Todos
- If possible, prefer using a command line tool like
gcloud
to create the Cloud Run service.