Check out a free preview of the full Introducing DevOps for Developers course:
The "Writing the CircleCI Config" Lesson is part of the full, Introducing DevOps for Developers course featured in this preview video. Here's what you'd learn in this lesson:

Erik walks through writing and configuring a circleci.yml file to further automate building and testing.

Get Unlimited Access Now

Transcript from the "Writing the CircleCI Config" Lesson

[00:00:00]
>> Let's do something a little bit more complex now, which is let's do our circleci.yml. Now I have a circleci.yml that I can use, and I'm gonna just show it to you, but it's not gonna be directly related to any type of tool, it's actually gonna be related to automation.

[00:00:18] So I run all of my automation in the cloud, as I'm sure most of us do, however, I have made a decision to use Pulumi everywhere, right? So what that means is if I've made a decision to use Pulumi, I can also make decisions on how jobs run in CI, right?

[00:00:42] And if we look at this configuration, for example, this is a circleci configuration. You'll see that I have an orb at the top, the TLDR on orbs, it's a reusable way of using code. It helps me so that I can use the AWS CLI with their orb or their package essentially.

[00:01:01] So that's the only thing to take away from that is, this just makes it so I have AWS CLI available to me. The next thing, log into ECR. This is a Docker file, right? We're gonna use Docker files pretty much everywhere. So we need a standardized way of authenticating with ECR.

[00:01:20] Think about how many configurations you've made, where you had a ton of boilerplate you had to do, just to get it to work and authenticate and all that stuff. Here, you just get it out of the box. We know you need to connect to ECR. So add that to the template so that you have it.

[00:01:40] And so then we start talking about build steps, right? And so if we start looking at this you'll notice that I have heavily standardized how some of this works. But what we can do to kind of make it fit for our circumstance is instead of this saying SHA circle CI, whatever, let's do this.

[00:02:02] Let's say this is actually gonna be the service name, Right? And then this will be the service name. As a matter of fact, there's more places we can do that because look, [LAUGH] I've got a bunch of names in my configuration all over the place. So how can we fix that?

[00:02:26] Altf4llc pulumi github. There. Now, I can even inject image names into my configuration based off of the standardization of service names and stuff like that, all right? And so then you'll see here after we've got basically our job, so our first job is our build job, right? It sets up our AWS CLI for us, right?

[00:03:08] It installs just or some other things that we need, but then again, the main point here is is that we're passing in the service name of our choice so that when we build it, we just build this service. We don't wanna build a different service with a different name or anything like that, we wanna just build this service.

[00:03:25] And after we build this service and push that image right here, right, then we wanna reuse that image here. But I don't know what the service name is gonna be for the image. However, we standardized in service directory how we name things. So because we standardize how we name things and on top of it, we know that in service directory we'll get a registry repository, right, now we can expect where our images are gonna be and automate around it without being worried about it.

[00:04:04] Okay, and so, again you can see here is our refresh, our preview and our update. Everything else is just pretty much straight-forward. So, again what we're really trying to do is, we're just trying to look for anything that have Pulumi GitHub or anything that made this unique and we're making it into a generic template that we can then reuse, right?

[00:04:25] And so now what we'll do, is we'll go here, and just like the dockerfile, circleci, circleci yml, right? And then here circleci.yml cuz we wanna create the file, and then this is gonna be the circleci render. I think I spelled that right, circleci.yml. Yeah, is it yml or ymal?

[00:05:01] Yml, okay cool, all right? There it is, DevOps course. DevOps course. The image, DevOps course, right? The image, Devops course. Now you don't even have to write configuration CI anymore. [LAUGH] So, as I said, what is the purpose of this? Is it to show you something cool and just wow you?

[00:05:37] No, [LAUGH] the main purpose of this is to hope that you can see how you can use programming to save you time, right? It's not just about making features and things like that when it comes to DevOps. It's about looking at the time we're spending and making sure that we're utilizing that time appropriately.

[00:05:59] I'm sure all of us can sit, again, [LAUGH] here for hours at sitting around configuration files and would have loved to just be able to hit up DevOps and be like, can I just auto generate this? You know what I mean? Or, again, the service directory thing. I just want a whole front end deployment.

[00:06:16] Okay, cool. Just add the configuration, you're done. These types of tools at Hippo, where I work, have changed how we talk at Hippo as well, because it's not so much developers coming to us anymore for help but they're now just coming to us for approvals, right? The conversation shifted from, hey, can we do this, to hey, can you approve this?

[00:06:45] And that's a lot easier than having to go through this whole other conversation of like, why do you have to do it [SOUND]? Having these standards and these practices that they have to, again, bump around, helps especially with those kind of conversations. Because, again, we say what we support, right?

[00:07:05] We support these docker files, we support these CircleCI configurations, we support these type of deployments, and then we basically just iterate off of them. If we need more stuff in our front end, what do we do? We just simply add more to that, yep, add more to the service directory.

[00:07:25] If we need a whole new template, really quickly if I was to say, all right, well I know some of them use a .npmrc. Here's the best part, you don't even have to template it. You can just put it in there so that they get it. It doesn't have to be a templated file, It just simply is saying, I want this CLI tool to give me everything that a developer expects, right?

[00:07:50] And so if we wanted to do that, right, we could just simply say, okay, cool, npmrc.npmrc, and .npmrc. And within five seconds almost, right, now, I can literally, Get an npmrc file. [LAUGH] And again, it's not templated, it doesn't have anything unique about it, but it's within the developer's expectations of what they're gonna get, right?

[00:08:29] And on top of it, it also takes their control away. And it says, we're in control of this file. If you need it, we'll give it to you.