<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Wilhelm Flüsse on Medium]]></title>
        <description><![CDATA[Stories by Wilhelm Flüsse on Medium]]></description>
        <link>https://medium.com/@gasrios?source=rss-1ab1442989d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H7IMfXfYOY3hYyEFXt6SNA.png</url>
            <title>Stories by Wilhelm Flüsse on Medium</title>
            <link>https://medium.com/@gasrios?source=rss-1ab1442989d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 11:26:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gasrios/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A comment on “clean code” and SOLID…]]></title>
            <link>https://medium.com/@gasrios/a-comment-on-clean-code-and-solid-bc2f15c143d?source=rss-1ab1442989d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc2f15c143d</guid>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Wilhelm Flüsse]]></dc:creator>
            <pubDate>Tue, 08 Sep 2020 17:45:35 GMT</pubDate>
            <atom:updated>2020-09-08T23:42:27.120Z</atom:updated>
            <content:encoded><![CDATA[<p>The book by Robert C. Martin Et al. is insightful and definitely worth reading. Still, I have no doubt one can read it, apply all principles in it (well, almost all; more on that in a jiffy) and still write crappy code.</p><p>The problem is, people do not realize “clean code” is to writing code as a grammar is to writing a book, or, if you are lucky, an essay, depending on how big the particular chunk of code you are working on is, and how intertwined it is with the rest.</p><p>My point being, clarity is about the idea at least as much as it is about expressing it; you can’t formulate a reasonable point about a subject unless you study and understand it, first and foremost.</p><p>You can find great romances out there, for example, written by people that do not have a perfect domain of grammar, or whom make the conscious choice of challenging formal grammar. When these books work, that happens because the author has such a good grip on what they are trying to say that, as long as the language does not stand in the way of understanding their point, you really don’t care about it. In fact, you hardly pay attention to it.</p><p>One can argue programs are not romances, but objective expressions of ideas. Fair enough, so before jumping into clean code and writing computer programs, let me try another analogy: technical writers usually are not grammar masters (unless the subject they write is grammar itself) and, no matter how technical their subject is, some are just better than others at making their books more readable. Andrew S. Tanenbaum being the best example that comes to my mind right now.</p><p>Actually, this point is not lost in Martin’s book, and here is a quotation that proves it:</p><p><em>“Understand the Algorithm</em></p><p><em>“Lots of very funny code is written because people don’t take the time to understand the algorithm. They get something to work by plugging in enough if statements and flags, without really stopping to consider what is really going on.</em></p><p><em>“Programming is often an exploration. You think you know the right algorithm for something, but then you wind up fiddling with it, prodding and poking at it, until you get it to ‘work.’ How do you know it ‘works’? Because it passes the test cases you can think of.</em></p><p><em>“There is nothing wrong with this approach. Indeed, often it is the only way to get a function to do what you think it should. However, it is not sufficient to leave the quotation marks around the word ‘work.’</em></p><p><em>“Before you consider yourself to be done with a function, make sure you understand how it works. It is not good enough that it passes all the tests. You must know that the solution is correct.</em></p><p><em>“Often the best way to gain this knowledge and understanding is to refactor the function into something that is so clean and expressive that it is obvious how it works.”</em></p><p>Now, if I have a problem with this book, it is that, in my edition, the excerpt above is part of Chapter 17, the very last one, “Smells and Heuristics,” section “General”, item “G21” out of 36. You can find it at page 287. This is the kind of thing that should be said at the beginning of chapter one, it should even be discussed in the introduction. Hell, the foreword should start with it, and there should be a whole chapter devoted to this subject alone.</p><p>Maybe the problem is the book assumes this point is a prerequisite well understood by anyone reading it. Well, in my experience, it isn’t; the more time passes, the worse it gets, as the idea that degrees do not matter and should be replaced by “certificates” become more prevalent. Which is not wrong in and on itself, considering the low standards of certain college degrees, and assuming the equivalent certificates do more than just giving one working knowledge of (very) specific technologies, without ever teaching people how to actually think about problem solving.</p><p>Another problem is, in practice, several ideas put forth in “clean code” are not as clean cut as one might imagine. In fact, I’m pretty sure there’s a lot of people out there thinking they follow the book to the letter in their daily lives, but fail to write “clean code” because, conceptually and long before they start writing, they were already approaching their problem incorrectly. Giving things “meaningful names” means nothing, when they denote the wrong concepts.</p><p>Not to mention sometimes the problem is not happening at development time at all, and technically minded individuals may fail to realize that: if you are not given time to write quality into your programs, you will just jump from one chunk of unclean code to the next. I usually approach this by negotiating a “capacity reserve” with whatever relevant stakeholders there might be, outside of my team, so paying technical debt becomes routine.</p><p>And, trust me on that, paying technical debt and writing clean code are one and the same; you never get it right the first time, sometimes you know it immediately, sometimes it takes a while, but, apart from the really obvious stuff, which can be dealt with best practices, “clean code” emerges out of successive iterations. It’s never there when you write it, even if it looks good enough at first glance. Just give it some time, and people will start noticing issues they previously missed.</p><p>If anything, the “clean code frenzy” motivated me to go back to a book no one talks about anymore, and I never got around to actually reading from cover to cover: “The Art of Computer Programming”, Volume one (out of seven planned, three and a quarter of which were already written), by Donald E. Knuth.</p><p>And, by the way, in this book, Section 1.1 of Chapter 1, “Basic Concepts,” is called “Algorithms”. That’s literally page one.</p><p>So, in closing, and just in case you forgot along the reading: “the book by Robert C. Martin Et al. is insightful and definitely worth reading.” But, people, please stop treating it like a panacea, it is just one tool in the box and, I dare say, not the most important one. By the time you can actually benefit from “clean code”, you got the basics of actually performing problem solving and designing algorithms so well, the only thing left is adjusting a few tweaks here and there, using the reasonable standards defined in the book, so the next guy will not have issues with the language, and can jump straight into understanding what you were trying to do.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc2f15c143d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up a local environment for DevOps related development]]></title>
            <link>https://medium.com/@gasrios/setting-up-a-local-environment-for-devops-related-development-3414a53b70db?source=rss-1ab1442989d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3414a53b70db</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[jenkins-pipeline]]></category>
            <dc:creator><![CDATA[Wilhelm Flüsse]]></dc:creator>
            <pubDate>Tue, 20 Aug 2019 20:52:10 GMT</pubDate>
            <atom:updated>2019-08-21T13:02:59.974Z</atom:updated>
            <content:encoded><![CDATA[<p>Once your service is up and running on the cloud, things are great. But, before you get there…</p><ol><li>During development, updating your code many times per day (or even per hour) is not unusual. Even if you automate the whole deployment process, it still takes time to execute it; the more stuff you can test locally, before absolutely having to start deploying it, the better;</li><li>Even if you can live with multiple deployments during development, unless you provide one remote test environment for each developer, they are bound to start stepping on each other’s toes, once their work leave their computers.</li><li>There is no point in testing something locally, unless you can expect the same behavior, after deploying it. The closest your local environment is to the real thing, the better.</li><li>Testing CI/CD, in my case Jenkins <a href="https://jenkins.io/doc/book/pipeline/getting-started/#defining-a-pipeline-in-scm">pipelines</a> and <a href="https://jenkins.io/doc/book/pipeline/shared-libraries/">Shared Libraries</a>, is not easy.</li></ol><p>(Note: while reviewing Jenkins pipeline test alternatives, I came across the following projects that are worth mentioning: <a href="https://issues.jenkins-ci.org/browse/JENKINS-33925]">JENKINS-33925</a> discusses the need for a test framework for Jenkinsfiles, but has not seen any action since it was created, back in 2016; <a href="https://github.com/jenkinsci/JenkinsPipelineUnit">JenkinsPipelineUnit</a> seems to have gained some traction; and <a href="https://github.com/jenkinsci/jenkinsfile-runner/">Jenkinsfile Runner</a> caught my attention, too)</p><p>All this is difficult to approach; after all, you can’t run the cloud in your laptop.</p><p><strong>Or can you?</strong></p><p>Every person I know that arrived at DevOps, coming from software development, has wondered about this, and tried to come up with a solution, sometimes for personal use, sometimes to standardize development environments across their team or teams. How deep to go into this pursuit is a matter of personal choice: if you have great Internet connection, budget is not a concern (at least, not to you, and you alone can but make a dent on the overall budget) and you have a monster of a computer to work on, you are likely to put very little work into it, get the basics running, and you are ready to go.</p><p>Or, if you are me, working on one of my personal projects, on my laptop, from home, this is kind of a big deal. Eventually, I started putting some code together. The result was <a href="https://github.com/gasrios/localops">localops</a>, followed by its sibling project, <a href="https://github.com/gasrios/localops-infra">localops (infra)</a>. Both are opinionated approaches to how to set up a development environment for <a href="https://kubernetes.io/">Kubernetes</a> based services.</p><p>Think of it more as a proof of concept than a one-size-fits-all solution. Your mileage may vary, you may have other concerns I don’t, or choose to address the very same ones differently. My goal is to propose one way to approach certain issues, to promote reflecting about them.</p><p>localops is a set of <a href="https://www.ansible.com/">Ansible</a> playbooks. I figured that, if Ansible was good enough to manage enterprise wide infrastructures, it should be enough to automate the work of setting up a development computer in a way to make it replicable, ensuring all setups that use localops are compatible with each other.</p><p>In short, I eventually grew tired of having to execute exactly the same steps manually, whenever I had to set up a new computer for development, so I decided to automate them (hence the overly unimaginative name). This helped specially while testing pipelines; using localops, installing Jenkins from scratch boils down to…</p><pre># install localops<br>wget -O- \<br> <a href="https://raw.githubusercontent.com/gasrios/localops/ubuntu_bionic_beaver/bootstrap.sh">https://raw.githubusercontent.com/gasrios/localops/ubuntu_bionic_beaver/bootstrap.sh</a> \<br> | sh -</pre><pre># install Jenkins<br>./ansible-playbook.sh jenkins.yaml</pre><p>… including creating a Kubernetes cluster and a <a href="https://docs.docker.com/registry/">Docker registry</a>.</p><p>Ok, now I have a shareable environment in which both pipeline development and everyday coding can be tested, and this probably would have been enough for me. Still, I wanted something others could benefit from, by using as reference for their own projects and ideas, or even by adopting it as their development environment. As it stood, localops does nothing to motivate someone else, specially people who are not working on pipeline related issues, to go through the pain of changing from their setup to something else.</p><p><a href="https://github.com/gasrios/localops-infra">localops (infra)</a> is meant to bridge that gap, by providing an easy-to-use entry point to localops, in the form of scripts that handle local execution of services, either as k8s pods, or using <a href="https://docs.docker.com/compose/">Docker Compose</a>. The only caveat is, localops (infra) needs the services to provide a <a href="https://www.gnu.org/software/make/">Makefike</a>, so it knows how to build them. I have made a case for the use of make to build cloud services <a href="https://medium.com/@guilhermerios/decoupling-project-and-pipeline-specific-logic-blocks-on-a-ci-cd-pipeline-496b4e747786">elsewhere</a>, and there is no reason why both approaches shouldn’t work together; in fact, each one leverages the other.</p><p>Both projects have more documentation on their GitHub repositories, in case you would like to give them a try.</p><p><strong>“But why would you…”</strong></p><p>I am not 100% comfortable with some of the technical decisions made, and imagine someone looking at the code might question them. Here are a few things I may review in the future:</p><p>1. Set up a k8s cluster using kubeadm</p><p>There are many different ways you can <a href="https://developer.ibm.com/blogs/options-to-run-kubernetes-locally/">run Kubernetes locally</a> and, arguably, doing so from scratch is not be best choice. In fact, I tried all other alternatives, before committing to this one.</p><p>One “nice to have” goal (meaning, one that should never take precedence over other, more important, ones) I set to myself, when I started, was ensuring localops would be as low resource-intensive as I could make it to be. This meant, for example, using minikube’s <a href="https://kubernetes.io/docs/setup/learning-environment/minikube/#specifying-the-vm-driver">vm-driver=none</a> option. Which I could not make work after a few tries, so I moved on to Microk8s, then k3s. And every time, something would go wrong. Eventually, I got it working with kubeadm, and decided to focus on other stuff, and that was it.</p><p>I am not saying you should not use any of those solutions, in fact, I encourage you to, because they are great and would love to support them in localops. But you can only insist on something so many times before giving up.</p><p>One thing I really want to try is using <a href="https://kubernetes.io/docs/setup/production-environment/tools/kubespray/">Kubespray</a> and <a href="https://metallb.universe.tf/]">MetalLB</a>. But, baby steps.</p><p>2. Set up a local Certification Authority</p><p>Running a local CA does seem to be far-fetched. To even begin defending this, I assume, as a premise, that running a <a href="https://docs.docker.com/registry/deploying/">local Docker registry</a> is necessary. If this use case does not apply to you, there is no hope in making a case for a local CA. These aren’t the droids you’re looking for. Move along.</p><p>Still with me? Good! Remember I wrote above: “the closest your local environment is to the real thing, the better.” Well, the way Docker handles secure and insecure registries is different enough to justify forcing the use of a secure local registry. If your registry is insecure, you can’t get away with tagging, pushing or pulling, <a href="https://docs.docker.com/engine/reference/commandline/push/#push-a-new-image-to-a-registry">unless you specify a port explicitly</a>.</p><p>Which does not seem to be that big of a deal, until you realize you will have to add that port to all references to your image… including FROM declarations in Dockerfiles that use it, k8s manifests, the pipeline and so on.</p><p>One of the things I wanted localops to support was adding real Docker registry URLs to /etc/hosts, pointing to 127.0.0.1. This would allow for simulating, locally, docker push operations to Docker registries in your cloud provider, or even to docker.io. You could also test images locally before making them available in registries used by your enterprise. And I could not come up with any way to do this, other than using a local secure registry.</p><p>Now, I could have just created a snake-oil certificate, or use Docker’s own features to create certificates. But, considering setting up a local CA is just a matter of creating a few files, and I was already using Ansible and nginx, I went with it.</p><p>Again, local CAs and secure registries are meant to support particular use cases, which may not apply to everyone. In fact, <a href="https://raw.githubusercontent.com/gasrios/localops-infra/master/services/hello/Makefile">the example service</a> provided as part of localops (infra) shows how you could run local tests, without having to resort to secure local registries, by dynamically changing your repository in Dockerfiles, k8s configurations and on the build itself. So, pick your choice.</p><p><strong>The future of localops</strong></p><p>The main feature I tried to have in localops, that seemed to be missing for similar approaches, was going all the way when “bringing the cloud to your computer”, including the pipeline, which is to say, the CI/CD process itself, as a first class citizen of the development process.</p><p>I like expressing ideas in code, and will definitely keep evolving localops and localops (infra), because both became cornerstones of several personal projects I am working on. Still, I think of them less as “products” or “frameworks” than “concepts”: there are infinitely many ways to approach the “cloud in a computer” concept, and I am skeptical as to the possibility of a one-size-fits-all solution ever existing for this. But it is a topic worth pursuing, and localops is my personal contribution to this discussion.</p><p>What I imagine will happen, going forward, is some sort of “divergent evolution”, with both projects acting as test-beds for ideas and ways to support as many “cloud resources” as possible, locally, for development purposes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3414a53b70db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Things to avoid when adopting DevOps]]></title>
            <link>https://faun.pub/things-to-avoid-when-adopting-devops-a17115fb1ae5?source=rss-1ab1442989d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a17115fb1ae5</guid>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Wilhelm Flüsse]]></dc:creator>
            <pubDate>Thu, 15 Aug 2019 22:53:27 GMT</pubDate>
            <atom:updated>2019-08-22T14:12:06.378Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever since my professional career shifted from development to DevOps (meaning I stopped coding in Java and started working with CI/CD pipelines and IaC), I’ve had the chance to learn a few “dos” and “don’ts” of DevOps culture adoption/implementation, on existing teams and projects.</p><p>Well, if there was one insight I got out of reading Jim Collins’ “How the Mighty Fall”, it was that it pays more to look at what people have done wrong, and avoid it, than at what was done right, only to end up asking yourself “how come it did not work? I did everything right!”</p><p>So, without further ado, here is my list of “things you should never, ever, ever do, when adopting DevOps”:</p><p><strong>Mixing up “DevOps” and “The Cloud”</strong></p><p>Or, put in a different way, mistaking technology for culture, that is, approaching something that is essentially a concept as if it was a matter of start using a set of tools.</p><p>On a parallel universe where no one came up with cloud computing, there are still people adopting DevOps, and benefiting from it; on another one, where no one thought about DevOps, you still have people opening support tickets to infra, asking them to setup new database servers for them. It’s just that, there, sysops run scripts, instead of adding servers to racks in data centers.</p><p>As the name implies, “DevOps” will impact on how at least two very distinct groups of people do their work; some responsibilities will be shared, others transferred between them altogether. Granted, learning new technologies, like Jenkins pipelines and Terraform, is a challenge on its own, but hardly the most difficult one, for technically oriented people; it’s the mindset transformation hardships that screw you.</p><p>Here’s the example I always come back to, to drive home the point of how different “culture” is from “technology”: do not expect developers, that never had to care about infrastructure costs, will suddenly realize they should not spin environments just because they can, after you give then that amazing, fully automated, just-push-this-button, IaC enabled, interface. It is like giving a bazooka to a child, then blaming the child for what happens afterwards.</p><p>You have a team with five people, working on the same sprint, albeit in different stories/features, that are constantly stepping on each others toes because they are all deploying to the same stage environment. From their point of view, it may seem perfectly reasonable to create other environments; if doing so would be unacceptable because of cost related issues, do not expect they will realize that on their own.</p><p>If anything, they are probably thinking that, by spinning new environments, they are optimizing their development process and actually <strong>cutting down</strong> costs.</p><p>This is just an example of one, among many things, that could go wrong. What you should have done, in the first place, was evaluating the impact adopting DevOps would have across your enterprise, anticipating which new responsibilities and concerns each team member (or team member profile) would now have, and train them accordingly.</p><p>Everything else is more or less a side effect of this mistake, in the sense that not realizing the distinction between “culture” and “technology” leads to poor planning.</p><p><strong>Assume the development team will catch on the technology on their own, without proper training</strong></p><p>Just because the technology is not where you should start, does not mean you should underestimate it. For example, it is becoming increasingly common to find developers that are familiar with <a href="https://en.wikipedia.org/wiki/OS-level_virtualisation">containerization</a>, but not so much that you can simply assume anyone could properly configure a Kubernetes deployment, in ways that are both safe and resource correct (that is, neither allocating more resources than needed, generating unnecessary costs, nor too little of them, causing pods to starve and crash).</p><p>It pays to support key team members in learning new technologies, so they can in turn help spreading the knowledge to everyone else. In my experience, poorly understood new technologies are more damaging than the ones you know absolutely nothing about. What you <strong>don’t</strong> know, you learn; what you <strong>think</strong> you know, you do wrongly.</p><p>Learning-as-you-go has its benefits, but do tend to make people only catch up to something when the need arises; which sometimes is only after something has gone terribly, terribly wrong.</p><p>There are lots of online training platforms out there, and lots of certifications. Help your key team members get them.</p><p><strong>Ignore your context, history and team members profiles</strong></p><p>Say you have an amazing development team: your architects seem to feed on technology books and articles, and are always on top of everything that is going on in IT. Your developers code as if their fingers are dancing away carelessly on their keyboards.</p><p>Still, shit happens, and sometimes it happens in production. On Sunday. At 4:00AM.</p><p>And, because you adopted DevOps, you now believe whoever builds the code, runs it. In the old days, an alarm would go up, or someone would notice the issue, and sooner or later your operations team would get cracking on it. Because this is how things used to be done back then, they would most likely be sysops.</p><p>Now, you are playing a different game. Now, the “DevOps guys” are responsible for monitoring, and they will handle it. Problem is, that super development team you have abhors support. They believe, most of the time, when something goes wrong, it is not because their superb code has a bug, but because the network had a glitch, or a database has to be scaled up, or anything else they don’t care about.</p><p>Well, you say, they should care, because now we are doing it “the DevOps way”. But maybe they are thinking don’t have to care, at all. They just have to find a new job.</p><p>It does happen, you know. People get unhappy about their current job and move on to new ones. I have never worked on a company at which turnover was not, to some extent or another, a concern.</p><p>Cultural transformations can be traumatic events. It pays off to set the game rules, before your roll them out. Sometimes people will be ok with them, as long as they are consulted first, and have a chance to agree on what you expect of them, and organize accordingly. Sometimes you will know, in advance, that you need to hire new profiles, to cover the bases your team is currently missing.</p><p><strong>Starting DevOps as a technical initiative, without executive sponsorship</strong></p><p>Because people — all kinds of people, all across the enterprise — see DevOps as something inherently technical, sometimes they miss how important it is to get executive sponsorship, first.</p><p>Say you want to start doing continuous delivery as part of your project, because you know this will help with POs complaining your team does not seem to be able to keep up with the competition: if they can have a new feature up and running in just a few days, how come it takes <strong>you</strong> weeks?</p><p>So, you work overtime, write a pipeline and tell your team to start doing Trunk Based Development. Presto! You now can deploy new features in production not in days, but <strong>hours</strong>.</p><p>Except…</p><ul><li>Your scrum master still wants stories broken down in a way that does not grant you the granularity you would need to deploy features independently from one another, and won’t agree to releases, except at the end of each sprint;</li><li>When you go to your PO for help, they won’t hear any of it: delivering is <strong>your</strong> problem, they are already busy enough seeing where the competition is at, doing research to understand what the clients want, or simply coming up with as many ideas as they can, that they need you to finish by yesterday;</li></ul><p>(To all the product owners out there: sorry. You know I am not talking about you, right? But we all know <strong>that</strong> guy, don’t we?)</p><ul><li>Management can’t or won’t approve overtime, and your team can’t or won’t work out of regular hours to learn everything they need to run the new process, so you are seeing a sudden decline in performance;</li><li>Stuff is breaking up in production a lot more often than it used to.</li></ul><p>You can’t mobilize people for change, if they think the change in question is out of their scope of work, and it can be hard to explain why DevOps is their problem, too. Your best bet is to seek executive sponsorship.</p><p>If you can get people above you to understand the value of what you are trying to do (and if you can’t, maybe you should consider whether there is actually value in it), you won’t have to do the same to people around you, with their own problems and concerns. It’s not their job to see the benefits you see, but yours to create a context in which transformation can happen and each person receives the conditions they need to be able to commit to delivering what is expected of them.</p><p>And last but not least…</p><p><strong>Assume “adopting DevOps” is a one-shot initiative</strong></p><p>Just like you would never assume your product has reached perfection and will never need another feature added to it, never assume your DevOps efforts have reached their peak, and are finished.</p><p>If I was given the opportunity of having a whole department to stop to “work on setting DevOps up” for a fixed period of time, then go back to their business, I would never take it, not in a million years. I would probably suggest to direct 10% of the available resources to it, but for an indefinite amount of time. It this was not approved, I would bring it down to 5%, and try again, then work on building success cases that might justify increasing the investment.</p><p>Just like everything else, we are talking about a learning process. At first, things will go wrong, problems will be misunderstood and underestimated. Things you never thought of will appear out of nowhere. It’s not like shooting an arrow at a known target; it’s more like driving to a destination based on spoken instructions (ok, maybe written down on a piece of paper), without a map (or, these days, without GPS) and without knowing the road conditions (we are probably talking about an apocalypse-like scenario here).</p><p>So, you want a long-lived commitment on something everyone agrees, and understands, will not be perfect at first, but will improve, given time.</p><p>I dare say that, if you do not make any of the mistakes above, no matter how you are approaching the adoption of DevOps at your enterprise, you have a reasonable chance of success. Each context will be different and demand a different approach, but these errors seem to be pervasive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>💬<strong>.</strong></p><p><strong>To join our community Slack </strong>🗣️ <strong>and read our weekly Faun topics </strong>🗞️,<strong> click here⬇</strong></p><figure><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oSdFkACJxs5iy1oR" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a17115fb1ae5" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/things-to-avoid-when-adopting-devops-a17115fb1ae5">Things to avoid when adopting DevOps</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decoupling “project” and “pipeline” specific logic blocks on a CI/CD pipeline]]></title>
            <link>https://medium.com/@gasrios/decoupling-project-and-pipeline-specific-logic-blocks-on-a-ci-cd-pipeline-496b4e747786?source=rss-1ab1442989d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/496b4e747786</guid>
            <category><![CDATA[jenkins-pipeline]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[continuous-deployment]]></category>
            <category><![CDATA[makefile]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Wilhelm Flüsse]]></dc:creator>
            <pubDate>Thu, 15 Aug 2019 18:19:50 GMT</pubDate>
            <atom:updated>2019-08-15T20:04:26.137Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Disclaimer:</strong> this is an extremely personal view on how to implement CI/CD pipelines, that I have not adopted on any but a few personal projects, and find promising, but YMMV. I am just throwing it out there to, hopefully, get some feedback on how other people feel about it.</p><p><strong>In the beginning…</strong></p><p>It all started with the following thought: “damn, I wish I could test this pipeline locally”. Ok, it was more of a swear than a thought, but still.</p><p>This would happen under one out of two possible circumstances:</p><ul><li>While testing a pipeline I was working on.</li></ul><p>My pipeline development cycle felt unnecessarily slow and heavy, forcing me to push changes to GitHub and using our Jenkins server to run them using another project, sometimes competing for resources with other teams, like available Jenkins agents or GitHub’s API limits.</p><p>This is nothing new; people have been thinking about it for some time (<a href="https://issues.jenkins-ci.org/browse/JENKINS-33925">JENKINS-33925</a>, <a href="https://github.com/jenkinsci/JenkinsPipelineUnit">JenkinsPipelineUnit</a>) and, incidentally, on a topic not directly related to this article, it was one among several concerns that led me to create <a href="https://github.com/gasrios/localops">localops</a>, an idea I will eventually write about, too.</p><p>The second scenario, however, is more relevant to this article:</p><ul><li>When I, or someone on my team, would forget to run locally some step that would end up breaking the build, and should have been tested locally before pushing code.</li></ul><p>This got me thinking whether there were ways to mock a pipeline execution locally, not for the benefit of the pipeline itself, but to help developers to be more thorough, by automating their work. Please keep in mind I am not talking about tools like <a href="https://gradle.org/">Gradle</a>, <a href="https://cli.angular.io/">Angular CLI</a> or many others, which everyone should use, always, and most likely the pipeline will, too. What I mean is, how can I help my developers to be sure, by the time they try to deploy their code to any environment, that they effectively did all they had to, for the pipeline not to fail?</p><p>The first answer that comes to mind is quite simple: by writing a shell script, or maybe leveraging the project’s build tool, adding a “pipeline” task/target/goal to it, that emulates pipeline behavior.</p><p>But…</p><p>Once I started reflecting on this, I got the feeling there was something more meaningful that I was missing. Lots of questions started popping on my mind, each one more abstract and conceptual than the previous:</p><ul><li>Isn’t there redundancy in having the steps I want to run, and the order I want them run into, defined in two different places?</li><li>What happens if the pipeline logic changes? Who is in charge of keeping both flows updated to enforce the same process?</li><li>Do I really want to run all the pipeline steps locally and, in case I don’t, what is the difference between those I want, and those I do not?</li><li>If I think about “pipeline” as a document that defines a process (a sort of “documentation as code” approach), do I really want it tied to specific technologies and platforms? Wouldn’t it be nice if I could use the same process to deploy Angular, Node.js, Java and what-have-you on Kubernetes, AWS Lambdas, GCP Cloud Functions…</li><li>Where is the frontier that separates that which I want to enforce (as part of the pipeline), from that which I want to be customizable (as part of the projects that use it)?</li></ul><p><strong>Make me, asshole</strong></p><p>All these questions came to me at different moments and, at some point while trying to answer them, it occurred to me <a href="https://www.gnu.org/software/make/">make</a> might help, by providing a layer of abstraction between pipelines and projects. After all, it is not true all projects are written in Java, built with Gradle and deployed to EKS, but it is a much safer bet to assume your Jenkins was deployed on a platform that can run make.</p><p>(BTW, it is no accident that “Jenkinsfile” and “Dockerfile” follow a convention initially created with “Makefile”.)</p><p>As I started playing around with this notion, it started making more and more sense. In fact, when you think about it, technologies aside, “deployment processes” are notably uniform these days. Stripping them down to the bare minimum, deployments are usually made of:</p><ul><li><em>static code review</em>, which not everyone does, but everyone should do;</li><li><em>build</em>, that is, generating deployable artifacts from source code;</li><li><em>build-config</em>, usually thought of as part of the build, but which generates artifacts that are environment dependent, and you may want to execute separately, given that “build” only need to happen once, for all environments you are deploying to;</li><li><em>test</em>, which covers all sorts of tests, and you may want to break additionally down into whatever makes sense to you: unit, performance etc;</li><li><em>versioning</em>, to ensure proper SCM and traceability, from deployments to source code bases;</li><li><em>publish</em>, which is making your artifacts available for later deployment (think publishing to a Docker registry, or copying your lambda to a bucket);</li><li><em>deploy</em>.</li></ul><p><strong>Talk is cheap</strong></p><p>Let’s look at some example code I wrote, to help materialize the concept. First, the pipeline itself, which is deployed as a <a href="https://jenkins.io/doc/book/pipeline/shared-libraries/">Jenkins shared library</a></p><p><em>vars/continuousDelivery.groovy</em></p><pre>#!groovy<br>def call() {</pre><pre>pipeline {</pre><pre>  agent any</pre><pre>  environment {<br>    def VERSION = &quot;${GIT_BRANCH + &#39;_&#39; + env.BUILD_ID}&quot;<br>    def ENVIRONMENT =<br>      &quot;${GIT_BRANCH.equals(&#39;master&#39;)? &#39;prod&#39; : &#39;test&#39;}&quot;<br>  }</pre><pre>  stages {</pre><pre>    stage(&#39;Code review&#39;) {<br>      steps {<br>        script { sh &quot;make code-review&quot; }<br>      }<br>    }</pre><pre>    stage(&#39;Build project&#39;) {<br>      steps {<br>        script { sh &quot;make clean build&quot; }<br>      }<br>    }</pre><pre>    stage(&#39;Build environment specific artifacts&#39;) {<br>      steps {<br>        script {<br>          sh &quot;make build-config ENVIRONMENT=${ENVIRONMENT} VERSION=${VERSION}&quot;<br>        }<br>      }<br>    }</pre><pre>    stage(&#39;Test&#39;) {<br>      steps {<br>        script { sh &quot;make test&quot; }<br>      }<br>    }</pre><pre>    stage(&#39;Versioning&#39;) {<br>      steps {<br>        script {<br>          sh &#39;git add .&#39;<br>          sh &quot;git commit -m \&#39;Version ${VERSION}\&#39; || exit 0&quot;<br>          sh &quot;git tag -f ${VERSION}&quot;<br>          sh &quot;git push \$(git config --get remote.origin.url)&quot;<br>          sh &quot;git push \$(git config --get remote.origin.url) ${VERSION}&quot;<br>        }<br>      }<br>    }</pre><pre>    stage(&#39;Publish&#39;) {<br>      steps {<br>        script { sh &quot;make publish ENVIRONMENT=${ENVIRONMENT} VERSION=${VERSION}&quot; }<br>      }<br>    }</pre><pre>    stage(&#39;Deploy&#39;) {<br>      steps {<br>        script { sh &quot;make deploy ENVIRONMENT=${ENVIRONMENT} VERSION=${VERSION}&quot; }<br>      }<br>    }</pre><pre>  }</pre><pre>}</pre><pre>}</pre><p>As you can see, the pipeline delegates to “make” most of the work, aside from versioning. The idea here is, going back to “where is the frontier that separates that which I want to enforce, from that which I want to be customizable?”, that version control is something we want standardized across all projects, not to mention something you should never run locally.</p><p>In order to use the pipeline, all projects will need to import it, by defining a Jenkinsfile in their root directories:</p><p><em>Jenkinsfile</em></p><pre>library ‘shared-library’</pre><pre>continuousDelivery()</pre><p>Looks simple enough. Now, we need a project that uses our pipeline; the example below assumes it is written in Java, built using gradle and deployed to Kubernetes. It will need the following Makefile on its root directory:</p><p><em>Makefile</em></p><pre>PROJECT := java-gradle-k8s<br>REPOSITORY := DOCKER_REGISTRY_URL<br>UNIX_TIME := $(shell date +%s%N)<br>VERSION ?= $(UNIX_TIME)<br>ENVIRONMENT ?= dev</pre><pre>.PHONY: clean code-review build-config test publish deploy pipeline</pre><pre>clean:<br> ./gradlew clean</pre><pre>code-review:<br> ./gradlew findBugsMain</pre><pre>build: build/libs/$(PROJECT).jar<br>build/libs/$(PROJECT).jar: $(shell find src/main/java)<br> ./gradlew bootRepackage</pre><pre>build-config:<br> mkdir -p manifests<br> rm -f manifests/$(ENVIRONMENT).yaml<br> kustomize build overlays/$(ENVIRONMENT) &gt; manifests/$(ENVIRONMENT).yaml</pre><pre>test:<br> ./gradlew test</pre><pre>publish:<br> docker build -t $(REPOSITORY)/ref/$(PROJECT):$(VERSION) .<br> docker push $(REPOSITORY)/ref/$(PROJECT)</pre><pre>deploy:<br> cat manifests/$(ENVIRONMENT).yaml<br> kubeval manifests/$(ENVIRONMENT).yaml<br> kubectl config use-context $(ENVIRONMENT)<br> kubectl apply -f manifests/$(ENVIRONMENT).yaml</pre><pre>pipeline:<br> make clean<br> make code-review<br> make build<br> make build-config<br> make test<br> make publish<br> make deploy</pre><p>Points of interest:</p><ul><li>The Makefile provides sensible defaults for parameters VERSION and ENVIRONMENT, so, when running locally, the developer does not have to worry about them;</li><li>This project uses Gradlew’s <a href="https://docs.gradle.org/current/userguide/findbugs_plugin.html">FindBugs Plugin</a> for code review;</li><li>Configuration is generated dynamically with <a href="https://kustomize.io/">kustomize</a>.</li></ul><p>Now the developer can replicate the pipeline’s behavior locally by running “make pipeline”. No more excuses for pushing code that breaks it. =^)</p><p>What’s even more interesting, though, is that, if the development team chooses to migrate the project to, say, Python, it is their responsibility to update their Makefile, but, as far as the build is concerned, the process remain fundamentally the same. Another example would be, if the project were to move from k8s to AWS Lambda, the build would not care, either. From Lambda to Google Cloud Functions? No difference, the pipeline is still the same, enforcing best practices uniformly across as diverse a platform/ecosystem as you want.</p><p>(<strong>Note:</strong> of course there are all sorts of configurations under the hood that would still be needed to enable Jenkins to support all those platforms. My point is, now there is only one uniform way to think about your deployment process across all the enterprise, one that promotes best practices. And, while I haven’t got that far, yet, <a href="https://jenkins.io/doc/book/pipeline/docker/">configuring agents using Docker</a> for each deployment should make that job easier. In fact, each project might provide their own build Docker image.)</p><p>By now, the attentive reader might be asking: you did not fix two of the problems you set out to fix at the beginning: make rule “pipeline” is redundant with your Jenkins pipeline; and someone has to keep both in sync. Yes, that is correct, and I do not have an answer to that, yet. As I said, the more I thought about it, the more I moved away from my initial practical concerns, and into process-related, abstract, ones. And all this is still a work in progress, at best.</p><p><strong>In conclusion</strong></p><p>That’s it. I think the main takeaways from this article should be:</p><ol><li>Is “pipeline re-usability” a valid concern?</li><li>Can a pipeline be implemented in ways that make it a tool to enforce processes and best practices, not tied to particular technologies?</li><li>Can a pipeline be thought of as “documentation as code”?</li><li>How can we define rules to separate what should be enforced, from what should be customizable?</li><li>What are the best practices to actually implement generic, reusable pipelines, ensuring proper decoupling among technologies, platforms, projects, processes and standards?</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=496b4e747786" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The agony and the ecstasy of Git squash]]></title>
            <link>https://medium.com/@gasrios/the-agony-and-the-ecstasy-of-git-squash-7f91c8da20af?source=rss-1ab1442989d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f91c8da20af</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Wilhelm Flüsse]]></dc:creator>
            <pubDate>Mon, 12 Aug 2019 22:01:43 GMT</pubDate>
            <atom:updated>2019-08-16T13:13:39.290Z</atom:updated>
            <content:encoded><![CDATA[<p>Every now and then, my team would run into issues while trying to “<a href="https://help.github.com/en/articles/about-pull-request-merges#squash-and-merge-your-pull-request-commits">Squash and merge</a>&quot; pull requests in GitHub. The most common ones would be merge conflicts that made no sense, and duplicated commits.</p><p>Well, one can only see this happening so many times before deciding to really understand what is happening. Unfortunately, GitHub documentation is less than clear on what exactly transpires under the hood. So, I did some experiments using Git and, hopefully, what follows is an accurate description of that functionality, preceded by an overview of different Git merge techniques, for the sake of clarity.</p><p>First, a bit of context: we perform continuous delivery; our processes and pipeline enforce <a href="https://trunkbaseddevelopment.com/short-lived-feature-branches/">short lived feature branch development</a>. Different merge strategies may apply to other situations, but, for us, a well executed “Squash and merge” yield several benefits, hence my interest on its inner workings.</p><p><strong>Basic setup</strong></p><p>This is the base scenario I set up for my tests. Assume the following git commands are executed inside a pristine repository, created in GitHub, then cloned locally:</p><blockquote>$ echo ‘file1 created’ &gt; file1<br>$ git add file1<br>$ git commit -m ‘Added file1’<br>$ git push -u origin master<br>$ git checkout -b feature-branch<br>$ echo ‘file2 created’ &gt; file2<br>$ git add file2<br>$ git commit -m ‘Added file2’<br>$ git push -u origin feature-branch<br>$ git checkout master<br>$ echo ‘file1 updated’ &gt; file1<br>$ git add file1<br>$ git commit -m ‘Updated file1’<br>$ git push<br>$ git checkout feature-branch<br>$ echo ‘file2 updated’ &gt; file2<br>$ git add file2<br>$ git commit -m ‘Updated file2’<br>$ git push</blockquote><p>The situation I am trying to simulate is:</p><ol><li>Having a master branch with preexisting history;</li><li>Developer creates, then starts working on, their feature branch;</li><li>Developer pushes feature branch to remote at least once per day, possibly while it is still inconsistent (perhaps it has known bugs, or even breaks the build);</li><li>Meanwhile, the master is changing, too (for example, because someone merged a production hotfix, or someone else merged their feature branch first);</li><li>Developer finishes work on feature, and commits, then pushes to remote, their work one last time.</li></ol><p>For the sake of simplicity, I am assuming there are no merge conflicts. If there were, they would have to be fixed before merging, but the overall picture would essentially remain the same.</p><p>By now, this is how this repository’s history would look like (using “git log --reverse”):</p><blockquote><strong><em>master</em></strong></blockquote><blockquote>commit a5e333fef78d393bbd6a50f60f48450a86b51f26<br>Author: XXX<br>Date: Thu Aug 8 16:14:17 2019</blockquote><blockquote>Added file1</blockquote><blockquote>commit 3f94bace42f5e8e7db261311eb95512215e9ddc3 (HEAD -&gt; master, origin/master)<br>Author: XXX<br>Date: Thu Aug 8 16:18:58 2019</blockquote><blockquote>Updated file1</blockquote><blockquote><strong><em>feature-branch</em></strong></blockquote><blockquote>commit a5e333fef78d393bbd6a50f60f48450a86b51f26<br>Author: XXX<br>Date: Thu Aug 8 16:14:17 2019</blockquote><blockquote>Added file1</blockquote><blockquote>commit 8590c5e0ff12773d87a518a9e2d7f96c26c6c486 (origin/feature-branch)<br>Author: XXX<br>Date: Thu Aug 8 16:15:51 2019</blockquote><blockquote>Added file2</blockquote><blockquote>commit ba04d82434ab3b56bdf55da52e0c57cb6147a0ee (HEAD -&gt; feature-branch)<br>Author: XXX<br>Date: Thu Aug 8 16:23:47 2019</blockquote><blockquote>Updated file2</blockquote><p><strong>Merging</strong></p><p>The simplest way to combine all the work done so far is performing your everyday, vanilla, merge:</p><blockquote>$ git checkout master<br>$ git merge feature-branch</blockquote><p>This is how the log looks like, after merging:</p><blockquote><strong><em>master</em></strong></blockquote><blockquote>commit a5e333fef78d393bbd6a50f60f48450a86b51f26<br>Author: XXX<br>Date: Thu Aug 8 16:14:17 2019</blockquote><blockquote>Added file1</blockquote><blockquote>commit 8590c5e0ff12773d87a518a9e2d7f96c26c6c486 (origin/feature-branch)<br>Author: XXX<br>Date: Thu Aug 8 16:15:51 2019</blockquote><blockquote>Added file2</blockquote><blockquote>commit 3f94bace42f5e8e7db261311eb95512215e9ddc3 (origin/master)<br>Author: XXX<br>Date: Thu Aug 8 16:18:58 2019</blockquote><blockquote>Updated file1</blockquote><blockquote>commit ba04d82434ab3b56bdf55da52e0c57cb6147a0ee (feature-branch)<br>Author: XXX<br>Date: Thu Aug 8 16:23:47 2019</blockquote><blockquote>Updated file2</blockquote><blockquote>commit f604199b0a1acf1987ec86f458880892ffce3793 (HEAD -&gt; master)<br>Merge: 3f94bac ba04d82<br>Author: XXX<br>Date: Thu Aug 8 17:03:55 2019</blockquote><blockquote>Merge branch ‘feature-branch’</blockquote><p>At this point, we don’t care about the feature branch history anymore (in fact, it should be deleted, both locally and on the remote).</p><p>The main takeaways from this example are:</p><ul><li>A merge commit (f604199b0a1acf1987ec86f458880892ffce3793) was created</li><li>“feature-branch” commit hashes (8590c5e0ff12773d87a518a9e2d7f96c26c6c486 and ba04d82434ab3b56bdf55da52e0c57cb6147a0ee) remain unchanged, after merging</li><li>Commit temporal order (‘Added file1’, ‘Added file2’, ‘Updated file1’ and ‘Updated file2’) was preserved in history</li><li>“git log --graph” will show two branches, each with its own set of commits</li><li>8590c5e0ff12773d87a518a9e2d7f96c26c6c486, our unreliable, possibly buggy, commit, is part of master’s history now.</li></ul><p>Depending on how your project works, or what your personal preferences are, or which tools you use to manage history, all or none of the points above might be relevant.</p><p><strong>Rebasing</strong></p><p>Let’s see what happens when we <a href="https://git-scm.com/docs/git-rebase">rebase</a>:</p><blockquote>$ git rebase master<br>$ git checkout master<br>$ git merge feature-branch</blockquote><blockquote><strong><em>master</em></strong></blockquote><blockquote>commit a5e333fef78d393bbd6a50f60f48450a86b51f26<br>Author: XXX<br>Date: Thu Aug 8 16:14:17 2019</blockquote><blockquote>Added file1</blockquote><blockquote>commit 3f94bace42f5e8e7db261311eb95512215e9ddc3 (origin/master)<br>Author: XXX<br>Date: Thu Aug 8 16:18:58 2019</blockquote><blockquote>Updated file1</blockquote><blockquote>commit d0950960667bc717ea27bed905b39aa1f6d85d02<br>Author: XXX<br>Date: Thu Aug 8 16:15:51 2019</blockquote><blockquote>Added file2</blockquote><blockquote>commit 4546851fdb29ab4022835e9f3bf0ab3e61e859bd (HEAD -&gt; master, feature-branch)<br>Author: XXX<br>Date: Thu Aug 8 16:23:47 2019</blockquote><blockquote>Updated file2</blockquote><p>Notice there is no merge commit, this time; also, the hashes of commits “Added file2” and “Updated file2” have changed. This means they are not the same commits, anymore, but updated copies of them.</p><p>The following points are also worth noting:</p><ul><li>Commit temporal order was not preserved in history (All commits to “feature-branch” now are after all commits in master, up until the rebase)</li><li>“git log --graph” will show only one branch</li><li>d0950960667bc717ea27bed905b39aa1f6d85d02, our unreliable, possibly buggy, commit, is still part of master’s history.</li></ul><p><strong>Squashing</strong></p><p>For me, the most confusing point to was understanding that <a href="https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History">squashing</a> is actually a particular case of rebasing, literally: there is no “git squash” command. Instead, this is how you squash commits in Git:</p><blockquote>$ git rebase -i $(git merge-base master feature-branch)<br>$ git checkout master<br>$ git merge feature-branch</blockquote><p>And this is what squashing does:</p><blockquote><strong><em>master</em></strong></blockquote><blockquote>commit a5e333fef78d393bbd6a50f60f48450a86b51f26<br>Author: XXX<br>Date: Thu Aug 8 16:14:17 2019</blockquote><blockquote>Added file1</blockquote><blockquote>commit 3f94bace42f5e8e7db261311eb95512215e9ddc3 (origin/master)<br>Author: XXX<br>Date: Thu Aug 8 16:18:58 2019</blockquote><blockquote>Updated file1</blockquote><blockquote>commit a789fccb90eafc7a471140923b6fdaa9400ce5ce (feature-branch)<br>Author: XXX<br>Date: Thu Aug 8 16:15:51 2019</blockquote><blockquote>Added file2<br> <br> Updated file2</blockquote><blockquote>commit 6d0d6d6aad6c74e541557dfc6a8a242b962d4dc8 (HEAD -&gt; master)<br>Merge: 3f94bac a789fcc<br>Author: XXX<br>Date: Thu Aug 8 19:11:31 2019</blockquote><blockquote>Merge branch ‘feature-branch’</blockquote><p>Again, and contrary to rebasing as previously seen, a merge commit (6d0d6d6aad6c74e541557dfc6a8a242b962d4dc8) was created; However, this time, and because of squashing, no commits in master’s history are inconsistent (unless the feature branch itself was inconsistent). Also, “git log --graph” shows two branches.</p><p>If you were to try and execute the commands above, you would see that “git rebase -i” would start an “interactive step”, and you would have to manually replace “pick” with “squash” in the second commit, to actually perform the squashing. You would have to do that to as many commits as there were, after the first, to squash them all together, and it would only work if there were no merge conflicts, to begin with; I will talk about this in more detail below.</p><p><strong>Squashing and rebasing</strong></p><p>What if we tried both squashing, then rebasing, our branch, before merging it to master?</p><blockquote>$ git rebase -i $(git merge-base master feature-branch)<br>$ git rebase master<br>$ git checkout master<br>$ git merge feature-branch</blockquote><p>This is how the repo’s history looks, after the commands above:</p><blockquote><strong><em>master</em></strong></blockquote><blockquote>commit a5e333fef78d393bbd6a50f60f48450a86b51f26<br>Author: XXX<br>Date: Thu Aug 8 16:14:17 2019</blockquote><blockquote>Added file1</blockquote><blockquote>commit 3f94bace42f5e8e7db261311eb95512215e9ddc3 (origin/master)<br>Author: XXX<br>Date: Thu Aug 8 16:18:58 2019</blockquote><blockquote>Updated file1</blockquote><blockquote>commit bbaf18933f8976387337ee0abdbf24b69dd75f46 (HEAD -&gt; master, feature-branch)<br>Author: XXX<br>Date: Thu Aug 8 16:15:51 2019</blockquote><blockquote>Added file2<br> <br> Updated file2</blockquote><p>This is arguably the best history scenario, for short lived feature branch development (fell free to disagree, though). Consider the following points:</p><ul><li>No merge commit was created, but commit bbaf18933f8976387337ee0abdbf24b69dd75f46 covers exactly what was added in the context of whatever feature was being worked on</li><li>“git log --graph” will show only one branch, that is, the project’s history is clear and linear</li><li>No commits in master’s history break the build, assuming no feature is merged without proper testing</li></ul><p>But, just as when squashing, there will be an interactive step to be handled.</p><p><strong>Using GitHub’s “Squash and merge” button</strong></p><p>Having considered all the scenarios above, we are ready to compare GitHub’s “Squash and merge” button to them. If you were to open a PR, then squash and merge it, your history would look like this, after:</p><blockquote><strong><em>master</em></strong></blockquote><blockquote>commit a5e333fef78d393bbd6a50f60f48450a86b51f26<br>Author: XXX<br>Date: Thu Aug 8 16:14:17 2019</blockquote><blockquote>Added file1</blockquote><blockquote>commit 3f94bace42f5e8e7db261311eb95512215e9ddc3<br>Author: XXX<br>Date: Thu Aug 8 16:18:58 2019</blockquote><blockquote>Updated file1</blockquote><blockquote>commit 283373480579bfa9ea344c3c603a17a8144e017f (HEAD -&gt; master, origin/master)<br>Author: XXX<br>Date: Fri Aug 9 15:17:10 2019</blockquote><blockquote>Feature branch (#1)<br> <br> * Added file2<br> <br> * Updated file2</blockquote><p>Essentially, it is the same behavior as squashing and rebasing (no merge commit is created, history is linear), without the interactive step. Also, if there were any merge conflicts, GitHub would force you to fix them, prior to merging.</p><p>All things considered, “Squash and merge” provides all the benefits of squashing and rebasing, with none of the drawbacks.</p><p><strong>Pitfalls</strong></p><p>All this is nice and good, but, as I said earlier, sometimes things just don’t happen as expected, and my team would end up with merge conflicts that made no sense and duplicated commits. After finally understanding how “Squash and merge” works, I came up with a scenario that would explain what was happening. Let’s consider the following variation of our base scenario:</p><blockquote>$ echo ‘file1 created’ &gt; file1<br>$ git add .; git commit -m ‘Added file1’<br>$ git push<br>$ git checkout -b feature-branch<br>$ echo ‘file2 created’ &gt; file2<br>$ git add .; git commit -m ‘Added file2’<br>$ git push -u origin feature-branch<br>$ git checkout master<br>$ echo ‘file1 updated’ &gt; file1<br>$ git add .; git commit -m ‘Updated file1’<br>$ git push</blockquote><p>(At this point, we open a PR in GitHub, and “feature-branch” is merged to master via GitHub’s “Squash and merge”, then deleted.)</p><blockquote>$ git checkout feature-branch<br>$ echo ‘file2 updated’ &gt; file2<br>$ git add .; git commit -m ‘Updated file2’<br>$ git push</blockquote><p>What happens if you merge, or open a PR, now? You get a conflict, because both branches have created files with the same name, but different contents. GitHub cannot tell there was only one creation action, because now the commits have different IDs (a side effect of rebasing/squashing).</p><p>You can see what happened locally by executing the following commands:</p><blockquote>$ git checkout master<br>$ git fetch --all<br>$ git pull<br>$ git merge feature-branch<br>$ git status</blockquote><blockquote>On branch master<br>Your branch is up to date with ‘origin/master’.</blockquote><blockquote>You have unmerged paths.<br> (fix conflicts and run “git commit”)<br> (use “git merge --abort” to abort the merge)</blockquote><blockquote>Unmerged paths:<br> (use “git add &lt;file&gt;…” to mark resolution)</blockquote><blockquote>both added: file2</blockquote><blockquote>no changes added to commit (use “git add” and/or “git commit -a”)</blockquote><p>Unsurprisingly, what the example above shows is, when weird issues happen, they are caused by process flaws. In this case, the reuse of a feature branch, after it has been merged to master.</p><p>The main takeaway here is: rebase (any form of rebasing, including squashing) should be the absolute last thing you do in a feature branch. <strong>Never reuse a branch, once it has been rebased</strong>. It should be deleted, both from local and remote, and any new work should go into a new branch, with a different name.</p><p><strong>Conclusion</strong></p><p>After researching the matter, I do not believe there is anything intrinsically wrong with GitHub’s “Squash and merge” button. On the contrary, it enforces squashing and rebasing, which I believe to be the best merge strategy provided by Git, for short lived feature branch development, with the additional benefit of only allowing it to happen at the exact moment it should, and without the hassle of interactive rebasing.</p><p>Which is not to say it is impossible to end up with unwanted scenarios, but when you take human failure into account, this is always a possibility. The particular case relevant here, the reuse of feature branches after they are merged, would yield issues under any merging strategy (albeit other strategies might handle them more gracefully). Still, I feel pretty comfortable adopting it, and working with my team to ensure they follow proper process, to avoid merge chaos.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f91c8da20af" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>