IK.AM

@making's tech note


BOSHを使ってConcourse CIをAzureにインストール

🗃 {Dev/CI/ConcourseCI}
🏷 BOSH 🏷 Concourse CI 🏷 Azure 
🗓 Updated at 2016-11-12T17:44:36Z  🗓 Created at 2016-04-28T14:22:01Z   🌎 English Page

前記事で、BOSHを使ってAWSにConcourse CIをインストールしましたが、BOSHを使えばIaaS非依存(ただしCloud Provider Interfaceの対応が必要)でインストールが可能になるので、今度はAzureにインストールしてみます。

基本的にはドキュメントの通り。

をみて、

  • TENANTID
  • CLIENTID
  • CLIENTSECRET

を用意してください。

BOSH Directorのインストール

テンプレートが用意されているので簡単です。

https://azure.microsoft.com/en-us/documentation/templates/bosh-setup/ から"Deploy to Azure"をクリック

image

必要な情報を入力。SSHの公開鍵は普段使っているやつでOK。ADMINUSERNAMEadminという名前は使えないので注意してください。

image

"Resource group"は新規作成(ここではboshという名前にしました)。 "Resource group location"はJapan Eastを選択。 "Legal terms"で"Purchase"をクリック。

image

"Create"をクリック。1時間くらい待ちます。

image

bosh/initdevboxが完了すれば準備完了です。

devboxというBOSHクライアントとして使うVMと、devboxからbosh-initで作られたBOSH DirectorのVMができます。Public IP addressを確認してください。

devboxにログインしましょう。VM名はテンプレートで指定した名前になっています(上の例だとbosh)。

image

テンプレートで指定した公開鍵に対応する秘密鍵を使ってSSHでログインします。ユーザー名もテンプレートで指定したものです。

$ ssh bosh@13.78.52.18

BOSH Directorにログイン済みの状態になっています。

bosh@bosh:~$ bosh target
Current target is https://10.0.0.4:25555 (bosh)

これでBOSH Directorのインストールが不要です。

ただし、インストールされているBOSHのバージョンには注意してください。 ホームディレクトリにbosh.ymlがあるので、less ~/bosh.ymlで以下のバージョンをチェックしてください。

---
name: bosh

releases:
- name: bosh
  url: https://bosh.io/d/github.com/cloudfoundry/bosh?v=257.3
  sha1: e4442afcc64123e11f2b33cc2be799a0b59207d0
- name: bosh-azure-cpi
  url: https://bosh.io/d/github.com/cloudfoundry-incubator/bosh-azure-cpi-release?v=17
  sha1: b265730fc26ae8dc07958de61c4b7f8c0187d59a

Azureの情報をBOSH Directorに設定

AWSのときと同様にAzureのインフラ情報をcloud.ymlに設定します。以下のyamlを完全コピーでOKのはずです。

azs:
- name: z1 # dummy
- name: z2 # dummy

vm_types:
- name: web
  cloud_properties:
    instance_type: Standard_D1 # 安くしたい場合はBasic_A1
- name: database
  cloud_properties:
    instance_type: Standard_D1 # 安くしたい場合はBasic_A1
- name: worker
  cloud_properties:
    instance_type: Standard_D1 # 安くしたい場合はBasic_A1
- name: compilation
  cloud_properties:
    instance_type: Standard_D1

disk_types:
- name: database
  disk_size: 50_000

networks:
- name: web
  type: vip
  cloud_properties:
    tcp_endpoints:
    - "80:80"
    - "443:443"
    - "8080:8080"
    - "22:22"
- name: public
  type: manual
  subnets:
  - range: 10.0.16.0/20
    dns: [168.63.129.16]
    gateway: 10.0.16.1
    azs: [z1]
    reserved: [10.0.16.2-10.0.16.10]
    cloud_properties:
      virtual_network_name: boshvnet-crp
      subnet_name: CloudFoundry
- name: private # dummy
  type: manual
  subnets:
  - range: 10.0.16.0/20
    dns: [168.63.129.16]
    gateway: 10.0.16.1
    azs: [z1]
    reserved: [10.0.16.2-10.0.16.10]
    cloud_properties:
      virtual_network_name: boshvnet-crp
      subnet_name: CloudFoundry

compilation:
  workers: 8
  reuse_compilation_vms: true
  az: z1
  vm_type: compilation
  network: public

テンプレートから環境を作るとCloudFoundryという名前のサブネットができています。Cloud Foundryをインストールするわけではありませんが、今回はこのサブネットを使いました。

publicprivateというネットワークの設定を作りましたが、同じ内容です。privateは作る必要がないですが、前記事で作成したConcourse CIのマニフェストファイルをそのまま使うため、ダミーのネットワークとして作りました。

bosh update cloud-configでこのIaaS情報を適用します。

$ bosh update cloud-config cloud.yml

Concourse CIのマニフェストファイル作成

テンプレートから作った場合、

  • bosh-bosh
  • bosh-cf
  • bosh-devbox

というPublic IP addressができています。bosh-devboxはアサイン済みなので、bosh-cfのIPアドレスをConcourse CIのWeb用に使います。 (prefixのboshは多分resource groupに指定したもの。もしくはVM名・・・) 残ったIPアドレスは使わないので捨ててもOKです。

image

concourse.ymlにConcourse CIのマニフェストを定義します。

---
name: concourse

director_uuid: <%= `bosh status --uuid` %>

releases:
- name: concourse
  version: latest
- name: garden-runc
  version: latest

stemcells:
- alias: trusty
  os: ubuntu-trusty
  version: latest

instance_groups:
- name: web
  instances: 1
  vm_type: web
  stemcell: trusty
  azs: [z1]
  networks:
  - name: public
    default: [dns, gateway]
  - name: web
    static_ips: [13.78.58.110] # Should be changed!!
  jobs:
  - name: atc
    release: concourse
    properties:
      # replace with your CI's externally reachable URL, e.g. https://ci.foo.com
      external_url: http://13.78.58.110:8080

      # replace with username/password, or configure GitHub auth
      basic_auth_username: concourse
      basic_auth_password: password

      postgresql_database: &atc_db atc

      # Allow viewing of pipelines as an anonymous user if the job is configured with `public: true`
      publicly_viewable: true
  - name: tsa
    release: concourse
    properties: {}

- name: db
  instances: 1
  vm_type: database
  stemcell: trusty
  persistent_disk_type: database
  azs: [z1]
  networks: [{name: private}]
  jobs:
  - name: postgresql
    release: concourse
    properties:
      databases:
      - name: *atc_db
        # make up a role and password
        role: REPLACE_ME
        password: REPLACE_ME

- name: worker
  instances: 1
  vm_type: worker
  stemcell: trusty
  azs: [z1]
  networks: [{name: private}]
  jobs:
  - name: groundcrew
    release: concourse
    properties: {}
  - name: baggageclaim
    release: concourse
    properties: {}
  - name: garden
    release: garden-runc
    properties:
      garden:
        listen_network: tcp
        listen_address: 0.0.0.0:7777

update:
  canaries: 1
  max_in_flight: 1
  serial: false
  canary_watch_time: 1000-60000
  update_watch_time: 1000-60000

IPアドレス以外は、AWSのときと同じです。

(AWS版を執筆時点ではWebインスタンスへPublic IPアドレスを設定するのをWebから行っていましたが、今回はBOSHから設定しました。AWS版も後で直す)

Concourse CIをデプロイ

まずはベースVMイメージであるStemcellとConcourse CIで必要となるリリースをBOSHにアップロードします。 リリースはhttp://bosh.ioから確認できます。

Stemcellのアップロードは少し時間がかかります。

bosh upload stemcell https://bosh.io/d/stemcells/bosh-azure-hyperv-ubuntu-trusty-go_agent?v=3263.8
bosh upload release http://bosh.io/d/github.com/concourse/concourse?v=2.4.0
bosh upload release http://bosh.io/d/github.com/cloudfoundry/garden-runc-release?v=1.0.2

マニフェストを設定して、デプロイ。

bosh deployment concourse.yml
bosh deploy

完了を待ってください。

完了するとdbwebworker3つのVMができていることがわかります。

$ bosh vms
Acting as user 'admin' on 'bosh'
Deployment `concourse'

Director task 17

Task 17 done

+-------------------------------------------------+---------+----+----------+--------------+
| VM                                              | State   | AZ | VM Type  | IPs          |
+-------------------------------------------------+---------+----+----------+--------------+
| db/0 (0fedc3a7-77d1-4b58-b999-9bfe33142b55)     | running | z1 | database | 10.0.16.14   |
| web/0 (d87cc7b6-839b-455a-814e-41ed1ad75dc0)    | running | z1 | web      | 10.0.16.11   |
|                                                 |         |    |          | 13.78.58.110 |
| worker/0 (a8bc5d86-16c4-4b55-9b4b-d4b6a65359e3) | running | z1 | worker   | 10.0.16.15   |
+-------------------------------------------------+---------+----+----------+--------------+

VMs total: 3

image

ちなみに、

Error 400007: `worker/0 (...)' is not running after update. Review logs for failed jobs: ...

というエラーが出たら、もう一回deployすれば大丈夫になったりします。

最後に、VMにデフォルトで設定されているnsg-boshというセキュリティグループに対して8080番でのアクセスを許可します。

image

(セキュリティグループの設定はマニフェストで明示したほうがいいかも。)

これで完了です。

ブラウザPublic IP addressの8080番にアクセスしてください。

image

flyコマンドでログイン

$ fly -t azr login -c http://13.78.58.110:8080/
username: concourse
password: password
target saved

Hello Worldなパイプラインをセット & アンポーズ

$ fly -t azr sp -p first -c first.yml
$ fly -t azr up -p first

image

ジョブをクリックして、

image

(+)ボタンをクリックしてジョブを実行

image

できた。AWSのVPCとは違って、NATがなくてもVM内部からインターネットアクセスできるようなので、設定が少し楽でした。


AWSのときと同じようにAzureでもConcourse CIをインストールできました。 BOSHのおかげです。

また、いままで作ってきたパイプラインをそのままここで作ったConcourse CI上で即実行できるのがうれしいです。 Concourse CIは本当に良いCI/CDツールだと思います。

次はGCPでも試してみたい。 https://github.com/cloudfoundry-incubator/bosh-google-cpi-release


✒️️ Edit  ⏰ History  🗑 Delete