How to setup ci cd pipeline in aws for apk build of a react‐native project? - arnabutilities/rbac-frontend GitHub Wiki

Setting up a CI/CD pipeline in AWS for building the APK of a React Native project involves several steps. Here’s a detailed guide to help you set it up using AWS services such as CodeCommit, CodeBuild, and CodePipeline:

Prerequisites

  1. AWS Account: Ensure you have an AWS account.
  2. React Native Project: Ensure your React Native project is properly set up.
  3. AWS CLI: Install and configure the AWS CLI on your local machine.

Steps to Setup CI/CD Pipeline

1. Store Code in AWS CodeCommit

  1. Create a CodeCommit Repository:

    • Go to the CodeCommit console in AWS Management Console.
    • Click on "Create repository" and follow the prompts to create a new repository.
  2. Push Your React Native Project to CodeCommit:

    • Clone the CodeCommit repository to your local machine.
    • Push your existing React Native project to this repository.

2. Create Buildspec File

Create a buildspec.yml file in the root directory of your React Native project. This file tells AWS CodeBuild how to build your project. Below is an example buildspec.yml for building a React Native APK:

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 14
  pre_build:
    commands:
      - npm install
  build:
    commands:
      - cd android
      - ./gradlew assembleRelease
artifacts:
  files:
    - android/app/build/outputs/apk/release/app-release.apk
  discard-paths: yes

3. Setup AWS CodeBuild

  1. Create a CodeBuild Project:
    • Go to the CodeBuild console.
    • Click "Create build project".
    • Configure the following settings:
      • Project Name: Choose a name for your project.
      • Source Provider: Select "AWS CodeCommit" and choose your repository.
      • Environment: Select "Managed image" and choose an appropriate image (e.g., Ubuntu with Node.js).
      • Buildspec: Choose "Use a buildspec file".
    • Click "Create build project".

4. Setup AWS CodePipeline

  1. Create a Pipeline:
    • Go to the CodePipeline console.
    • Click "Create pipeline".
    • Configure the following settings:
      • Pipeline Name: Choose a name for your pipeline.
      • Service Role: Choose an existing service role or create a new one.
      • Source Stage: Select "AWS CodeCommit" and choose your repository and branch.
      • Build Stage: Select "AWS CodeBuild" and choose the project you created earlier.
      • Deploy Stage: (Optional) If you want to deploy the APK somewhere, you can add deployment steps here.
    • Click "Create pipeline".

5. Triggering the Pipeline

Every time you push a change to the CodeCommit repository, the pipeline will trigger automatically. CodePipeline will use CodeBuild to build the APK and store it as an artifact.

Additional Considerations

  • Secrets Management: Use AWS Secrets Manager or SSM Parameter Store to manage sensitive information like API keys, if required.
  • Notifications: Set up Amazon SNS or AWS CloudWatch for notifications on build status.
  • Scaling: For larger teams or projects, consider using AWS CodeArtifact for managing dependencies.

This setup provides a robust CI/CD pipeline for building React Native APKs on AWS. You can further customize the buildspec, add tests, and enhance the pipeline as needed.