Notification
새로운 알림이 없습니다.
Trending Searches (last 7 days)

[CI/CD] GCP VM Deploy Guide with Jenkins CI/CD(1)

GCP VM Deploy Guide with Jenkins CI/CD

  • Introduction
    • Overview of the Article
    • What is Jenkins?
      • Jenkins Pros/Disadvantages
  • Prerequisites
    • GCP Account and Project Setting 
    • Installing and Configuring Jenkins & Plugins
  • Jenkins Project Setup
    • GCP Service Account and Authentication
  • Next Actions
    • New Project in Jenkins
    • Integrating with the source Code Repository
    • Teams Webhook with Jenkins Configuration
    • Jenkins Pipeline Script 

Introduction

GCP에서 VM Deploy에 대한 방법은 다양합니다.
(*Cloud Build, Deployment Manager....) 
위와 같은 방법이 있으나, 이전 글에도 설명드린것과 같은 이유로 Jenkins를 선택하게 되었으며 목차에 따라 Jenkins 소개부터 글을 시작하도록 하겠습니다. 

What is Jenkins? 

    출처: https://www.jenkins.io/images/logos/brno/brno.png

Jenkins는 오픈 소스 CI/CD 도구로, 소프트웨어 개발 프로세스를 자동화하고 지속적으로 통합 및 배포하는 데 사용됩니다.

Jenkins는 다양한 플러그인을 지원하여 다양한 개발 환경과 통합할 수 있으며, 유연한 구성 옵션을 제공하여 사용자 정의 CI/CD 파이프라인을 구축할 수 있습니다. 

아래는 Jenkins 사용시 얻을수 있는 이점과, 단점에 대해서 간략하게 설명 드리겠습니다. 
  • Jenkins Pros/Disadvantages
    • Jenkins 사용시 얻을수 있는 이점
      • 빌드, 테스트, 배포 등의 작업을 자동화하여 생산성 향상
      • 다양한 플러그인으로 다른 도구와 통합 가능
      • 무료로 사용이 가능한 Tool Chain 
    • Jenkins 단점
      • 초기 구성에 대한 복잡성
      • Jenkins서버 및 Pipeline의 유지보수 필요
      • 보안 설정과 취약성 점검 관련 유지보수 필요

Prerequisites 

Jenkins로 Pipeline을 구성하기 이전에 간략하게 사전 준비사항에 대해서 정리하였습니다.

우선, Cloud에 있는 서버를 사용할 것이기 때문에 3사 CSP(AWS,Azure,GCP)중 GCP의 Project 설정 및 GCE(Google Compute Engine)이 사용하는 Service Account 계정에 권한 부여가 필요합니다. 
해당 내용은 하기 이미지 및 설명을 참고하시면 될 것 같습니다.  

GCP Account and Project Setting
  • GCP Project
    • GCP Console(console.cloud.google.com)을 접근하게되면, 위와 같이 프로젝트 페이지를 확인하실수 있습니다.
    • 위에서 설명한 Service Account를 선택하기 위해 IAM & Admin Tab 접근이 필요합니다.
  • GCP IAM & Admin
    • VM 생성등을 위해 Compute Instance Admin 권한을 부여한 것을 확인하실수 있습니다.
    • 해당 Project의 경우, 필자가 생성한 프로젝트이기에 필자의 구글 계정엔 Owner 권한이 할당이 사전에 되어있음을 참고 부탁드립니다.
  • Jenkins용 GCP VM 생성


    • GCP에서 Compute Engine 배포를 위해 Compute Engine Tab에 접근 후 Machine Type등 VM 생성을 위한 옵션들을 선택 후 VM을 생성해주시면 됩니다. 
    • 해당 가이드를 위해 생성한 VM의 Machine Type은 e2-standard-4로 설정하였고, Service Account는 이전 단락에 생성한 SA로 설정하였습니다. 
      • 해당 내용은 GCP Docs를 참고하실것을 권고 드립니다.
  • VM 생성 후 Jenkins 배포
    • 필자의 경우, Docker 설치 이후 GCE에 Docker로 Jenkins Container를 띄워서 Jenkins를 배포하였습니다. Docker 설치 및 Jenkins Container 배포에 대해서는 아래 Bash Script 참고 부탁드립니다.
      # Add Docker's official GPG key:
      sudo apt-get update -y
      sudo apt-get install ca-certificates curl gnupg -y
      sudo install -m 0755 -d /etc/apt/keyrings
      curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
      sudo chmod a+r /etc/apt/keyrings/docker.gpg

      # Add the repository to Apt sources:
      echo \
      "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
      "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
      sudo tee /etc/apt/sources.list.d/docker.list > /dev/null    sudo apt-get update -y
      sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
      docker pull jenkins/jenkins #TZ(TimeZone Seoul로 설정) docker run -d --name jenkins --restart=on-failure -p 8080:8080 -p 50000:50000 -v /var/jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -e TZ=Asia/Seoul -u root jenkins/jenkins
    • 위 Script를 통해 Docker Container를 배포하게 되면 아래와 같이 Container가 떠있는것을 확인할 수 있습니다.
    • Container 배포 이후 아래와 같이 Jenkins WEB UI 접근을 확인할 수 있었습니다.
    • Jenkins Plugin의 경우, Default로 설치가 필요한 Plugin들은 다 설치하였으며, 추가로 설치해준 내역은 아래와 같습니다.
      • GitHub
      • Git Plugin
      • Google OAuth Credentials
      • Google Compute Engine
      • Google Cloud Storage
      • Office 365 Connector(Teams Webhook 용도) 

Next Actions

Jenkins 설치가 완료되었으니, GCP에서 간단하게 Host 정보를 확인할수 있는 App Service를 배포하고, Jenkins를 통한 Pipeline Script에 대한 설명을 진행하고자 합니다.

끝으로 이 포스팅을 보시는 분들이 관련 정보를 얻으시는데 도움이 되었으면 합니다. 
CI/CD
Stan Cloud
Stan Cloud
An avid cloud engineering Fan
대화 참여하기
댓글 쓰기