<?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 Cristian Covali on Medium]]></title>
        <description><![CDATA[Stories by Cristian Covali on Medium]]></description>
        <link>https://medium.com/@cristian.covali?source=rss-e2e1b2f47727------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qWCbTNYFKLsQ6YtgJpE49g.png</url>
            <title>Stories by Cristian Covali on Medium</title>
            <link>https://medium.com/@cristian.covali?source=rss-e2e1b2f47727------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 01:20:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cristian.covali/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[How we deploy our branch]]></title>
            <link>https://medium.com/crunchyroll/how-we-deploy-our-branch-d0231bacb9b7?source=rss-e2e1b2f47727------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0231bacb9b7</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[anime]]></category>
            <category><![CDATA[crunchyroll]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[tools]]></category>
            <dc:creator><![CDATA[Cristian Covali]]></dc:creator>
            <pubDate>Fri, 11 Feb 2022 15:22:53 GMT</pubDate>
            <atom:updated>2022-02-11T15:22:53.584Z</atom:updated>
            <content:encoded><![CDATA[<p>Writing code is fun. You can build great things, challenge your brain to solve complex problems, and of course, everything works perfectly “on your local machine.” Sometimes you face the situation when you need to set up your project on a colleague’s machine, and things don’t go as smoothly as they “should.” <br>You ran into a situation when he either doesn’t have docker, doesn’t have the correct version of dependency 1, dependency 2, his machine doesn’t support one or another thing, and you waste more time digging and trying to debug when the real problem is that you want to share the feature you developed. Here at Crunchyroll, one of the requirements we have in terms of code review is that you should perform a short QA on the code you are reviewing. This means you should check out the branch, install the dependencies, build the project and start it, just to check if the color/width/height of a button is correct or not.</p><h3>Deploy your code instead of setting it up</h3><p>Knowing what the problem is, is the first step to solving it. We face the problem that we want to share the functionality/feature we develop with someone else QA/PM/DEV with minimal effort. So instead of setting up the project on their machine, we decided that we wanted to deploy our code and make it accessible via simple applications like a browser.</p><h3>Choosing the right tools to deploy your code</h3><p>There are many tools to write your infrastructure as code like AWS CloudFormation, Red Hat Ansible, Chef, Puppet, SaltStack, HashiCorp Terraform, etc. We decided to use terraform for this task, mainly because it is open-source, community-driven, and has a very elegant syntax.<br>Also, since we work very closely with AWS, we decided to use ECS as a container engine for our branch environment and ECR as the container registry. It’s the era of containers anyway. Building and registering the container can be done via any CI; therefore, the smartest choice would be to simply use what we already have for unit tests, linters, and other code quality checks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2OH3dYg-QtwU-MWVaDkA1Q.png" /></figure><h3>Let&#39;s put things together</h3><p>Since we know the tools we want to use, we need to orchestrate them. First, we need to have a build job in our project CI pipeline. Project configuration can be handled in different ways like files, volumes, environment variables. The simplest way to do this when working with containers is environment variables, which works perfectly when you don’t have many parameters.</p><pre>build_and_push_image:<br>  steps:<br>    - aws-ecr/build-and-push-image:<br>        account-url: AWS_ECR_ACCOUNT_URL_ENV_VAR_NAME<br>        aws-access-key-id: ACCESS_KEY_ID_ENV_VAR_NAME<br>        aws-secret-access-key: SECRET_ACCESS_KEY_ENV_VAR_NAME<br>        dockerfile: myDockerfile<br>        region: AWS_REGION_ENV_VAR_NAME<br>        tag: &#39;latest,myECRRepoTag&#39;</pre><p>One extra job we have in our flow is a job that synchronizes our static files. After that, we need to register our image into ECR, and finally, we can apply our terraform files to deploy the environment.</p><pre>sync_static_assets:<br>  steps:<br>    - checkout<br>    - docker_image_load<br>    - docker_create:<br>        img_name: app<br>    - run:<br>        name: Extract build files<br>        command: docker cp app:/app/build build<br>    - aws-cli/setup:<br>        aws-access-key-id: AWS_ECR_ACCOUNT_URL_ENV_VAR_NAME<br>        aws-secret-access-key: SECRET_ACCESS_KEY_ENV_VAR_NAME<br>        aws-region: AWS_REGION_ENV_VAR_NAME<br>    - aws_s3_sync:<br>        from: build<br>        to: s3://AWS_BUCKET_NAEM/$BRANCH</pre><p>We need to ensure that each environment doesn’t have conflicts with other ones. We can use either terraform workspaces for that or look for other tools like terragrunt, which offer different levels of flexibility when working with multi-environment terraform modules.</p><pre>terraform_apply:<br>  steps:<br>    - checkout<br>    - aws-cli/setup:<br>        aws-access-key-id: AWS_ECR_ACCOUNT_URL_ENV_VAR_NAME<br>        aws-secret-access-key: SECRET_ACCESS_KEY_ENV_VAR_NAME<br>        aws-region: AWS_REGION_ENV_VAR_NAME<br>    - run:<br>        name: Deploy infrastructure into AWS<br>        command: terragrunt apply -auto-approve</pre><p>In the end, our workflow is going to look like this:</p><pre>deploy:<br>    - build_and_push_image<br>    - sync_static_assets<br>    - terraform_apply</pre><h3>Make sure to clean up things</h3><p>Now since we have our environment up and running, we can easily share it with anyone who needs to take a look at the feature we implemented. But things are not finished yet. Once our feature was tested, approved, and merged, we no longer need the environment we deployed; therefore, we need to orchestrate an undeploy pipeline for that. The easiest way to achieve this is via our VCS webhooks. Once a pull request is merged, we can set up a webhook to undeploy the environment, clean up the static files, and get everything cleaned.</p><pre>undeploy:<br>    - terraform_destroy<br>    - remove_static_files<br>    - unregister_ecr_image</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XHP7tMf3zoamrt1-17qFxA.png" /></figure><h3>Future plans</h3><p>Having an environment deployed for each our branch allows us to implement features like:</p><p>- running automation tests on commit level;<br>- performing lighthouse automated audits;<br>- writing custom performance audits.</p><p>This opens the path for a healthier and safer development cycle. We are actively thinking about new areas of improvement. Thank you for the read, and I hope this experience will help you deploy your code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0231bacb9b7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/crunchyroll/how-we-deploy-our-branch-d0231bacb9b7">How we deploy our branch</a> was originally published in <a href="https://medium.com/crunchyroll">Crunchyroll</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>