<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://adityasinha26.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://adityasinha26.github.io/" rel="alternate" type="text/html" /><updated>2025-02-17T03:43:58+00:00</updated><id>https://adityasinha26.github.io/feed.xml</id><title type="html">Aditya Vikram Sinha</title><subtitle></subtitle><author><name>Aditya Vikram Sinha</name></author><entry><title type="html">Upload Android Libraries from Github to S3 using AWS CodePipeline, CodeBuild</title><link href="https://adityasinha26.github.io/upload-library-to-S3/" rel="alternate" type="text/html" title="Upload Android Libraries from Github to S3 using AWS CodePipeline, CodeBuild" /><published>2020-01-26T19:34:30+00:00</published><updated>2020-01-26T19:34:30+00:00</updated><id>https://adityasinha26.github.io/upload-library-to-S3</id><content type="html" xml:base="https://adityasinha26.github.io/upload-library-to-S3/"><![CDATA[<p>Let’s say I am building an android library and want to host it somewhere but not on Maven Central, JCenter etc. So I decided that I will host it on a S3 bucket and somehow automate the process of getting it there, and then pull artifacts from the bucket in other projects.</p>

<h4 id="requirements">Requirements</h4>
<p>Github , AWS account(free tier would do)</p>

<h4 id="problem">Problem</h4>
<p>An app with source code present on Github has two libraries “liba” and “libb”. Lets say we want these two libraries to be pushed to S3 with appropriate dependancies. The dependancy structure looks something like this:</p>
<blockquote>
  <p>App -&gt; liba -&gt; libb</p>
</blockquote>

<h4 id="solution">Solution</h4>
<h6 id="step-1">Step 1</h6>
<p>Open AWS CodePipeline and create a new pipeline.</p>

<p><img src="/assets/images/2020-01-26-upload-library-to-s3/Step1.png" alt="Step1 Image" /></p>

<h6 id="step-2">Step 2</h6>
<p>Add Github repo and branch as the source of the pipeline. We need webhooks(found in the repo settings) to trigger the pipeline on code commits, tags, releases etc etc (by default it is set to push). Webhooks will get created on the repo automatically by CodePipline.</p>

<p><img src="/assets/images/2020-01-26-upload-library-to-s3/Step2.png" alt="Step2 Image" /></p>

<h6 id="step-3">Step 3</h6>
<p>Add the Build stage which will be used by CodeBuild. Here we specify a docker container on which the code pulled from github is going to run and create the library artifacts(aar, pom files).</p>

<p><img src="/assets/images/2020-01-26-upload-library-to-s3/Step3.png" alt="Step3 Image" /></p>

<h6 id="step-3a">Step 3a</h6>
<p>This step is after creating a codebuild project using the “Create project” option shown in the image above. The configuration for the CodeBuild project is below 👇</p>

<p><img src="/assets/images/2020-01-26-upload-library-to-s3/Step3a.png" alt="Step3a Image" /></p>

<h6 id="step-3b">Step 3b</h6>
<p>CodeBuild requires a buildspec.yml file which needs to be present for it to figure out which commands should be run on the container and what artifacts have to be uploaded.</p>

<blockquote>
  <p>Note : Enabling logs would help debug in case some command fails on the build environment.</p>
</blockquote>

<p><img src="/assets/images/2020-01-26-upload-library-to-s3/Step3b.png" alt="Step3b Image" /></p>

<p>The buildspec.yml file for this project looks like this 👇</p>

<p><img src="/assets/images/2020-01-26-upload-library-to-s3/Step3b-buildspec.png" alt="Step3b-buildspec Image" /></p>

<p>Checkout the source code to see what these gradle tasks do. Gradle requires the files to be in a particular directory structure so that it can be resolved hence the tasks to “moveAAR” and “movePOM”.</p>

<h6 id="step-4">Step 4</h6>
<p>Finally the deploy stage to specify where the created artifacts would live. Make sure the region is same. Otherwise the pipeline would fail.</p>

<p><img src="/assets/images/2020-01-26-upload-library-to-s3/Step4.png" alt="Step4 Image" /></p>

<p>After reviewing the whole pipeline, continuing would trigger the pipeline and upload your artifacts to S3. You need to configure the S3 bucket policy to keep it public/private depending on the use case.</p>

<p><img src="/assets/images/2020-01-26-upload-library-to-s3/Step4-final.png" alt="Step4-final Image" /></p>

<h4 id="using-the-newly-published-artifacts">Using the newly published artifacts</h4>
<p>Add this to the project level build.gradle —</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://codebuildtest-bucket.s3.us-east-2.amazonaws.com"
        }
    }
</code></pre></div></div>

<p>And to the module build.gradle use it like any other dependancy —</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>implementation 'codebuildtestproject:liba:1.0.0'
</code></pre></div></div>

<p>Hope this helps.</p>

<p>Thanks 😊</p>]]></content><author><name>Aditya Vikram Sinha</name></author><summary type="html"><![CDATA[Let’s say I am building an android library and want to host it somewhere but not on Maven Central, JCenter etc. So I decided that I will host it on a S3 bucket and somehow automate the process of getting it there, and then pull artifacts from the bucket in other projects.]]></summary></entry></feed>