Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
About a week ago I was trying to figure out if thereās a good started Makefile I could use for Go projects.
body[data-twttr-rendered="true"] {background-color: transparent;}.twitter-tweet {margin: auto !important;}
anyone knows any good starter Makefile for Go CLIs? #golang #go
āāā@pjausovec
function notifyResize(height) {height = height ? height : document.documentElement.offsetHeight; var resized = false; if (window.donkey && donkey.resize) {donkey.resize(height); resized = true;}if (parent && parent._resizeIframe) {var obj = {iframe: window.frameElement, height: height}; parent._resizeIframe(obj); resized = true;}if (window.location && window.location.hash === "#amp=1" && window.parent && window.parent.postMessage) {window.parent.postMessage({sentinel: "amp", type: "embed-size", height: height}, "*");}if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.resize) {window.webkit.messageHandlers.resize.postMessage(height); resized = true;}return resized;}twttr.events.bind('rendered', function (event) {notifyResize();}); twttr.events.bind('resize', function (event) {notifyResize();});if (parent && parent._resizeIframe) {var maxWidth = parseInt(window.frameElement.getAttribute("width")); if ( 500 < maxWidth) {window.frameElement.setAttribute("width", "500");}}
I was able to find a bunch of resources that ranged from very simple Makefiles to pretty advanced stuff that includes various tasks, such as running tests, linting, go format,Ā etc.
As I was going through all those resources, I stumbled upon one of the Makefiles from Jess Frazelleās Github repos. In addition to what I considered at this point āstandardā targets (build, lint, format) she also uses a bump-version target that increments the project/package version. To increment the version, Jess uses a sembump tool she created, and I was thinking it would be nice to have a service that I could just curl to and it would do pretty much the sameāāāyouād provide it a version, the portion of the version you want to bump (major, minor or patch) and the service would respond with a newĀ version.
What started as a search for a starter Makefile for Go, ended up a simple service for bumping semversion. Service I created is up and running at https://semver.xyz and you can either curl to it or try it out by going to e.g. https://bump.semver.xyz/minor?version=1.0.0
Iāve also uploaded the whole project to GitHub in case you want to follow along and actually look at theĀ code.
Thanks to the bunch of work already done by others, thereās not much to the actual codeāāāitās only a couple of lines. I am using an existing library called semver, built by Benedikt Lang. That library does the hard part of parsing the version, and I just take the portion of the version you want to bump up and increment it. In addition to this library, I am using Gorilla to expose an endpoint you can call to bump the version it receives.
With the coding portion pretty much done, I started to think what would be the easiest and fastest way to quickly deploy this service to Kubernetes cluster.
At this point an image a toy truck on a huge flatbed truck comes to mindāāāitās probably wasteful to run such a small thing on a cluster, but I already had an existing cluster with stuff running on it, so I am excusedĀ :)
Anyway, in order to get stuff deployed to the cluster, I started with Kubernetes Deployment and Serviceāāāsomething likeĀ this:
Deploying this is a of running kubectl apply -f filename.yaml and youāre good. But, once you make some changes to your code, you have to rebuild the Docker image, push it to the registry and then restart the Pod in order for the new image to be picked up. That meant I probably need a Makefile target that builds and pushes the image(s) for me, which roughly looked like this (I did parametrize the Docker file name and the image nameĀ though):
So, now I am able to build my image and push it to the registry. Next steps was to modify the Kubernetes yaml with the new image name and then deploy it. At first, I wanted to just do define some variables inside the yaml file (e.g. %IMAGE_NAME%, %VERSION%,Ā ā¦) and use sed to replace them with actual values. Sounded like a good approach, but then I remembered I could use Helm and templatize the deploymentāāāit would make things much easier in the long run as Iāll be able to upgrade the releases and have some tracking thatĀ way.
With Helm installed, I started by creating a chart (helm create semver-svc). Luckily, the empty chart Helm has pretty much everything I needed, so it was only a matter of updating the values in the values.yaml file. Once I tested it out by running helm install I ended up back in the Makefile and create another set of targets for installing and upgrading Helm releases:
I defined an install and upgrade targets for the serviceāāāinstall is used first time youāre trying to create a Helm release and upgrade is used for subsequent updates to theĀ release.
With most of the targets parametrized I was able to define the uber upgrade target that bumps the version, builds and publishes the Docker images and finally calls upgrade on the service to actually upgrade the thing thatās already running in the Kubernetes cluster.
The bump-version part of the Makefile is pretty much the same Jess has in her Makefile, difference being that once I had my service deployed, I was able to call the service to bump the version likeĀ this:
I also wanted to expose this service through a custom domain (https://www.semver.xyz) all with SSL and stuff! Setting this up involved installing kube-lego (for automatically obtaining the SSL cert from Letsencrypt) and an Nginx ingress (to expose the service to the world) likeĀ this:
helm install stable/kube-lego \ --set config.LEGO_EMAIL=[YOUR_EMAIL] \ --set config.LEGO_URL=https://acme-v01.api.letsencrypt.org/directory
helm install stable/nginx-ingress --namespace [NAMESPACE]
Since the default Helm chart that was created for the service already contained an ingress.yaml template, it was just a matter of setting the values forĀ it:
Finally, I had to go over to my domain registrar (name.com) and hook up the cool domain I got with the IP address of the Nginx ingress controller (you basically need to create an A record for your domain that points to the IP address).
Done! I had the service now accessible publicly over https! (Later I also added a simple static HTML page and basically used the same targets and a new Helm chart to deployĀ it).
Conclusion
The implementation of the actual service was extremely straightforward and simple. I spent most of my time figuring out the Makefile targets, creating the Helm charts and coming up with the names for my targets (install? upgrade? deploy? release?).
As I next step, Iāll think about trying to come up with a good basic template with a Makefile/Helm charts that I could use for any new services/projects I might workĀ on.
Thanks forĀ Reading!
Any feedback on this article is more than welcome! You can also follow me on Twitter and GitHub. If you liked this and want to get notified when other parts are ready, you should subscribe to my newsletter!
From Makefile to Go semantic versioning service on Kubernetes was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.