メインコンテンツへスキップ
見出し画像
Photo bytakemu113

We built awesome internal CI/CD with ArgoCD and Workflows.

    Hi! I’m Rob. I work at a company called EMC Healthcare. We do a lot of IoT work in the hardware lab and host some of our services directly from the office.

    A cool side-effect of having all of that hardware is that we have a ton of freely available CPU and RAM. We very literally have crates of mini pcs, server racks with dozens of cpus, and sticks of RAM and spare parts almost everywhere. We also aggressively adopted Kubernetes a while ago for managing our on-site deployments.

    The problem: Our workflow was pretty flakey and kind of inconsistent. We would have a release, find a bug, fix the bug, release, another bug caused by that fix. Have a feature that needs reviewing? Someone else has to pull your code, docker compose up all of your containers, and then verify the changes. Want to show someone what you’re working on, or sales has a question about how something looks? Hope you didn’t change branches, or there goes about 40 minutes of your life while you spin down, stash, change branches, spin up, show, and then repeat.

    So at some point, we decided enough was enough and put some very serious, prolonged effort into making a robust in-office cluster that we could use to run all kinds of complex pipelines and tests. Now, we already had a Gitlab CI/CD pipeline. It was great. We still use it! But it basically linted, built containers, pushed them to ECR (on tag), and called it a day.

    We needed:

    • Unit tests

    • E2E tests

    • Easy ways to test someone’s changes

    • Easy ways to show other people what it your features look like, even if you aren’t working on them

    • This should be cheap, ideally free!

    We built this over time bit-by-bit, but I’m just going to cut to the interesting part where I explain what we have and what it does.

    We had our CTO allocate a bunch of space in the server (CPU, memory, disk space) to run our project. He called it “Rob’s Playground.”

    This profoundly bothered me, and I immediately renamed it “Number Nine.”

    We used K3s to install Kubernetes and we were off. First order of business — install k9s. I cannot use kubectl without looking all the commands up constantly, so this was magical. Then we installed ArgoCD, and eventually Argo Workflows.

    Now, our work flow looks like this:

    • Gitlab sees that code was pushed inside of an MR

    • Gitlab fires off a web hook to our Argo cluster.

    • If this is a newly opened MR, the Argo cluster makes some http requests and updates the matching Notion issue to “in progress”

    • Gitlab then runs linters, compilers, and all the unit tests

    • If these steps pass, a container is built for Gitlab Container Registry

    • Gitlab runners then contact Cloudflare via API and register a new subdomain of [MERGE_REQUEST_ID].[TESTING_DOMAIN].com

    • They then, using Kubernetes and Kustomize, fire off an http request to Argo

    • Argo http controller gets the request and builds a mini-cluster in an Argo app. The minicluster has 2 mongo replicas, all of the containers and services needed to run in prod, is set up to listen to traffic from the sub domain, etc.

    • The cluster runs a mongo sidecar init container to inject data into our two replicas

    • the cluster then runs our front end e2e testing suite written in go. It starts by using an argo workflow to set up 4 chrome browsers and then runs the tester

    • The tester takes and compares screenshots, clicks buttons, etc. and makes sure that everything is all right

    • Finally, it pings Gitlab to it know that the job passed or failed.

    This has a ton of advantages — notion tickets get automatically updated, you get to know if your e2e tests passed without checking logs, etc., but the biggest advantage is that if someone ever wants to test your feature or see it for themselves, they just go to [MERGE_REQUEST_ID].[TESTING_DOMAIN].com and they can see it for themselves!

    The last step is that when the MR is finally merged, Gitlab tells the Argo web hook which deletes the Argo app, freeing up cluster resource and disk space, before updating the notion task to let sales known the feature is ready for release.

    We build all of this piece-by-piece, but the greatest advice I can give anyone looking to build this: document everything. Without good documentation on how the cluster works, this would have been impossible. We actually did it by having 1–2 people work on the cluster at a time, document it, then have another person from the team read the docs, follow in their footsteps, and then explain how it works. If you can’t do that just from the docs, then your docs aren’t good enough.

    The other thing I would recommend is patience. Kubernetes is hard (it typically takes my interns about 2 weeks to learn it), ArgoCD is hard, and Argo Workflows is harder. Also, the documentation for the ArgoCD API and everything to do with Workflows is terrible, which is a shame because Argo is magical. I even use it on my home network on a couple of mini-pcs to manage my own apps.

    If you have Argo specific questions, reach out!

    Thanks for reading.

    あなたへのおすすめ