SpringBoot x Concourseでビルド

2018/01/04

SpringBoot x Concourseでビルド

Spring BootのアプリケーションをConcourseでビルドする。

シンプルなパイプラインを作成

今回の検証では、2つのジョブを実装してみる。

  1. Pull RequestでUnitテストを実行するジョブ(Continuous Integration)
  2. アプリケーションの成果物をDocker RegistryへPushするジョブ

pipeline.ymlの実装

resources

引用
Concourse Resource

リソースは、他のソフトウェアやプラットフォーム(GitHubやSlack等)との連携を定義できる。
連携するときの認証で使う鍵も決まった記法で定義できる。

resource_types

引用
Concourse Resource type

Concourse側で提供している以外のリソースを定義したい場合、Concourseで利用するためのリソースを他のプラットフォームが提供している以外のリソースを定義したい場合に利用するカスタムリソースのようなイメージ。

jobs

引用
Concourse job

ジョブは複数定義する。
1つのパイプラインをどのように何を実行していくのかを定義する。
ジョブの最も重要な属性は、プランとして構成されたビルドプラン。
ビルドプランで、実行ステップのシーケンスが決まる。

今回のパイプラインを作成

画像の構成にあるパイプラインを作成してみる。
((値))は、ローカルに設置したcredentialsのファイルを参照される。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
resources:
- name: repository
type: git
source:
branch: master
uri: git@github.com:moff-bear/springboot-bestpractice.git
private_key: ((github-deploy-key))

- name: pull-request
type: pull-request
source:
uri: git@github.com:moff-bear/springboot-bestpractice.git
repo: moff-bear/springboot-bestpractice
access_token: ((github-access-token))
private_key: ((github-deploy-key))
base: master

- name: springboot-bestpractice-image
type: docker-image
source:
repository: ((docker-hub-account))/springboot-bestpractice
username: ((docker-hub-user))
password: ((docker-hub-pass))

resource_types:
- name: pull-request
type: docker-image
source:
repository: jtarchie/pr

- name: slack-notification
type: docker-image
source:
repository: cfcommunity/slack-notification-resource
tag: latest

jobs:
- name: unit-test
serial: true
public: true
plan:
- get: repository
resource: pull-request
trigger: true
version: every
- do:
- put: pull-request
params:
path: repository
status: pending
- task: unit-test
file: repository/concourse/unit-test.yml
on_success:
put: pull-request
params:
path: repository
status: success
on_failure:
put: pull-request
params:
path: repository
status: failure

- name: deploy-image
serial: true
public: true
plan:
- get: repository
trigger: true
- do:
- task: unit-test
file: repository/concourse/unit-test.yml
- task: deploy-image
file: repository/concourse/deploy-image.yml
- put: springboot-bestpractice-image
params:
tag: out/version.txt
build: repository

パイプラインの説明

パイプラインの反映は以下のコマンドとなる。

1
$ fly -t {target} set-pipeline -p {pipeline name} -c {pipeline.yml path} -l {credential.yml}

(()) の値は?

Concourseがデフォルトで定義しているcredential情報の展開機能。

credential.yml。ローカルに設置される。

1
2
3
4
5
github-access-token: ******
github-deploy-key: ******
docker-hub-account: ******
docker-hub-user: ******
docker-hub-pass: ******

resources

name description
repository GitHubのリポジトリ
pull-request GitHubのPull Request。jtarchie/prが提供しているのリソースタイプを利用
springboot-bestpractice-image Docker Registryのパス

resource_types

name description
pull-request jtarchie/prが提供しているDocker Image
slack-notification cfcommunity/slack-notification-resourceが提供しているDocker Image

jobs

name description
unit-test Spring BootのアプリケーションのUnitテストを実行する。テストに失敗した場合は、GitHubのステータスをfalsemにする
deploy-image Spring BootのアプリケーションのBuild、Docker Build、Docker Push、Slackへの成功可否通知を行う