{"id":5282,"date":"2017-02-16T13:12:23","date_gmt":"2017-02-16T13:12:23","guid":{"rendered":"https:\/\/blog.cloudthat.com\/?p=5282"},"modified":"2024-06-25T11:12:13","modified_gmt":"2024-06-25T11:12:13","slug":"awscodebuild","status":"publish","type":"blog","link":"https:\/\/www.cloudthat.com\/resources\/blog\/aws-codebuild-a-fully-managed-build-tool","title":{"rendered":"AWS CodeBuild: A Fully Managed Build Tool"},"content":{"rendered":"<p>Integrate Code, Build Artifact, Manage release. If you know the pain of these processes you might need to look at AWS CodeBuild. Maintaining a project developed by many team members concurrently which is composed of different functions, environment, and languages, AWS CodeBuild is here to help you.<\/p>\n<p>AWS CodeBuild is a fully managed service that compiles your source code and gives you a software package which you can directly deploy into your servers. Instead of setting up and scaling your own build server fleet, you can use CodeBuild to streamline your development process. AWS CodeBuild is elastic, scalable, and easy to use. For each build, it launches a fresh, Isolated container-based environment and terminates it after the build process ends. You can also use CodeBuild as AWS CodePipeline Build Provider.<\/p>\n<p>Let\u2019s look at the major Terminologies of AWS CodeBuild.<br \/>\n\u2022 Source Repository \u2013 Location of your source code.<br \/>\n\u2022 Build Environment \u2013 Your runtime environment.<br \/>\n\u2022 IAM Role \u2013 Grants CodeBuild permission to access to specific AWS services and resources.<br \/>\n\u2022 Build Spec \u2013 Build commands.<br \/>\n\u2022 Compute Type \u2013 Amount of memory and compute power required.<\/p>\n<p>AWS CodeBuild uses Docker containers to build your code depending on your environment. You can use build environments provided by AWS or existing Docker images from Docker hub or Elastic Container Registry. Currently AWS provides build environments for Java, Android, Ruby, Go, Node.js, Python, and Docker (to build Docker images). All your command line output is streamed into AWS management console during the build process. Let\u2019s go through the build process.<\/p>\n<ul>\n<li>CodeBuild fetches code from the Source repository. It could be S3 Bucket, GitHub Repository, or AWS CodeCommit Repository.<\/li>\n<li>\u00a0Runs the commands in the build spec. You can have a buildspec.yml file in the source code root directory or you can explicitly write your build commands. The buildspec contains four phases. Install, pre-build, build and post-build.<\/li>\n<\/ul>\n<p>-&gt; Install \u2013 Install packages in the build environment if any.<br \/>\n-&gt; Pre-build \u2013 Commands that should run before build if any.<br \/>\n-&gt; Build \u2013 Commands to build the artifact.<br \/>\n-&gt; Post-build \u2013 Commands to run after the build if any.<\/p>\n<ul>\n<li>Uploads the generated artifact to S3 with optional KMS encryption.<\/li>\n<\/ul>\n<p>Here is an example for your buildspec.yml<\/p>\n<pre class=\"theme:feeldesign font:courier-new lang:default decode:true\">version: 0.1\r\nenvironment_variables:\r\nplaintext:\r\nJAVA_HOME: \"\/opt\/java-8-openjdk-amd64\"\r\nphases:\r\ninstall:\r\ncommands:\r\n- apt-get update -y\r\n- apt-get install -y maven\r\npre_build:\r\ncommands:\r\n- echo This is pre_build\r\nbuild:\r\ncommands\r\n- echo Starting build `date`\r\n- mvn clean package\r\npost_build:\r\ncommands:\r\n- echo Build completed on `date`\r\nartifacts:\r\nfiles:\r\n- target\/messageUtil-1.0.jar\r\ndiscard-paths: yes<\/pre>\n<p>&nbsp;<\/p>\n<p>Now, let us see how to build your first project in AWS CodeBuild. I\u2019m going to show you how to build a maven project here. I have my maven code zipped and pushed into S3 Bucket.<\/p>\n<p><strong>Step1:<\/strong> Go to AWS CodeBuild console and create a project.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/img21.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-5304 size-large\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/img21.png\" alt=\"img2\" width=\"940\" height=\"268\" \/><\/a><\/p>\n<p><strong>Step2:<\/strong> Give a project name and a description.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/456.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-5289\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/456.png\" alt=\"456\" width=\"975\" height=\"335\" \/><\/a><strong>Step3:<\/strong> Select source provider as S3, select your bucket from the drop-down list and provide your filename.<\/p>\n<p><strong>Step4:<\/strong> Configure your environment to build. Let us use an image managed by AWS.<br \/>\nSelect Runtime as Java, and use Java: openjdk-8 as the version. Under Build command gives as mvn clean package.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/789.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-5290\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/789.png\" alt=\"789\" width=\"692\" height=\"484\" \/><\/a><strong>Step5<\/strong>: Describe where you need your artifacts to get saved.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/107.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-5291\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/107.png\" alt=\"10\" width=\"743\" height=\"321\" \/><\/a><strong>Step6:<\/strong> Select the Service role for your project and click on continue.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1115.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-5293\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1115.png\" alt=\"11\" width=\"963\" height=\"315\" \/><\/a><strong>Step7:<\/strong> Click on Save and build to start to build.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/img7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-5306\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/img7.png\" alt=\"img7\" width=\"722\" height=\"283\" \/><\/a><strong>Step8:<\/strong> This will build your project. To see your build logs from the console.<\/p>\n<p>open the project and select the latest build. Once the project is built successfully you will see your status SUCCEEDED.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1312.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-5294\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1312.png\" alt=\"13\" width=\"953\" height=\"417\" \/><\/a><strong>Pricing:<\/strong><\/p>\n<p>You pay only for the resources you use. You charged for the compute resources you use per minute.<\/p>\n<p>Please write us at forum.cloudthat.com for any queries.<\/p>\n","protected":false},"author":219,"featured_media":5370,"parent":0,"comment_status":"open","ping_status":"open","template":"","blog_category":[3606],"user_email":"prarthitm@cloudthat.com","published_by":"324","primary-authors":"","secondary-authors":"","acf":[],"_links":{"self":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/5282"}],"collection":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/users\/219"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/comments?post=5282"}],"version-history":[{"count":1,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/5282\/revisions"}],"predecessor-version":[{"id":41155,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/5282\/revisions\/41155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/media?parent=5282"}],"wp:term":[{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog_category?post=5282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}