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

예제 Go 파이프라인

원문 보기 위키 갱신

예제 Go 파이프라인 (GOPATH)

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

출처: Drone CI Docs

본문

빌드와 테스트 (Build and Test)

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

kind: pipeline
name: default

workspace:
  base: /go
  path: src/github.com/octocat/hello-world

steps:
- name: test
  image: golang
  commands:
  - go get
  - go test

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

GOPATH

Go modules를 사용하지 않는다면 코드가 GOPATH 안의 올바른 위치에 클론되도록 기본 프로젝트 워크스페이스를 재정의해야 해요.

kind: pipeline
name: default

workspace:
  base: /go
  path: src/github.com/octocat/hello-world

steps:
- name: test
  image: golang
  commands:
  - go get
  - go test

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

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

---
kind: pipeline
name: go-1-11

steps:
- name: test
  image: golang:1.11
  commands:
  - go get
  - go test

---
kind: pipeline
name: go-1-10

steps:
- name: test
  image: golang:1.10
  commands:
  - go get
  - go test

...

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

local Pipeline(name, image) = {
  kind: "pipeline",
  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
name: test-on-amd64

platform:
  arch: amd64

steps:
- name: test
  image: golang
  commands:
  - go get
  - go test

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

platform:
  arch: arm64

steps:
- name: test
  image: golang
  commands:
  - go get
  - go test

...

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

더 알아보기 (Learn more)