y-ohgi's blog

TODO: ここになにかかく

Hashicorp の新しいCD ツール "Waypoint" を試してみる

TL;DR

  • hashicorp がリリースしたCD ツールの hashicorp/waypoint を試してみる記事
  • サーバーを立ち上げてデプロイx2をしてみた(感動的に楽)
  • 個人的にECS を運用するときはまっさきに検討したいツール

version

  • waypoint
    • v0.1.3

試す

公式のGet Started を参考にためしてみる。
https://learn.hashicorp.com/collections/waypoint/get-started-docker

Install

各種OS に対応している。とりあえず今回はMacを選択。
https://learn.hashicorp.com/tutorials/waypoint/get-started-install?in=waypoint/get-started-docker

brew からサクッと入る

$ brew tap hashicorp/tap
$ brew install hashicorp/tap/waypoint
$ waypoint
Welcome to Waypoint
Docs: https://waypointproject.io
Version: v0.1.3

Usage: waypoint [-version] [-help] [-autocomplete-(un)install] <command> [args]

Common commands
  build        Build a new versioned artifact from source
  deploy       Deploy a pushed artifact
  release      Release a deployment
  up           Perform the build, deploy, and release steps for the app

Other commands
  artifact        Artifact and build management
  config          Application configuration management
  context         Server access configurations
  deployment      Deployment creation and management
  destroy         Delete all the resources created for an app
  docs            Show documentation for components
  exec            Execute a command in the context of a running application instance
  hostname        Application URLs
  init            Initialize and validate a project
  install         Install the Waypoint server to Kubernetes, Nomad, or Docker
  logs            Show log output from the current application deployment
  runner          Runner management
  server          Server management
  token           Authenticate and invite collaborators
  ui              Open the web UI
  version         Prints the version of this Waypoint CLI

FIXME: 立ち上げ

まずはwaypoint サーバー用Docker をpull

$ docker pull hashicorp/waypoint:latest

waypoint サーバーを起動( -accept-tos は規約への同意。CLIだと珍しい?)。

$ waypoint install -platform=docker -accept-tos
 + Installing Waypoint server to docker
 + Server container started!
 + Configuring server...
Waypoint server successfully installed and configured!

The CLI has been configured to connect to the server automatically. This
connection information is saved in the CLI context named "install-1603176863".
Use the "waypoint context" CLI to manage CLI contexts.

The server has been configured to advertise the following address for
entrypoint communications. This must be a reachable address for all your
deployments. If this is incorrect, manually set it using the CLI command
"waypoint server config-set".

Advertise Address: waypoint-server:9701
Web UI Address: https://localhost:9702

出力されたURL へアクセスするとログイン画面が出てきた
f:id:y-ohgi:20201020174732p:plain

画面に表示されてる通りにtoken発行コマンドをしてログイン

$ waypoint token new
bM152PWkXxfoy4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

余談: 永続化の確認

気になったのでどこで永続化してるのか確認。

diff で生成されたものを確認。特に無い。

$ docker diff <CONTAINER ID>
C /home
C /home/waypoint
A /home/waypoint/.config
A /home/waypoint/.config/waypoint
$ docker exec <CONTAINER ID> ls -l /home/waypoint/.config/waypoint
total 0

volume を使ってるかinspect をしてみると、docker volume を使って永続化をしている模様。

$ docker inspect <CONTAINER ID>
        "Mounts": [
            {
                "Type": "volume",
                "Name": "waypoint-server",
                "Source": "/var/lib/docker/volumes/waypoint-server/_data",
                "Destination": "/data",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": ""
            }
        ],

$ docker exec <CONTAINER ID> ls /data
data.db

/data だけっぽい。
EFSだったりCircleCIのキャッシュだったりで管理できるのかな・・・?とりあえず永続化に悩むことはなさそう。楽だ。

デプロイ

公式で用意してくれているexample リポジトリを走らせる

$ git clone https://github.com/hashicorp/waypoint-examples.git
$ cd waypoint-examples/docker/ruby

そのままデプロイコマンドを打つと動いた。

$ waypoint up

» Building...
Creating new buildpack-based image using builder: heroku/buildpacks:18
 + Creating pack client
 + Building image
 │ [exporter] Adding layer 'heroku/ruby:ruby'
 │ [exporter] Adding 1/1 app layer(s)
 │ [exporter] Adding layer 'launcher'
 │ [exporter] Adding layer 'config'
 │ [exporter] Adding label 'io.buildpacks.lifecycle.metadata'
 │ [exporter] Adding label 'io.buildpacks.build.metadata'
 │ [exporter] Adding label 'io.buildpacks.project.metadata'
 │ [exporter] *** Images (bdf20206cb92):
 │ [exporter]       index.docker.io/library/example-ruby:latest
 │ [exporter] Adding cache layer 'heroku/ruby:gems'
 + Injecting entrypoint binary to image

Generated new Docker image: example-ruby:latest

» Deploying...
 + Setting up waypoint network
 + Starting container

» Releasing...

The deploy was successful! A Waypoint deployment URL is shown below. This
can be used internally to check your deployment and is not meant for external
traffic. You can manage this hostname using "waypoint hostname."

           URL: https://visually-literate-hamster.waypoint.run
Deployment URL: https://visually-literate-hamster--v1.waypoint.run

出力されているURL に飛ぶとデプロイされていることを確認できる(Hashicorp がホストしているwaypoint テスト用のPaaS?

f:id:y-ohgi:20201020174813p:plain

ローカルで立てたwaypoint UI からデプロイのログを確認することもできた。 f:id:y-ohgi:20201020174825p:plain

ついでにdive でビルドされたDocker イメージもみてみた。思ってたより軽いしdive の評価もよい(score 99%)。
f:id:y-ohgi:20201020174839p:plain

デプロイ(2回目)

雑にerb を編集。

docker/ruby/app/views/welcome/index.erb
-    <h1>This Ruby on Rails app was deployed with Waypoint.</h1>
+    <h1>This Ruby on Rails app was deployed with Waypoint. v2</h1>

デプロイ(2回目)

$ waypoint up

» Building...
Creating new buildpack-based image using builder: heroku/buildpacks:18
 + Creating pack client
 + Building image
 │ [exporter] Adding layer 'heroku/ruby:ruby'
 │ [exporter] Adding 1/1 app layer(s)
 │ [exporter] Reusing layer 'launcher'
 │ [exporter] Reusing layer 'config'
 │ [exporter] Adding label 'io.buildpacks.lifecycle.metadata'
 │ [exporter] Adding label 'io.buildpacks.build.metadata'
 │ [exporter] Adding label 'io.buildpacks.project.metadata'
 │ [exporter] *** Images (528cbb473237):
 │ [exporter]       index.docker.io/library/example-ruby:latest
 │ [exporter] Reusing cache layer 'heroku/ruby:gems'
 + Injecting entrypoint binary to image

Generated new Docker image: example-ruby:latest

» Deploying...
 + Setting up waypoint network
 + Starting container
 + App deployed as container: example-ruby-01EN2HM2PW3APBQHVKSCH9R8E1

» Releasing...

The deploy was successful! A Waypoint deployment URL is shown below. This
can be used internally to check your deployment and is not meant for external
traffic. You can manage this hostname using "waypoint hostname."

           URL: https://visually-literate-hamster.waypoint.run
Deployment URL: https://visually-literate-hamster--v2.waypoint.run

アクセスして"v2" の文字が追加されてることを確認

f:id:y-ohgi:20201020174904p:plain

お片付け

$ waypoint destroy

 Destroying releases...

 Destroying deployments...

Destroy successful!

destroy してもwaypoint ui の方にはデータが残る模様。

所感

  • デプロイがめっちゃ楽になる!感動!
    • ECS をサクッとCD したいときはまず検討するレベルにはすてき
    • 複数環境もデフォルトで考慮されており、切り替えも楽
      • -workspace オプションを使うだけ
  • キーバリューストアも内蔵しているのもgood
    • $ waypoint config で登録/削除ができる
    • 自動で環境変数に登録してくれる!
  • waypoint サーバー自体の運用も楽そう
    • テキストファイル( data.db )でステートを管理してるので、雑にwaypoint サーバーを建てれて楽
    • ただしユーザー管理機能は"v0.1.3" 時点では無いので、大規模な運用に使うにはまだ早そう
      • token の一覧を見たりdisable したりする方法が見つからなかった。