IT

CI/CD 파이프라인 구축은 어떻게 해요? (feat. Jenkins, CircleCI, GitHub Actions)

jaewon_sss 2024. 7. 18. 17:07
반응형

Jenkins

1. Jenkins 소개

  • 설명: 오픈 소스 자동화 서버로, 빌드, 테스트, 배포 자동화를 지원합니다.

2. Jenkins 설치

  • 설명: Jenkins를 설치하고 설정하는 과정.
# Ubuntu에서 Jenkins 설치
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins

 

 

3. Jenkins 파이프라인 설정

  • 설명: Jenkinsfile을 사용한 파이프라인 정의.
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh 'make'
            }
        }
        stage('Test') {
            steps {
                sh 'make test'
            }
        }
        stage('Deploy') {
            steps {
                sh 'make deploy'
            }
        }
    }
}

 

 

 

 

 

CircleCI

1. CircleCI 소개

  • 설명: 클라우드 기반 CI/CD 서비스로, 쉽게 설정하고 관리할 수 있습니다.

2. CircleCI 설정 파일

  • 설명: .circleci/config.yml 파일을 사용한 설정.
version: 2.1
jobs:
  build:
    docker:
      - image: circleci/python:3.7
    steps:
      - checkout
      - run:
          name: Install dependencies
          command: |
            python -m venv venv
            . venv/bin/activate
            pip install -r requirements.txt
      - run:
          name: Run tests
          command: |
            . venv/bin/activate
            pytest

3. 워크플로우 설정

  • 설명: 빌드, 테스트, 배포 작업을 워크플로우로 정의.
workflows:
  version: 2
  build_and_test:
    jobs:
      - build

 

 

 

 

GitHub Actions

1. GitHub Actions 소개

  • 설명: GitHub에서 제공하는 CI/CD 서비스로, 리포지토리 내에서 워크플로우를 정의하고 실행할 수 있습니다.

2. GitHub Actions 워크플로우 파일

  • 설명: .github/workflows/ 디렉토리에 워크플로우 파일 생성.
name: CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.7
      - name: Install dependencies
        run: |
          python -m venv venv
          . venv/bin/activate
          pip install -r requirements.txt
      - name: Run tests
        run: |
          . venv/bin/activate
          pytest

3. 배포 작업 설정

  • 설명: 배포 작업을 추가하여 CI/CD 파이프라인 완성.
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.7
      - name: Install dependencies
        run: |
          python -m venv venv
          . venv/bin/activate
          pip install -r requirements.txt
      - name: Run tests
        run: |
          . venv/bin/activate
          pytest
      - name: Deploy to Heroku
        run: |
          git push heroku main
        env:
          HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
반응형