CI/CD pipeline to deploy angular on AWS with Gitlab Runner.

Posted on November 30, 2021 at 05:26 AM

What are CI and CD

What are CI and CD?

Continuous Integration (CI) is a development practice of merging all code developed by developers into a shared repository. Each integration is then verified by an automated build, allowing teams to detect problems quickly and resolve them in a very efficient way.

Continuous Delivery helps to deploy our app/software at any time, generally done when we push our code to the staging environment.

Continuous Deployment deploys code to the production environment, often done when we merge our code to the main branch.

Gitlab provides a nice way to support CI Integration and to utilize that we need to create a .gitlab-ci.yml file in our project directory.

Now, If you commit to your master branch with .gitlab-ci.yml and files in the root directory of your project then the CI/CD pipeline will initiate the set of instructions that we described below.

CI/CD using GitLab

CICD-using-GitLab

# Node Image for docker on which code will execute

image: node:latest

stages:

– build

deploy_master:

stage: deploy

before_script:

– npm install

– npm run build — –prod

– ‘which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )’

– eval $(ssh-agent -s)

– mkdir -p ~/.ssh

– chmod 700 ~/.ssh

– chmod 400 $PRIVATE_KEY_STAGING

– echo -e “Host *\n\tStrictHostKeyChecking no\n\n” > ~/.ssh/config

– apt-get update -y

– apt-get -y install rsync

script:

– ssh -i PRIVATE_KEY SERVER_NAME@SERVER_IP

– rsync -zvhr -auv -e “ssh -i PRIVATE_KEY dist/ ubuntu@SERVER_IP:/

only: [‘master’]

 

Facebook Comments

Related Posts

Start a Project

We could talk tech all day. But we’d like to do things too,
like everything we’ve been promising out here.