Docker & K8S

Docker & K8S - Github Actions 소개

터칭 데이터 2023. 12. 19. 21:31

 

학습 목표

 

CI/CD의 개념과 가장 많이 사용되는 소스 컨트롤 시스템

 

Git과 Github에 대해 알아보고 Github이 제공하는 CI/CD 서비스인

 

Github Actions에 대해 알아보려 합니다.

 

 

이렇게 배운 개념들을 바탕으로

1. Github Actions로 Hangman 코드에 테스트를 붙이는 실습

 

2. Github Actions를 통해 Docker Image를 만들고 Docker hub에 push하는 실습

 

2개의 실습을 하려합니다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Push나 Merge 시점이 CI/CD를 실행하기 위한 절호의 순간

 

코드가 메인/마스터나 브랜치에 추가되는 순간 CI/CD를 트리거

이를 특정 메인/마스터나 특정 브랜치만 대상으로 하도록 설정 가능
이 때 테스트 수행하고 최종적으로 Docker Image등을 만들도록 하는 것이 가능
그래서 CI/CD는 Github에 구현하는 것이 가장 자연스러움

 

Github에서는 이를 Actions라는 기능을 통해 Workflow라는 이름으로 구현 가능

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Github Actions이란?

 

CI/CD를 Github위에서 구현하기 위한 서비스

코드 테스트, 빌드, 배포 자동화 기능 제공

 

Workflow라 부르며 아래 컴포넌트로 구성

Events
Jobs
Actions
Runner
    - Github hosted runners
    - Self hosted runners

Runner 요금제

 

 

 

In the context of GitHub Actions, here's what each term means:

1. Events: An event is a specific activity that triggers a workflow run. Events can originate from GitHub when someone pushes a commit, opens a pull request, creates an issue, etc. You can also schedule events using the schedule event.

2. Jobs: A job is a set of steps that execute on the same runner. You can define dependencies between jobs and run jobs concurrently or sequentially depending on the status of a previous job.

3. Actions: An action is the smallest portable building block of a workflow. You can create your own actions, or use and customize actions shared by the GitHub community. Actions are individual tasks that you can combine to create jobs and customize your workflow.

4. Runner: A runner is a server that has the GitHub Actions runner application installed. You can use a runner hosted by GitHub, or host your own. A runner listens for available jobs, runs one job at a time, and reports the progress, logs, and results back to GitHub.

In a typical GitHub Actions workflow, an event triggers the workflow, which contains one or more jobs. Each job runs on a runner and contains a sequence of tasks called steps. Steps can run commands or actions. When the jobs complete, the workflow can trigger other events, which can in turn trigger other workflows, creating a complex chain of automated processes.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Github Actions - Workflow (1)

 

Workflow는 트리거 이벤트(Events)가 발생하면 시작되는 일련의 동작(Jobs)들을 지칭

 

트리거 이벤트의 예들은?

코드 커밋 (main과 같은 특정 브랜치를 대상으로만 제한 가능)
PR 생성
다른 Workflow의 성공적인 실행 (다수의 Workflow 체이닝으로 연쇄작동 가능)

 

 

 

 

 

 

 

 

 

Github Actions - Workflow (2)

 

Workflow를 위한 명령어들은 YAML 파일로 저장

명령어들로는 환경설정과 scripts 실행들이 대표적

예를 들어 Docker Image를 만들 때 Docker와 관계된 명령과 환경설정을 실행합니다.

 

Workflow는 Job들로 나눠지며 각 Job은 일련의 스텝을 수행

각 스텝은 하나 혹은 그 이상의 명령어를 실행
    - 이 명령어는 actions라고 부르는 명령어들의 집합이 될 수도 있음
각 스텝은 윈도우나 리눅스 서버 위에서 runner에 의해 실행
    - 이걸 Docker Image에서 수행하는 것이 서비스 배포 과정에 따라 더 일반적이기도 함

 

점점 Github Actions와 Docker와 더 많이 연동되고 있습니다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Github에서 어떻게 Github Actions를 선택하는가?

 

 

적용하려는 repo에 보면 Actions 메뉴가 있음

 

다음으로 workflow를 하나 생성

 

yml 파일을 직접 생성 혹은 템플릿(CI Templates) 선택 후 수정

Python Application 혹은 Docker Image