본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

예제 Python 파이프라인

원문 보기 위키 갱신

예제 Python 파이프라인 (Kubernetes)

Python 프로젝트를 위한 지속적 통합(CI) 파이프라인 설정 방법을 다루는 가이드예요. Drone이 처음이라면 먼저 튜토리얼과 빌드 설정 가이드를 읽어 보세요.

출처: Drone CI Docs

본문

빌드와 테스트 (Build and Test)

아래 예제는 pip install과 pytest 명령을 실행하는 파이프라인을 보여줍니다. 이 명령들은 Docker 컨테이너 안에서 실행되며, 컨테이너는 실행 시점에 DockerHub에서 내려받아요.

kind: pipeline
type: kubernetes
name: default

steps:
- name: test
  image: python
  commands:
  - pip install -r requirements.txt
  - pytest

파이프라인에서는 어떤 Docker 레지스트리의 어떤 Docker 이미지든 사용할 수 있다는 점에 유의하세요. 공식 python 이미지를 쓸 수도 있고, 직접 만든 이미지를 가져올 수도 있습니다.

여러 버전 테스트 (Test Multiple Versions)

Drone의 멀티 파이프라인 기능을 사용하면 여러 Python 버전에 대해 동시에 테스트할 수 있어요. 다른 지속적 통합 시스템의 매트릭스(matrix) 기능과 동일한 역할을 합니다.

---
kind: pipeline
type: kubernetes
name: python-2

steps:
- name: test
  image: python:2
  commands:
  - pip install -r requirements.txt
  - pytest

---
kind: pipeline
type: kubernetes
name: python-3-3

steps:
- name: test
  image: python:3.3
  commands:
  - pip install -r requirements.txt
  - pytest

---
kind: pipeline
type: kubernetes
name: python-3-4

steps:
- name: test
  image: python:3.4
  commands:
  - pip install -r requirements.txt
  - pytest
...

이 문법이 너무 장황하다고 느껴진다면 jsonnet 사용을 추천합니다. jsonnet이 익숙하지 않다면 가이드를 읽어 보세요.

local Pipeline(name, image) = {
  kind: "pipeline",
  type: "kubernetes",
  name: name,
  steps: [
    {
      name: "test",
      image: image,
      commands: [
        "pip install -r requirements.txt",
        "pytest"
      ]
    }
  ]
};

[
  Pipeline("python-2", "python:2"),
  Pipeline("python-3-3", "python:3.3"),
  Pipeline("python-3-4", "python:3.4"),
  Pipeline("python-3-5", "python:3.5"),
  Pipeline("python-3-6", "python:3.6"),
]

여러 아키텍처 테스트 (Test Multiple Architectures)

Drone의 멀티 파이프라인 기능을 사용하면 여러 아키텍처와 운영체제에서 코드를 동시에 테스트할 수 있어요.

---
kind: pipeline
type: kubernetes
name: test-on-amd64

platform:
  arch: amd64

steps:
- name: test
  image: python
  commands:
  - pip install -r requirements.txt
  - pytest

---
kind: pipeline
type: kubernetes
name: test-on-arm64

platform:
  arch: arm64

steps:
- name: test
  image: python
  commands:
  - pip install -r requirements.txt
  - pytest

...

이 문법이 너무 장황하다고 느껴진다면 jsonnet 사용을 추천합니다. jsonnet이 익숙하지 않다면 가이드를 읽어 보세요.

더 알아보기 (Learn more)