jineecode

CI/CD ! Github Actions 본문

git

CI/CD ! Github Actions

지니코딩 2022. 9. 5. 16:33

1. CI? 

Continous Integration은 코드를 지속적으로 통합해나가는 것.

코드의 통합은 단순히 코드와 코드를 합치는 것뿐만이 아니라 코드를 테스트하고 유효한지 검사하는 확인.

 

2. CD?

Continuous Deployment는 CI 과정을 통해서 성공적으로 통합된 코드들을 실제 사용자가 사용하고 있는 Production 환경에 배포하는 것

 

3. 설치형 / 클라우드형

설치형: Jenkins

클라우드형: Github Actions

 

4. Github Actions 구성요소

name: CI/CD
on:
  push:
    branches:
      - master
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./docs
  1. name
    • Workflow의 이름
  2. on (event)
    • 여기에 기술된 이벤트에 의해 workflow가 작동한다. 특정 동작일 수 있고, schedule이 될 수도 있다. 위 코드로 예를 들자면, master 브랜치에서 push가 발생할 때 이 workflow가 실행된다.
    • 다른 이벤트 참조 
  3. jobs
    • workflow에서 실행할 작업의 단위. jobs 아래로 build, deploy 등이 들어올 수 있다.
    • name: job의 이름. 생략 가능하다.
    • runs-on: 해당 job을 실행할 가상 환경으로 ubuntu, linux, macOs 로 설정할 수 있다.
    • steps:  Job이 실행되는 하나의 가상 환경에서 이루어질 일련의 작업. job이 추상적이라면, step은 조금 더 실질적이다. command나 action을 실행할 수 있다.
      • name, run
        • name: 생략 가능하며 name은 알아서 정해진다.
        • run: command 를 실행한다. command는 여러줄로 생성 가능하다.
      • env
      • uses
        • Action을 사용한다는 뜻. action을 다른 저장소에서 가져와 사용하거나 workflow 파일이 존재하는 동일한 저장소에 만들어서 사용할 수 있다. GitHub Marketplace에서 Action들을 검색하고 활용한다.
        • actions/checkout@v2 : workflow를 실행하는 저장소의 최신 내역을 받아온다. 
        • with: Action에게 넘겨주는 파라미터. 

5. 실전! Github Actions 써보기 (ex. gh-pages)

  1. 파일 생성
    • .github/workflows/'파일이름'.yml
  2.  깃허브 마켓플레이스를 참조하여 yml을 꾸며보자
name: Build and Deploy
on: [push]
permissions:
  contents: write
jobs:
  build-and-deploy:
    concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
    runs-on: ubuntu-latest
    steps:
      - name: Checkout 🛎️
        uses: actions/checkout@v3

      - name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
        run: |
          npm ci
          npm run build

      - name: Deploy 🚀
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: build # The folder the action should deploy.

 

 

참조

https://ohseunghyeon.github.io/blogging/deploying-github-pages-with-github-actions/

 

Github pages를 github actions로 자동 배포하기

Github blog를 Github에서 제공하는 github actions로 배포하기

ohseunghyeon.github.io

https://velog.io/@adam2/Github-Action-%EC%A3%BC%EC%9A%94-%EB%AC%B8%EB%B2%95

 

▶ Github Action 주요 문법 배우기

이번 글에서는 본격적으로 workflow를 작성하기 위한 기본적인 문법들을 학습하는 시간을 가져보도록 하겠습니다. github 사용이 익숙하다면(PR, Push, review, issue 등등..) 이해가 더 쉬울 거라고 생각

velog.io

 

Comments