Goパイプラインの例

Updated 2 years ago by Admin

このガイドでは、Goモジュールを使用するGoプロジェクトの継続的インテグレーションパイプラインの構成について説明します。Droneを初めて使用する場合は、最初にチュートリアルとビルド構成ガイドをお読みください。


ビルドとテスト

go testおよびgo buildコマンドを実行するパイプラインを示しています。これらのコマンドは、実行時にDockerHubからダウンロードされたgolang Dockerコンテナ内で実行されます。

kind: pipeline
type: kubernetes
name: default

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

パイプラインでは、任意のDockerレジストリから任意のDockerイメージを使用できることに注意してください。公式のgolang画像を使用することも、自分で持参することもできます。


依存関係

パイプラインを複数のステップに分割する場合は、各ステップがプロジェクトの依存関係にアクセスできることを確認する必要があります。依存関係は、共有ワークスペースの外部/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: {}


複数のバージョンをテストする

Droneのマルチパイプライン機能を使用して、Goの複数のバージョンに対して同時にテストできます。これは、他の継続的インテグレーションシステムに見られるマトリックス機能と同等です。

---
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"),
]


複数のアーキテクチャをテストする

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に慣れていない場合は、ガイドをお読みください。


How did we do?