Go 파이프라인 예시 — Kubernetes
이 가이드는 Go Modules를 사용하는 Go 프로젝트를 위한 지속적 통합(CI) 파이프라인 설정 방법을 다뤄요. Drone이 처음이라면 먼저 튜토리얼과 빌드 설정 가이드를 읽어 주세요.
출처: Drone CI Docs
본문
빌드와 테스트 (Build and Test)
아래 예시는 go test와 go build 명령을 실행하는 파이프라인을 보여줘요. 이 명령들은 golang Docker 컨테이너 안에서 실행되고, 컨테이너는 실행 시점에 DockerHub에서 내려받아요.
kind: pipeline
type: kubernetes
name: default
steps:
- name: test
image: golang
commands:
- go test
- go build
어떤 Docker 레지스트리의 이미지든 파이프라인에서 사용할 수 있다는 점에 유의하세요. 공식 golang 이미지를 쓸 수도 있고, 직접 만든 이미지를 쓸 수도 있어요.
의존성 (Dependencies)
파이프라인을 여러 스텝으로 나누기로 했다면 각 스텝이 프로젝트 의존성에 접근할 수 있도록 해야 해요. 의존성은 공유 워크스페이스 밖에 있는 /go에 내려받아져요. 네임드 볼륨을 만들어 이 디렉터리를 모든 파이프라인 스텝과 공유하세요:
kind: pipeline
type: kubernetes
name: default
steps:
- name: test
image: golang
volumes:
- name: deps
path: /go
commands:
- go test
- name: build
image: golang
volumes:
- name: deps
path: /go
commands:
- go build
volumes:
- name: deps
temp: {}
여러 버전 테스트 (Test Multiple Versions)
Drone의 멀티 파이프라인 기능을 사용해 여러 버전의 Go에 대해 동시에 테스트할 수 있어요. 다른 지속적 통합 시스템의 matrix 기능과 같은 역할을 해요.
---
kind: pipeline
type: kubernetes
name: go-1-11
steps:
- name: test
image: golang:1.11
commands:
- go get
- go test
---
kind: pipeline
type: kubernetes
name: go-1-10
steps:
- name: test
image: golang:1.10
commands:
- go get
- go test
...
이 문법이 너무 장황하다고 느껴지면 jsonnet 사용을 추천해요. jsonnet이 낯설다면 우리의 가이드를 읽어 주세요.
local Pipeline(name, image) = {
kind: "pipeline",
type: "kubernetes",
name: name,
steps: [
{
name: "test",
image: image,
commands: [
"go get",
"go test"
]
}
]
};
[
Pipeline("go-1-11", "golang:1.11"),
Pipeline("go-1-12", "golang:1.12"),
]
여러 아키텍처 테스트 (Test Multiple Architectures)
Drone의 멀티 파이프라인 기능을 사용해 여러 아키텍처와 운영체제에서 코드를 동시에 테스트할 수 있어요.
---
kind: pipeline
type: kubernetes
name: test-on-amd64
platform:
arch: amd64
steps:
- name: test
image: golang
commands:
- go get
- go test
---
kind: pipeline
type: kubernetes
name: test-on-arm64
platform:
arch: arm64
steps:
- name: test
image: golang
commands:
- go get
- go test
...
이 문법이 너무 장황하다고 느껴지면 jsonnet 사용을 추천해요. jsonnet이 낯설다면 우리의 가이드를 읽어 주세요.