How To Deploy With GitLab CI/CD?

How To Deploy With GitLab CI/CD?

Dear Friend,

Last two weeks, we have been building the pipeline for the build and test stages. This week we will be deploying the artefact to a server.

If you haven't read previous articles on CI CD, you can check them here

Pre-requisite

Stage 1: Build a pipeline with .gitlab-ci.yml

As we have discussed the build and test previously, let's jump to the deployment stage.

The important part we need to focus on is ${HEROKU_PRODUCTION_KEY}

Two essential things here.

  • Heroku is a different vendor that provides servers to deploy apps and artefacts. Suitable for personal projects.
  • We have to create a Heroku Account. And configure the app name and key on GitLab to establish connectivity.

We can discuss the steps in Stage 2

image: maven:lates

stages:
  - build
  - test
  - deploy

build_job:
    stage: build
    script:
        - mvn verify -DskipTests=true
    artifacts:
        paths:
            - target/*.jar

test_job:
    stage: test
    script:
        - mvn clean test

deploy_job:
  stage: deploy
  when: manual
  script:
    - HEROKU_API_KEY=${HEROKU_PRODUCTION_KEY} mvn heroku:deploy        

Stage 2: Prepare the target deployment server.

Once you sign-up with Heroku, navigate to New --> Create new app

No alt text provided for this image

Key in the App name and choose preferred region then click Create app

No alt text provided for this image

Navigate to your profile and click Account settings

No alt text provided for this image

Scroll down until you see field named API Key

No alt text provided for this image

Click on Reveal button and copy the key.

Now, the actions are complete at Heroku end. We need to copy the API Key & app name to GitLab to establish connectivity.

Now, navigate to Settings ( at left pane ) --> CI/CD --> Variables --> click Expand button

No alt text provided for this image

Click Add variable and add Keys as below

Key HEROKU_APP_NAME Value - Copy from Heroku ( The name you provided in the previous step)

Key HEROKU_PRODUCTION_KEY Value - The Key copied in the earlier step

We are using this key in .gitlab-ci.yml

All done to kick start the build

Now, you can either change a file or trigger the pipeline by navigating to CI/CD --> Pipelines --> Run pipeline

No alt text provided for this image

As you see above the pipeline's build, test and deploy stages are passing. Now let's verify if the artefact deployed at Heroku.

To verify, navigate to your app at Heroku, you can see the activities log.

No alt text provided for this image

TL;DR

  • Heroku can be used for artefact deployment
  • You can use Heroku for personal projects
  • Gitlab projects cane be configured and connected with Heroku

What's Next Step ?

What we have seen here is the simplest form of deployment. And we scratched the surface. Real-time apps are complex and need a sophisticated configuration.

Docker, Kubernetes and Terraform are powering the production-grade apps.

We will discuss them in the coming weeks.

要查看或添加评论,请登录

Rajesh Muthusamy的更多文章

  • Terraform in 6 Weeks - Week 2: Build a Scalable Static Website

    Terraform in 6 Weeks - Week 2: Build a Scalable Static Website

    Dear friend, The week 2 objective is to create a scalable and highly available static website hosted on S3, served…

    2 条评论
  • Terraform in 6 Weeks - Week 1: Architectural view

    Terraform in 6 Weeks - Week 1: Architectural view

    Dear Friend, In Week 0, we covered the basics of Terraform to get you started. Now, let’s dive deeper into Terraform’s…

    2 条评论
  • Terraform in 6 Weeks - Week 0: Laying the Foundation

    Terraform in 6 Weeks - Week 0: Laying the Foundation

    Dear Friend, Terraform is the gold standard in Infrastructure as Code (IaC), and mastering it is a skill that will stay…

    8 条评论
  • Understanding the OSI Model

    Understanding the OSI Model

    Dear Friend, The Open Systems Interconnection (OSI) model is a fundamental conceptual framework that illustrates how…

    2 条评论
  • Understanding Linux File Permissions

    Understanding Linux File Permissions

    Dear Friend, Linux file permissions are a fundamental aspect of the operating system's security model, determining who…

  • Kubernetes Networking

    Kubernetes Networking

    Dear Friend, In the world of kubernetes, we have different levels of networking requirements. Container-to-container…

    1 条评论
  • How To Design A Container-Based Application?

    How To Design A Container-Based Application?

    Dear Friend, Container is an important moving part of microservices architecture. You will need to place your…

  • The Journey Of A Code To Pod

    The Journey Of A Code To Pod

    Dear Friend, The journey of code towards Pod has multiple stages, and would feel overwhelming to dig the path. But…

    2 条评论
  • How Pods Connect Over Network?

    How Pods Connect Over Network?

    Dear Friend, Kubernetes allows unrestricted communication between pods by default. All pods can communicate with each…

    5 条评论
  • What The Helm?

    What The Helm?

    Dear Friend, In the Kubernetes world, there's no shortage of buzzwords. One among them is Helm.

    1 条评论

社区洞察

其他会员也浏览了