<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 株式会社ジラフ on Medium]]></title>
        <description><![CDATA[Stories by 株式会社ジラフ on Medium]]></description>
        <link>https://medium.com/@jiraffestaff?source=rss-f35760a50c9f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*o_Ay65Dpf4hKr9PFMDRQ7g.png</url>
            <title>Stories by 株式会社ジラフ on Medium</title>
            <link>https://medium.com/@jiraffestaff?source=rss-f35760a50c9f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 20:29:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jiraffestaff/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Rails の routes 設定で、複数の URL 生成を一つのヘルパで行うようにする]]></title>
            <link>https://medium.com/@jiraffestaff/rails-%E3%81%AE-routes-%E8%A8%AD%E5%AE%9A%E3%81%A7-%E8%A4%87%E6%95%B0%E3%81%AE-url-%E7%94%9F%E6%88%90%E3%82%92%E4%B8%80%E3%81%A4%E3%81%AE%E3%83%98%E3%83%AB%E3%83%91%E3%81%A7%E8%A1%8C%E3%81%86%E3%82%88%E3%81%86%E3%81%AB%E3%81%99%E3%82%8B-615d3f853926?source=rss-f35760a50c9f------2</link>
            <guid isPermaLink="false">https://medium.com/p/615d3f853926</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[rails-routes]]></category>
            <dc:creator><![CDATA[株式会社ジラフ]]></dc:creator>
            <pubDate>Thu, 10 Dec 2020 06:48:44 GMT</pubDate>
            <atom:updated>2020-12-11T02:00:48.834Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bQmtxEefpGOHq_pX" /><figcaption>Photo by <a href="https://unsplash.com/@mackenzimartin?utm_source=medium&amp;utm_medium=referral">MacKenzi Martin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>ヒカカク！のエンジニアの桂です。</p><p>今回、マーケティングの都合上、コラム記事 (blog) の URL にカテゴリによる階層構造を持たせたいと言う要望がありました。いきなり全部を置き換えると言うのも手間だし、そもそも必要もないので、 URL 生成用のカテゴリを設定した時だけ階層構造を持つ URL になるような開発をすることにしました。</p><p>レコードに含まれる値によって URL が変わるため、素朴にやると開発者が常にどっちを使うか意識しながら URL 生成をする必要が生じて面倒です。</p><p>Rails 5.1 で導入された direct を使うとカスタムパスヘルパーのようなものを定義できます。つまり、 blog_path(blog) のようにするだけで勝手に複数種類のパスを切り替えてくれる挙動が実現できます。</p><h3>手法</h3><h4>二種類の routes を定義する</h4><p>まず既存の URL は slug ベースで、 /blog/本日は晴天なり/ のようなパスを利用していました。</p><pre>resources :blog, only: %i[index show], param: :slug</pre><p>ここに、新しく path と id ベースの routes 定義を追加し、 /blog/weather/today/123 のようなパスをルーティングできるようにします。</p><pre>get &#39;blog/*path/:id&#39;, to: &#39;blog#show&#39;</pre><h4>コントローラ側で両方の routes に対応できるようにする</h4><p>前者の routes 定義にマッチする URL でアクセスしてきた場合は params[:slug] が、後者の場合は params[:path] 、 params[:id] がコントローラに渡ってきます。</p><p>この両方に対応できるようにコントローラを書き換えます。</p><p>(本題から逸れるので手法は省略)</p><h4>direct を使って URL ヘルパで URL の出しわけをする</h4><p>Rails 5.1 から direct と言う命令が config/routes.rb で使えるようになりました。これを使うと任意のパスに導く (direct) ことができます。</p><p>まず、 Blog モデルにカテゴリ階層を持たせるかどうかを判定するメソッド (Blog#category_path_based?) とカテゴリ階層を返すメソッド (Blog#category_path) を定義しておき、</p><pre>direct :blog do |blog = nil, **options|<br>  {<br>    controller: &#39;/blog&#39;,<br>    action:     :show,<br>    path:       nil,<br>    id:         nil,<br>    slug:       nil,<br>    **if blog.nil?<br>        {}<br>      elsif blog.category_path_based?<br>        {<br>          path: blog.category_path,<br>          id:   blog.id<br>        }<br>      else<br>        {<br>          slug: blog.slug<br>        }<br>      end,<br>    **options<br>  }<br>end</pre><p>のような routes 定義をすると、パスヘルパーに渡す blog によって自動的に</p><pre>blog_path(blog_with_slug)          # =&gt; &quot;/blog/hoge&quot;<br>blog_path(blog_with_category_path) # =&gt; &quot;/blog/cat1/cat2/123&quot;</pre><p>のように URL 生成が切り替えられます。</p><h4>上記コードの補足事項</h4><ul><li>direct の返り値は url_for によって解釈されるようですが、 url_for にはリクエスト処理中に呼ばれるとコンテキストの影響を受けると言う罠があります</li><li>Users::HogeController から呼ぶと /users/blog/hoge のように namespace が反映されてしまうなどの問題が出るので、 controller: &#39;/blog&#39; のように / をつけてキャンセルします</li><li>同様にコンテキストに params[:slug] があると (先に定義されている) slug ベースの URL に常にマッチするようになるので、 slug: nil などをデフォルトで与えて潰すようにします</li><li>使いやすさを重視して resources によって定義されるデフォルトのパスヘルパーを上書きしていますが、気持ち悪い場合は別の名前で direct を定義しましょう</li></ul><h3>告知</h3><p>ジラフでは仲間を募集中です。興味がある方は是非ともご連絡ください。</p><p><a href="https://recruit.jiraffe.co.jp/entry">株式会社ジラフ 採用サイト</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=615d3f853926" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[mecabrc が見つからないというエラー]]></title>
            <link>https://medium.com/@jiraffestaff/mecabrc-%E3%81%8C%E8%A6%8B%E3%81%A4%E3%81%8B%E3%82%89%E3%81%AA%E3%81%84%E3%81%A8%E3%81%84%E3%81%86%E3%82%A8%E3%83%A9%E3%83%BC-b3e278e9ed07?source=rss-f35760a50c9f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3e278e9ed07</guid>
            <category><![CDATA[bert]]></category>
            <category><![CDATA[mecab]]></category>
            <category><![CDATA[hugging-face]]></category>
            <dc:creator><![CDATA[株式会社ジラフ]]></dc:creator>
            <pubDate>Wed, 15 Jul 2020 09:58:38 GMT</pubDate>
            <atom:updated>2020-07-15T09:58:38.928Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uimIrKoToqo_0qYs" /><figcaption>Photo by <a href="https://unsplash.com/@manucosen?utm_source=medium&amp;utm_medium=referral">Manuel Cosentino</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>エンジニアの桂です。</p><h3>現象</h3><p>最近、 Google Colab で、Hugging Face の Transformers で使える日本語学習済み BERT、 bert-japanese を使っていると以下のエラーが出るようになりました。</p><pre>----------------------------------------------------------</pre><pre>Failed initializing MeCab. Please see the README for possible solutions:</pre><pre>https://github.com/SamuraiT/mecab-python3#common-issues</pre><pre>If you are still having trouble, please file an issue here, and include the</pre><pre>ERROR DETAILS below:</pre><pre>https://github.com/SamuraiT/mecab-python3/issues</pre><pre>issueを英語で書く必要はありません。</pre><pre>------------------- ERROR DETAILS ------------------------</pre><pre>arguments:</pre><pre>error message: [ifs] no such file or directory: /usr/local/etc/mecabrc</pre><pre>---------------------------------------------------------------------------</pre><pre>RuntimeError                              Traceback (most recent call last)</pre><pre>&lt;ipython-input-7-1fe845d575ff&gt; in &lt;module&gt;()</pre><pre>----&gt; 1 tokenizer = BertJapaneseTokenizer.from_pretrained(‘cl-tohoku/bert-base-japanese-whole-word-masking’)</pre><pre>4 frames</pre><pre>/usr/local/lib/python3.6/dist-packages/MeCab/__init__.py in __init__(self, rawargs)</pre><pre>122</pre><pre>123         try:</pre><pre>--&gt; 124             super(Tagger, self).__init__(args)</pre><pre>125         except RuntimeError:</pre><pre>126             error_info(rawargs)</pre><pre>RuntimeError:</pre><p>この原因を調べてみたところ、 mecab-python3 が 1.0 にバージョンアップして、辞書ライブラリを別途インストールすることをを求めるようになったことに起因するようです。</p><h3>解決策</h3><p>単に MeCab を使いたいだけなら、 README に記載されているように</p><pre>$ pip install unidic-lite</pre><p>を実行すれば動くようになるはずです。</p><p>しかし、我々は MeCab を bert-japanese で使うことを目的にしているので、これだとうまくいきません。</p><p>何かしらの方法で ipadic を使わせることができれば動かせるのかもしれないですが、ここではそういう方向の深掘りはせず、確実に動くバージョンに戻すことで解消しました。</p><pre>$ pip install mecab-python3==0.996.5</pre><h3>告知</h3><p>最後に、ジラフでは仲間を絶賛募集中ですので、興味がある方は是非ともご連絡ください。</p><p><a href="https://recruit.jiraffe.co.jp/entry">株式会社ジラフ 採用サイト</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3e278e9ed07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cloud Build を定期実行する]]></title>
            <link>https://medium.com/@jiraffestaff/cloud-build-%E3%82%92%E5%AE%9A%E6%9C%9F%E5%AE%9F%E8%A1%8C%E3%81%99%E3%82%8B-7ccdb3ae9527?source=rss-f35760a50c9f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ccdb3ae9527</guid>
            <category><![CDATA[cron]]></category>
            <category><![CDATA[cloud-build]]></category>
            <category><![CDATA[google-cloud-build]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[pub-sub]]></category>
            <dc:creator><![CDATA[株式会社ジラフ]]></dc:creator>
            <pubDate>Mon, 22 Jun 2020 09:09:37 GMT</pubDate>
            <atom:updated>2020-06-23T02:07:01.432Z</atom:updated>
            <content:encoded><![CDATA[<h3>[2020年版] Cloud Build を定期実行する</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r2-amPn6Nu0itvTx" /><figcaption>Photo by <a href="https://unsplash.com/@danieltuttle?utm_source=medium&amp;utm_medium=referral">Daniel Tuttle</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>エンジニアの桂です。</p><p>今回は Cloud Build を定期実行する方法について紹介します。結構需要がありそうなのに明にやり方が示されていなくて難儀するやつです。</p><p>戦略としては、 Cloud Scheduler で Pub/Sub トリガーを定期的に発火して、 Cloud Build の API を叩く Cloud Functions を実行させます。</p><h3>設定手順</h3><h4>1. Cloud Build のトリガーを設定</h4><p>Cloud Functions に発火させるために、 Cloud Build のトリガーの設定が必要です。</p><p>我々の定期的に実行するのが目的なのですが、Cloud Build のトリガーはリポジトリの更新で発火させるのが目的のものなので、とりあえずそういう風に設定して、勝手に我々に都合の良い使い方をします。</p><p>Cloud Build で実行するcloudbuild.yaml や Dockerfile にmaster ブランチのものを使うのであれば、トリガーを「ブランチに push する」、ソースブランチを「 ^master$ 」にしておくとうまく動きます (確認していませんが、4. で指定する BRANCH_NAME にマッチする正規表現である必要があると思われます)。</p><p>このままだと master ブランチの更新のたびに実行されてしまうので、それが好ましくない場合はトリガーを無効化しておきましょう。</p><h4>2. Pub/Sub のトリガーを作成</h4><p>適当な ID で Pub/Sub トリガーを作成します。</p><h4>3. Cloud Scheduler のジョブを作成</h4><p>ターゲットを Pub/Sub にするとトピックの入力欄が現れるので、先ほど作成したトピックの ID を入力します ( projects/ から始まるトピック名という概念がありますが、アレを入力すると無言で空トピック ID が設定されて動かないので注意します)。</p><p>ペイロードは使わないのであれば適当に {} にでもしておくと良いと思います。</p><p>ちなみに cron の書式をよく間違えるので、私は一応<a href="https://crontab.guru/">シミュレータ</a>で確認しています。</p><h4>4. Cloud Functions の関数を作成</h4><p>Cloud Build トリガー編集ページの URL からトリガー ID を取得します。 UUID っぽいフォーマット ( 550e8400-e29b-41d4-a716–446655440000 の様な) になっているものがそれです。</p><p>トリガーを Pub/Sub に設定して、 2. で取得したトリガー名を設定します。</p><p>設定するソースコードは以下の通りです (node.js 10 の場合)。</p><p>index.js</p><pre>const gapis = require(&#39;googleapis&#39;)</pre><pre>const PROJECT_ID = &#39;&lt;プロジェクト ID&gt;&#39;</pre><pre>const TRIGGER_ID = &#39;&lt;Cloud Build トリガー ID&gt;’</pre><pre>const BRANCH_NAME = &#39;master&#39;</pre><pre>/**</pre><pre>* Triggered from a message on a Cloud Pub/Sub topic.</pre><pre>*</pre><pre>* @param {!Object} event Event payload.</pre><pre>* @param {!Object} context Metadata for the event.</pre><pre>*/</pre><pre>exports.run = async (event, context) =&gt; {</pre><pre>  const authCloudBuild = async () =&gt; {</pre><pre>    const client = await gapis.google.auth.getClient({</pre><pre>      scopes: [&#39;https://www.googleapis.com/auth/cloud-platform&#39;]</pre><pre>    })</pre><pre>    return new gapis.cloudbuild_v1.Cloudbuild({ auth: client })</pre><pre>  }</pre><pre>  const authedCloudBuild = await authCloudBuild()</pre><pre>  const runParams = {</pre><pre>    projectId: PROJECT_ID,</pre><pre>    triggerId: TRIGGER_ID,</pre><pre>    requestBody: { branchName: BRANCH_NAME }</pre><pre>  }</pre><pre>  const res = await authedCloudBuild.projects.triggers.run(runParams)</pre><pre>  console.log(res.data)</pre><pre>};</pre><p>package.json</p><pre>{</pre><pre>  &quot;name&quot;: &quot;sample&quot;,</pre><pre>  &quot;version&quot;: &quot;0.0.1&quot;,</pre><pre>  &quot;dependencies&quot;: {</pre><pre>    &quot;@google-cloud/pubsub&quot;: &quot;^0.18.0&quot;,</pre><pre>    &quot;googleapis&quot;: &quot;^52.1.0&quot;</pre><pre>  }</pre><pre>}</pre><p><a href="https://qiita.com/oubakiou/items/47390398abe2543925d7">@oubakiou 様のこちらの Qiita の記事</a>を参考に作りました。ありがとうございます。</p><h4>5. 動作確認</h4><p>作成した Cloud Scheduler ジョブを「今すぐ実行」して動いたら完成。</p><h3>告知</h3><p>最後に、ジラフでは仲間を絶賛募集中ですので、興味がある方は是非ともご連絡ください。</p><p><a href="https://recruit.jiraffe.co.jp/entry">株式会社ジラフ 採用サイト</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ccdb3ae9527" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[YAML ファイル一つで Kubernetes の Event を監視し、 Slack に通知する]]></title>
            <link>https://medium.com/@jiraffestaff/yaml-%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E4%B8%80%E3%81%A4%E3%81%A7-kubernetes-%E3%81%AE-event-%E3%82%92%E7%9B%A3%E8%A6%96%E3%81%97-slack-%E3%81%AB%E9%80%9A%E7%9F%A5%E3%81%99%E3%82%8B-13fb8155dfde?source=rss-f35760a50c9f------2</link>
            <guid isPermaLink="false">https://medium.com/p/13fb8155dfde</guid>
            <category><![CDATA[cronjob]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kubectl]]></category>
            <dc:creator><![CDATA[株式会社ジラフ]]></dc:creator>
            <pubDate>Fri, 08 May 2020 05:11:27 GMT</pubDate>
            <atom:updated>2020-05-09T06:51:11.334Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yH3JvJJpnTAYCmUN" /><figcaption>Photo by <a href="https://unsplash.com/@lukechesser?utm_source=medium&amp;utm_medium=referral">Luke Chesser</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>ヒカカク！チームの桂です。</p><p>Kubernetes の稼働状況を監視する方法はいろいろありますが、だいたいは <a href="https://prometheus.io/">Prometheus</a> とかその辺のまあまあ大袈裟なツールでやることになるんじゃないかと思います。</p><p>そういうのの紹介は他に譲るとして、今回はミニマルで Pod の Backoff とか Job / CronJob の失敗とかを検知する方法を紹介します。</p><h3>利点</h3><ul><li>簡単</li><li>実装が shell script なので加工とか絞り込みとか理論上何でもできる (モニタリングツールだとこの条件で絞り込むのは無理とかありますよね)</li></ul><h3>欠点</h3><ul><li>こいつが起動してないと通知できないので、リソース足りないとかで共倒れしたら通知できない</li><li>kubectl get events --watch を使うが、これにはたまに 1 時間前の Event を検知してしまう不具合がある (v1.15 時点)</li></ul><h3>前提: kubectl で監視</h3><p>Pod の Backoff とかの一覧は kubectlで実現できます。</p><pre>$ kubectl get events</pre><p><a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#event-v1beta1-events-k8s-io">Event の type には現在 </a><a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#event-v1beta1-events-k8s-io">Normal と </a><a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#event-v1beta1-events-k8s-io">Warning が存在します</a>。 Normal の方は気にしないことにして、かつ 1. 全てのネームスペースを対象するようにする、 2. 新規の Event だけリアルタイムで監視するようにすると、結局以下のコマンドになります。</p><pre>$ kubectl get events --field-selector=type!=Normal --all-namespaces --watch-only</pre><h3>前提: Pod で kubectl 実行</h3><p><a href="https://qiita.com/sotoiwa/items/aff12291957d85069a76">Kubernetes 上の Pod は ServiceAccount の設定さえすれば Kubernetes API の実行ができるようになっています</a>。</p><p>だから、 <a href="https://hub.docker.com/r/bitnami/kubectl/">bitnami/kubectl</a> とかその辺の kubectl が実行できる適当なイメージで Pod を作って、以下のような ClusterRole を ServiceAccount 経由で bind してやれば Pod 上で kubectl get events --watch できます。</p><pre>kind: ClusterRole<br>apiVersion: rbac.authorization.k8s.io/v1<br>metadata:<br>  name: event-watcher<br>rules:<br>- apiGroups: [&quot;&quot;]<br>  resources:<br>  - events<br>  verbs: [&quot;get&quot;, &quot;watch&quot;, &quot;list&quot;]</pre><p>(これは件の YAML に含まれるので、個別に適用する必要はありません。)</p><h3>前提: Slack API</h3><p>Slack 通知のためには当然 Slack API が必要なので準備します。</p><p><a href="https://api.slack.com/">https://api.slack.com/</a> でアプリを作成し、 OAuth &amp; Permissions の Bot Token Scopes に chat:write (と、必要に応じて chat:write:customize と chat:write:public あたり) を設定したものを、ワークスペースにインストールすれば完了です。</p><h3>Event を Slack 通知する YAML</h3><p>結局、こんな感じの YAML を用意して kubectl apply を実行してやるだけで直ちに Warning Event の Slack 通知ができるようになります。</p><p>env を ConfigMap などにすると、環境ごとに通知チャネルを分けたり、 Access Token を git にコミットしないようにしたりできます。</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: event-watcher<br>  labels:<br>    app: event-watcher<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: event-watcher<br>  strategy:<br>    type: RollingUpdate<br>  template:<br>    metadata:<br>      name: event-watcher<br>      labels:<br>        app: event-watcher<br>    spec:<br>      serviceAccountName: event-watcher<br>      containers:<br>      - image: bitnami/kubectl<br>        imagePullPolicy: Always<br>        name: event-watcher<br>        command: [&#39;bash&#39;]<br>        args:<br>        - -c<br>        - |<br>          set -euC -o pipefail<br>          notify_via_slack () {<br>            curl -s -X POST -H &#39;Content-Type: application/json; charset=UTF-8&#39; \<br>                            -H &quot;Authorization: Bearer ${SLACK_OAUTH_ACCESS_TOKEN}&quot; \<br>                            -d &#39;{&quot;channel&quot;: &quot;&#39;&quot;$1&quot;&#39;&quot;, &quot;text&quot;: &quot;&#39;&quot;$2&quot;&#39;&quot;, &quot;username&quot;: &quot;Kubernetes&quot;, &quot;icon_emoji&quot;: &quot;:kubernetes:&quot;}&#39; \<br>                            <a href="https://slack.com/api/chat.postMessage">https://slack.com/api/chat.postMessage</a><br>          }<br>          channel=&quot;${EVENT_NOTIFICATION_CHANNEL}&quot;<br>          jsonpath=&#39;[{.metadata.namespace}] {.involvedObject.kind}: {.involvedObject.name}\\n*{.reason}*: {.message}{&quot;\n&quot;}&#39;<br>          kubectl get events --all-namespaces --field-selector=type!=Normal --output=jsonpath=&quot;${jsonpath}&quot; --watch-only \<br>            | while read line; do notify_via_slack &quot;${channel}&quot; &quot;${line}&quot;; done<br>        env:<br>        - name: EVENT_NOTIFICATION_CHANNEL<br>          value: &#39;#monitoring&#39;<br>        - name: SLACK_OAUTH_ACCESS_TOKEN<br>          value: &#39;xoxb-XXXXX&#39; # ここに OAuth Access Token を設定<br>      restartPolicy: Always</pre><pre>---</pre><pre>kind: ClusterRole<br>apiVersion: rbac.authorization.k8s.io/v1<br>metadata:<br>  name: event-watcher<br>rules:<br>- apiGroups: [&quot;&quot;]<br>  resources:<br>  - events<br>  verbs: [&quot;get&quot;, &quot;watch&quot;, &quot;list&quot;]</pre><pre>---</pre><pre>apiVersion: v1<br>kind: ServiceAccount<br>metadata:<br>  name: event-watcher</pre><pre>---</pre><pre>apiVersion: rbac.authorization.k8s.io/v1beta1<br>kind: ClusterRoleBinding<br>metadata:<br>  name: event-watcher<br>roleRef:<br>  apiGroup: rbac.authorization.k8s.io<br>  kind: ClusterRole<br>  name: event-watcher<br>subjects:<br>- kind: ServiceAccount<br>  name: event-watcher</pre><p>※ :kubernetes: という Slack Emoji があることを前提にしています。</p><h3>補足</h3><ul><li>Namespace は意図的に切っていません。追加するなり、 kustomize に組み込むなりしてください。</li><li>Kubernetes API が叩ければいいので、shell script に限らず <a href="https://kubernetes.io/docs/reference/using-api/client-libraries/">Python, Go など好きな言語</a>でも実装できます。</li><li>通知部分もただ curl で Slack API 叩いてるだけなので、パラメータ変えるなり Slack 以外のツール (Chatwork, Elasticsearch, etc.) を使うなり自由にアレンジできます。</li></ul><h3>告知</h3><p>最後に、ジラフでは仲間を絶賛募集中ですので、興味がある方は是非ともご連絡ください。</p><p><a href="https://recruit.jiraffe.co.jp/entry">株式会社ジラフ 採用サイト</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13fb8155dfde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[実は難しい、 Cloud Build から Cloud SQL への接続]]></title>
            <link>https://medium.com/@jiraffestaff/%E5%AE%9F%E3%81%AF%E9%9B%A3%E3%81%97%E3%81%84-cloud-build-%E3%81%8B%E3%82%89-cloud-sql-%E3%81%B8%E3%81%AE%E6%8E%A5%E7%B6%9A-c77cb75bc813?source=rss-f35760a50c9f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c77cb75bc813</guid>
            <category><![CDATA[google-cloud-sql]]></category>
            <category><![CDATA[cloud-sql-proxy]]></category>
            <category><![CDATA[cloud-build]]></category>
            <category><![CDATA[cloud-sql]]></category>
            <category><![CDATA[google-cloud-build]]></category>
            <dc:creator><![CDATA[株式会社ジラフ]]></dc:creator>
            <pubDate>Fri, 01 Nov 2019 06:00:33 GMT</pubDate>
            <atom:updated>2019-11-01T07:14:32.767Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vJ2gVoN5xhHpOghU" /><figcaption>Photo by <a href="https://unsplash.com/@eberhardgross?utm_source=medium&amp;utm_medium=referral">eberhard grossgasteiger</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>エンジニアの桂です。</p><p>今日は Cloud Build から Cloud SQL に接続する方法について紹介していきます。</p><p>どちらも Google Cloud Platform 上のサービスなので一見簡単にできそうですが、 Cloud Build というサービスは予想外に不器用で、こういう作業はかなり苦手だったりします。</p><p>今回は Cloud SQL Proxy を立てながら並列的にSQL 接続を行う手法を使います。この手法は <a href="https://qiita.com/kshibata101">@kshibata101</a> 氏の <a href="https://qiita.com/kshibata101/items/fd8f5f10ff4c99504b9a">Cloud BuildでCloud SQLのマイグレーションをしたい</a> をベースにしていますが、最近 <a href="https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/317#issuecomment-540869722">Cloud SQL Proxy のイメージから </a><a href="https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/317#issuecomment-540869722">sh が削除された</a>ため、この手法は使えません。</p><pre>docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused &quot;exec: \&quot;sh\&quot;: executable file not found in $PATH&quot;: unknown.<br>time=&quot;2019-11-01T07:13:46Z&quot; level=error msg=&quot;error waiting for container: context canceled&quot;</pre><p>そこで、この GitHub Issue 内で <a href="https://github.com/ffjeremy">ffjeremy</a> 氏が<a href="https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/317#issuecomment-542847036">提案している方法</a>に近いものを紹介します。</p><h3>Cloud Build 設定</h3><p>Cloud SQL Proxy を起動して UNIX ソケットを介して Cloud SQL に接続すると言う流れですが、 Cloud SQL Proxy は SQL 実行の際にバックグラウンドで実行する必要があるので、工夫が必要です。</p><p>並列で実行するだけであれば、waitFor オプションを使って簡単に実現できますが、それだけだと Cloud SQL Proxy は永遠に終わらないので、用が終わってから docker kill を使って Cloud SQL Proxy のコンテナを終了させます。</p><p>これらを踏まえて、以下の cloudbuild.yaml を用意しました。『SQL 実行』と substitutions をタスクに合わせて変更して利用します。(_DB_USER と _DB_PASS はコマンドラインから渡します。)</p><pre>steps:<br>- id: Cloud SQL Proxy 起動<br>  name: gcr.io/cloudsql-docker/gce-proxy<br>  args:<br>    - /cloud_sql_proxy<br>    - -dir=/cloudsql<br>    - -instances=${_INSTANCE_CONNECTION_NAME}<br>  volumes:<br>  - name: cloudsql<br>    path: /cloudsql<br>- id: Cloud SQL Proxy 起動待機<br>  name: mysql:5.7.28 # 『SQL 実行』で使うイメージをここで pull しておくとお得<br>  entrypoint: bash<br>  args:<br>  - -c<br>  - |<br>    while [ ! -e &quot;/cloudsql/${_INSTANCE_CONNECTION_NAME}&quot; ]; do<br>      sleep 1<br>    done<br>  volumes:<br>  - name: cloudsql<br>    path: /cloudsql<br>  waitFor: [&#39;-&#39;]<br>- id: SQL 実行<br>  name: mysql:5.7.28<br>  entrypoint: bash<br>  args:<br>  - -c<br>  - |<br>    # ここを目的に合わせて変更します<br>    mysql -u&quot;${_DB_USER}&quot; -p&quot;${_DB_PASS}&quot; -S&quot;/cloudsql/${_INSTANCE_CONNECTION_NAME}&quot; -D&quot;${_DB_NAME}&quot; \<br>      -e &#39;SHOW TABLES&#39;<br>  volumes:<br>  - name: cloudsql<br>    path: /cloudsql<br>  waitFor: [&#39;Cloud SQL Proxy 起動待機&#39;]<br>- id: Cloud SQL Proxy 終了<br>  name: gcr.io/cloud-builders/docker<br>  entrypoint: bash<br>  args:<br>  - -c<br>  - docker kill -s TERM $$(docker ps -q --filter ancestor=gcr.io/cloudsql-docker/gce-proxy)<br>  waitFor: [&#39;SQL 実行&#39;]<br>substitutions:<br>  _DB_NAME: &lt;DB 名を指定&gt;<br>  _INSTANCE_CONNECTION_NAME: &lt;Cloud SQL のインスタンス接続名を指定&gt;</pre><h3>Cloud Build 実行の準備</h3><p>Cloud SQL Proxy を使うために、まず<a href="https://console.cloud.google.com/apis/api/sqladmin.googleapis.com/overview">こちら</a>から Cloud SQL Admin API を有効にします。</p><p>また、 Cloud Build から Cloud SQL にアクセスするために、 サービスアカウントにroles/cloudsql.client を付与します。</p><pre>$ PROJECT_NAME=$(gcloud projects list --filter=&quot;$(gcloud config get-value project)&quot; --format=&quot;value(NAME)&quot;)<br>$ PROJECT_NUMBER<strong>=</strong>$(gcloud projects list --filter<strong>=</strong>&quot;$(gcloud config get-value project)&quot; --format<strong>=</strong>&quot;value(PROJECT_NUMBER)&quot;)<br>$ gcloud projects add-iam-policy-binding ${PROJECT_NAME} --member<strong>=</strong>serviceAccount:<strong>${</strong>PROJECT_NUMBER<strong>}</strong>@cloudbuild.gserviceaccount.com --role<strong>=</strong>roles/cloudsql.client</pre><h3>Cloud Build の実行</h3><p>前述の通り、 _DB_USER と _DB_PASS を渡して実行します。</p><pre>$ gcloud builds submit --config=cloudbuild.yaml --substitutions=_DB_USER=&lt;DB ユーザ名&gt;,_DB_PASS=&lt;DB パスワード&gt;</pre><h3>終わりに</h3><p>Cloud Build は便利ではありますが、 VPC に繋げなかったり色々不便な箇所が目立ちます。今後の改善が期待されますね。</p><p>さて、最後に、ジラフでは仲間を絶賛募集中ですので、興味がある方は是非ともご連絡ください。</p><p><a href="https://recruit.jiraffe.co.jp/entry">株式会社ジラフ 採用サイト</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c77cb75bc813" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google の Cloud Memorystore で Action Cable 6.0 を動かす #rails6 #actioncable #gcp]]></title>
            <link>https://medium.com/@jiraffestaff/google-%E3%81%AE-cloud-memorystore-%E3%81%A7-action-cable-6-0-%E3%82%92%E5%8B%95%E3%81%8B%E3%81%99-rails6-actioncable-gcp-35f422be509a?source=rss-f35760a50c9f------2</link>
            <guid isPermaLink="false">https://medium.com/p/35f422be509a</guid>
            <category><![CDATA[actioncable]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[rails-6]]></category>
            <category><![CDATA[gcp]]></category>
            <dc:creator><![CDATA[株式会社ジラフ]]></dc:creator>
            <pubDate>Tue, 15 Oct 2019 02:29:17 GMT</pubDate>
            <atom:updated>2019-10-15T02:29:17.796Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google の Cloud Memorystore で Action Cable 6.0 を動かす。</h3><figure><img alt="Cable Action" src="https://cdn-images-1.medium.com/max/1024/0*OMwYHpR7p2ERPJU6" /><figcaption>Photo by <a href="https://unsplash.com/@cathus?utm_source=medium&amp;utm_medium=referral">Garry Neesam</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>エンジニアの桂です。</p><p>ヒカカク！では Action Cable を運用しているのですが、 Rails 6 へのアップデートの際に例外が発生する事案がありました。その原因と回避策について紹介します。</p><h3>現象</h3><p>GCP の Cloud Memorystore を Action Cable の Redis サーバーに設定した状態で ActionCable.server.broadcastすると以下のような例外が発生した。</p><pre>Redis::CommandError</pre><pre>ERR unknown command &#39;client&#39;</pre><p>発生箇所は<a href="https://github.com/redis/redis-rb/blob/0559b503f9303e9716957bdbea2f731006d549b2/lib/redis/client.rb#L109">こちら</a>。</p><h3>原因</h3><p>Action Cable が Redis.new するとき、自動的に id を設定する。Redis::Client は id が設定されると Redis サーバーに client 命令を発行してその id を設定するが、 <a href="https://cloud.google.com/memorystore/docs/reference/redis-configs#blocked">Cloud Memorystore は </a><a href="https://cloud.google.com/memorystore/docs/reference/redis-configs#blocked">client 命令に対応していない</a>。</p><h3>回避策</h3><p><a href="https://github.com/redis/redis-rb/blob/0559b503f9303e9716957bdbea2f731006d549b2/lib/redis/client.rb#L109">エラー発生箇所のコード</a>から、 Redis.new の際、 id に nil 渡してやると client 命令を発行せずに済むことが分かります。</p><p>Action Cable 曰く、</p><blockquote><a href="https://github.com/rails/rails/blob/1853f91a8dd81b23b323a223b0062eaccf844bf9/actioncable/lib/action_cable/subscription_adapter/redis.rb#L15-L16">Overwrite this factory method for Redis connections if you want to use a different Redis library than the redis gem.</a></blockquote><p>ということなので、ちょっと目的は違いますが、この値をパッチしてやります。</p><pre># config/initializers/action_cable.rb</pre><pre>require &#39;action_cable/subscription_adapter/redis&#39;</pre><pre>ActionCable::SubscriptionAdapter::Redis.redis_connector = -&gt;(config) do<br>  config[:id] = &quot;ActionCable-PID-#{$$}&quot; unless config.has_key?(:id)<br>  ::Redis.new(config.except(:adapter, :channel_prefix))<br>end</pre><p>これで config/cable.yml から id: null を渡してやることができるようになり、 client 命令を回避することができました。</p><pre># config/cable.yml</pre><pre>production:<br>  adapter: redis<br>  url: &lt;%= &quot;redis://#{ENV[&#39;REDIS_HOST&#39;]}:6379/0&quot; %&gt;<br>  id: null</pre><h3>コントリビューションはじめました</h3><p>id を明示的に null に指定しても強制的に上書きされるのは一先ずよくない挙動だということで、 <a href="https://github.com/rails/rails/pull/37437">Rails に PR を出しておきました</a>。</p><h3>仲間募集してます</h3><p><a href="https://www.wantedly.com/projects/266144">100%自社開発。Peing -質問箱-サーバサイドエンジニアWANTED by 株式会社ジラフ</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35f422be509a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pumaをstack driverで監視する]]></title>
            <link>https://medium.com/@jiraffestaff/puma%E3%82%92stack-driver%E3%81%A7%E7%9B%A3%E8%A6%96%E3%81%99%E3%82%8B-6d87c555f178?source=rss-f35760a50c9f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d87c555f178</guid>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[stackdriver]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[株式会社ジラフ]]></dc:creator>
            <pubDate>Wed, 11 Sep 2019 00:27:13 GMT</pubDate>
            <atom:updated>2019-09-11T04:52:30.597Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ylq777KkIiqMM2F2" /><figcaption>Photo by <a href="https://unsplash.com/@chrisliverani?utm_source=medium&amp;utm_medium=referral">Chris Liverani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>質問箱を担当している梅本です。</p><p>最近質問箱が落ちてしまいます。監視しているメトリクスに異常はほとんどない状態で落ちていました。</p><p>監視できていない部分が何か考えるとPumaについてあまり監視できてないことに気づきました。</p><p>そこでPumaのメトリクスをstack diverで監視したくなったので検索したのですが、日本語の情報はほとんどなくて困ったので書きます。</p><h3>やること</h3><ol><li><a href="https://github.com/GoogleCloudPlatform/k8s-stackdriver/tree/master/custom-metrics-stackdriver-adapter">custom-metrics-stackdriver-adapter</a> をリリースする</li><li>Rails側にメトリクスの設定を追加する</li><li>stack driverでグラフの設定をする</li></ol><h3>custom-metrics-stackdriver-adapter をリリースする</h3><p>今から書くリリースの方法は<a href="https://github.com/GoogleCloudPlatform/k8s-stackdriver/tree/master/custom-metrics-stackdriver-adapter">こちらの公式リポジトリ</a>に記載されています</p><h4>必要なもの</h4><ul><li>GKEのクラスター（Kubenretesのバージョンは 1.8.1 以上）</li><li>作成されたクラスターのcluster-adminの権限</li><li>権限がない場合は下のコマンドをcloud shellで実行してください</li></ul><pre># クラスタに接続するための認証<br>gcloud container clusters get-credentials クラスタ名 --zone クラスタのゾーン --project プロジェクトのID<br># cluster-adminを付与するコマンド<br>kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user $(gcloud config get-value account)</pre><h4>custom-metrics-stackdriver-adapterをリリースする</h4><p>リリース</p><pre>kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-stackdriver/master/custom-metrics-stackdriver-adapter/deploy/production/adapter_new_resource_model.yaml</pre><p>確認</p><pre>kubectl -n custom-metrics get po<br># =&gt; NAME                                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE<br>     custom-metrics-stackdriver-adapter   1         1         1            1           1m</pre><h3>Rails側にメトリクスの設定を追加する</h3><p><strong>Gemfileに追加</strong></p><pre>gem &#39;yabeda-puma-plugin&#39;<br>gem &#39;prometheus-client&#39;<br>gem &#39;yabeda-prometheus&#39;<br>gem &#39;yabeda-rails&#39;</pre><p><strong>puma.rbに追加</strong></p><pre>activate_control_app<br>plugin :yabeda</pre><p><strong>Routesに追加</strong></p><pre>mount Yabeda::Prometheus::Exporter =&gt; &#39;/metrics&#39;</pre><p><strong>Deploymentに設定を追加</strong></p><p>http://localhost:3000/metricsのportはpumaの設定に合わせて変更してください</p><p>auto scalerを設定している場合はresourcesを設定しないとauto scalerが動かなくなってしまいます。</p><pre>- name: prometheus-to-sd<br>  image: gcr.io/google-containers/prometheus-to-sd:v0.7.2<br>  command:<br>  - /monitor<br>  - --stackdriver-prefix=custom.googleapis.com<br>  - --source=rails:<a href="http://localhost:13270/puma/metrics">http://localhost:3000/metrics</a> <br>  - --pod-id=$(POD_NAME)<br>  - --namespace-id=$(POD_NAMESPACE)<br>  env:<br>  - name: POD_NAME<br>    valueFrom:<br>      fieldRef:<br>        apiVersion: v1<br>        fieldPath: metadata.name<br>  - name: POD_NAMESPACE<br>    valueFrom:<br>      fieldRef:<br>        apiVersion: v1<br>        fieldPath: metadata.namespace<br>  imagePullPolicy: IfNotPresent<br>  ports:<br>  - containerPort: 6060<br>    name: profiler<br>    protocol: TCP<br>  resources: {}<br>  terminationMessagePath: /dev/termination-log<br>  terminationMessagePolicy: File</pre><h4>ローカルで出力を試す</h4><p>pumaのworkerを増やすのでpuma.rbに追加</p><pre>workers 2</pre><p>ローカルのサーバーを起動後 <a href="http://localhost:3000/metrics">http://localhost:3000/metrics</a> にアクセスすると以下のような文字列が出力されます</p><pre># TYPE rails_requests_total counter<br># HELP rails_requests_total A counter of the total number of HTTP requests rails processed.<br>rails_requests_total{controller=&quot;user&quot;,action=&quot;id&quot;,status=&quot;301&quot;,format=&quot;html&quot;,method=&quot;get&quot;} 1<br>rails_requests_total{controller=&quot;user&quot;,action=&quot;id&quot;,status=&quot;302&quot;,format=&quot;html&quot;,method=&quot;get&quot;} 1<br># TYPE rails_request_duration_seconds histogram<br># HELP rails_request_duration_seconds A histogram of the response latency.<br>rails_request_duration_seconds_bucket{controller=&quot;user&quot;,action=&quot;id&quot;,status=&quot;301&quot;,format=&quot;html&quot;,method=&quot;get&quot;,le=&quot;0.005&quot;} 0.0<br>...</pre><p>出力されない場合は設定などの確認をしてください</p><h3>stack driverでグラフの設定をする</h3><p>stack driverのページを開く</p><p>左のサイドバーから「Dashboards」→「Create Dashboard」を選択</p><p>右上の「Add Chart」をクリック</p><p>custom/pumaと入力するとサジェストされるので見たいものを選択する</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*NslJQxYtkwr0DzqyajoCiw.png" /></figure><p>以上で一通りの流れが完了です。</p><p>メトリクスの説明についてはサジェストされた項目にカーソルを当てると見ることができます。</p><p>質問箱の開発を手伝っていただける方を随時募集中です！</p><p><a href="https://www.wantedly.com/projects/266144">100%自社開発。Peing -質問箱-サーバサイドエンジニアWANTED by 株式会社ジラフ</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d87c555f178" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GKE の限定公開クラスタに Cloud Build でデプロイする]]></title>
            <link>https://medium.com/@jiraffestaff/gke-%E3%81%AE%E9%99%90%E5%AE%9A%E5%85%AC%E9%96%8B%E3%82%AF%E3%83%A9%E3%82%B9%E3%82%BF%E3%81%AB-cloud-build-%E3%81%A7%E3%83%87%E3%83%97%E3%83%AD%E3%82%A4%E3%81%99%E3%82%8B-f2e78d1cb289?source=rss-f35760a50c9f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2e78d1cb289</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[cloud-build]]></category>
            <category><![CDATA[gke]]></category>
            <category><![CDATA[google-cloud-build]]></category>
            <dc:creator><![CDATA[株式会社ジラフ]]></dc:creator>
            <pubDate>Tue, 03 Sep 2019 06:08:09 GMT</pubDate>
            <atom:updated>2019-10-30T03:03:18.563Z</atom:updated>
            <content:encoded><![CDATA[<h3>GKE の限定公開クラスタに Cloud Build で (無理やり) デプロイする</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YZxCvBZ9TQbRpidE" /><figcaption>Photo by <a href="https://unsplash.com/@danist07?utm_source=medium&amp;utm_medium=referral">贝莉儿 NG</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>エンジニアの桂です。</p><p>Jenkins を管理し続けるのが辛くなってきたので、GCP の Cloud Build でデプロイする方法を模索しました。</p><p>基本的なデプロイはまあまあすんなり出来たんですが、限定公開クラスタ (private cluster) の IP 制限で蹴られてしまってクラスタの操作ができないという問題でどハマりしてしまいました。</p><p>結論から言うと、マスター承認済みネットワーク (master authorized networks) を動的に変更すると言うワークアラウンドで回避するのが一番簡単じゃないか、と言うところに落ち着きました。</p><h3>背景</h3><p><a href="https://stackoverflow.com/a/51978338">Stack Overflow の Google 関係者によるものと思われる回答</a>によると、</p><blockquote>It’s <strong>currently</strong> not possible to add Cloud Build machines to a VPC. Similarly, Cloud Build does not announce IP ranges of the build machines. So you can’t do this today without creating a “ssh bastion instance” or a “proxy instance” on GCE within that VPC.</blockquote><p>ということで、2018/08 時点、そしておそらく現時点 (2019/09) でも限定公開クラスタへ Cloud Build でそのままデプロイするということは不可能なようです。</p><p>bastion とか proxy インスタンス作るのは大仰だし面倒だし結構気をつけとかないと重大なセキュリティホールになるので、やりたくないですね。そこで、冒頭のワークアラウンドが候補に上がります。</p><h3>手順</h3><p>それでは、マスター承認済みネットワークを動的に変更する変更を具体的に紹介します。</p><p>通常利用する IP アドレスに加え、 Cloud Build サーバのパブリック IP を動的に取得して、 gcloud container clusters update でマスター承認ネットワークを変更しています。</p><h4>事前準備</h4><p>container.clusters.update 権限が必要なので、その権限を持つ role を Cloud Build のサービスアカウントに設定します。</p><pre>gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com --role=roles/container.clusterAdmin</pre><h4><strong>Cloud Build YAML</strong></h4><p>Cloud Build ワーカーの IP アドレスを <a href="http://inet-ip.info/">inet-ip.info</a> などを使って特定し、マスター認証済みネットワークに設定します。</p><pre>- id: permit to access to the cluster<br>  name: gcr.io/cloud-builders/gcloud<br>  entrypoint: bash<br>  args:<br>  - -c<br>  - |<br>    BUILDER_IP=$(curl inet-ip.info)<br>    gcloud container clusters update $_CLOUDSDK_CONTAINER_CLUSTER --zone $_CLOUDSDK_COMPUTE_ZONE \<br>      --enable-master-authorized-networks --master-authorized-networks=xxx.xxx.xxx.xxx/32,yyy.yyy.yyy.yyy/32,$${BUILDER_IP}/32</pre><p>許可したマスター承認済みネットワークはクラスタ操作完了後、同様の手順で元に戻しておきます。</p><h4>Pros and cons</h4><p><strong>利点</strong></p><ul><li>簡単</li></ul><p><strong>欠点</strong></p><ul><li>非限定公開クラスタよりは安全だが、やや脆弱になる</li><li>Cloud Build サービスアカウントにクラスタ操作を許可する必要がある</li><li>IP リストを GCP コンソール上から変更してもデプロイ時に上書きされる</li><li>[多分] クラスタ設定コンソールでは IP に名前をつけられるが、 gcloud ではできない</li></ul><h3>あとがき</h3><p>正直ダサいですが、近い将来きっと Google が公式の手法を提供してくれると信じたいですね。</p><p>ジラフでは GCP の beta 版に足りない機能をいい感じに工夫して解決してくれる仲間から、オフィスの雰囲気をいい感じにしてくれるメンバーまで幅広く募集してます。興味があったらぜひご連絡ください！</p><p><a href="https://recruit.jiraffe.co.jp/entry">株式会社ジラフ 採用サイト</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2e78d1cb289" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[業務未経験の僕がジラフにエンジニアとしてジョインして感じた事]]></title>
            <link>https://medium.com/@jiraffestaff/%E6%A5%AD%E5%8B%99%E6%9C%AA%E7%B5%8C%E9%A8%93%E3%81%AE%E5%83%95%E3%81%8C%E3%82%B8%E3%83%A9%E3%83%95%E3%81%AB%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E3%81%A8%E3%81%97%E3%81%A6%E3%82%B8%E3%83%A7%E3%82%A4%E3%83%B3%E3%81%97%E3%81%A6%E6%84%9F%E3%81%98%E3%81%9F%E4%BA%8B-8584a77e6919?source=rss-f35760a50c9f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8584a77e6919</guid>
            <dc:creator><![CDATA[株式会社ジラフ]]></dc:creator>
            <pubDate>Mon, 02 Sep 2019 07:19:05 GMT</pubDate>
            <atom:updated>2019-09-03T01:38:07.437Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AFljyxPL1wCpP5nn" /><figcaption>Photo by <a href="https://unsplash.com/@maxcodes?utm_source=medium&amp;utm_medium=referral">Max Nelson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>こんにちは、ジラフのヒカカク開発チーム芹澤です。</p><p>ジラフに入社させていただいて１ヶ月が経ちました。<br>Webエンジニアとしての業務は初めてで、とても毎日エキサイティングで楽しく、しかし覚えることの膨大さに会社でも家でも勉強の日々でめまいがしているひよっこエンジニアですが、チームのベテランエンジニアの方々に支えていただいてなんとかタスクをこなせている状況です。（感謝）</p><p>元々は比較的堅めの業界で新卒以来長らく働いていたのですが、ジラフに入社してからというもの、元々の会社の雰囲気と働き方の違いに驚いています。<br>そこで今回は僕がジラフに入社して受けたカルチャーショックを紹介したいと思います。</p><p><strong>・若い人がめっちゃ主体的<br></strong>これには実際目の当たりにしてすごく驚いたのですが、若い方でも主体的に働き、上流から物事を考えていることです。おぉこれが噂のWeb業界かと。典型的な年功序列制度の前の会社ではあり得ない事でした。</p><p><strong>・ ジラフレックス制度</strong></p><p>ジラフの制度として9:00〜11:00で出勤時間を選べるジラフレックスと呼ばれるフレックス制度があり、僕はその時々に合わせて使っています。<br>元々の会社では出勤時間は8:30固定でフレックス制度なんて全くなかったので、最初は変な感じでしたが、使ってみると非常に便利。普段は早めに出勤して早めに帰る方が好みですが、朝の勤務前に事前に勉強したい時や、復習したい時などに利用させてもらっています。</p><p><strong>・みんなすごく楽しそうに働いている<br></strong>実際に働いてみて思った事ですが、多くの方が楽しそうにイキイキと働いており非常にのびのびしている印象です。僕の主観としても、職場に変な圧迫感や息苦しさがなく、非常に働きやすい環境だと驚いています。</p><p><strong>・それでいて技術感度が高く、先進的な技術を使っている。<br></strong>これは入社を決めた主な理由の一つなのですが、ReactやVue.js,TypeScript,Docker,kubernetes、GCP、CI/CDツールの使用などモダンな開発環境で、かつ週に一回業務時間で社内勉強会を行なっていて、エンジニア的にはスキルを伸ばすのにとても良い環境だと思います。</p><p>なおこれは2019年現在の技術スタックで、現在進行形でモダンな技術は積極的に取り入れる文化があるので、ガンガンモダンな触れたい人にとっては良い環境だと思います。</p><p>環境の違いにまだ慣れきれていませんが、とても働きやすく成長機会も多くエンジニアの最初の一歩としてジラフは最高の環境だと感じました！<br>今回ジラフにジョインできたのは非常に幸運だったと思います。</p><p>もし少しでも興味を持った現役エンジニア、エンジニア志望のみなさん、ぜひお話だけでも聞きに来てください！</p><p><a href="https://www.wantedly.com/companies/hikakaku">https://www.wantedly.com/companies/hikakaku</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8584a77e6919" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[pre-commit レビューからpost-commit レビューに変えて結局戻した話]]></title>
            <link>https://medium.com/@jiraffestaff/pre-commit-%E3%83%AC%E3%83%93%E3%83%A5%E3%83%BC%E3%81%8B%E3%82%89post-commit-%E3%83%AC%E3%83%93%E3%83%A5%E3%83%BC%E3%81%AB%E5%A4%89%E3%81%88%E3%81%A6%E7%B5%90%E5%B1%80%E6%88%BB%E3%81%97%E3%81%9F%E8%A9%B1-eaa11a946788?source=rss-f35760a50c9f------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaa11a946788</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[peing]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[株式会社ジラフ]]></dc:creator>
            <pubDate>Tue, 02 Jul 2019 05:23:10 GMT</pubDate>
            <atom:updated>2019-07-02T05:23:10.581Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ibnfzRqKjE7XC3iXJ_oaA.jpeg" /></figure><p>Peing 質問箱の開発を担当している梅本です。</p><p>私の意思でチームのレビュー体制をpre-commit（コミット前）のレビューから post-commit（コミット後）のレビューに変更する相談を行い、納得してもらい変更をしました。</p><p>変更をしたのですが期待した結果とは異なったので戻すことになりました。</p><p>レビュー体制の変更は5月30日に行い6月29日まで実施されていました。</p><p>その意思決定や思考のプロセスをまとめます。</p><p>ちなみに、pre-commit レビューと post-commit レビューについては「pre-commit post-commit code review」で検索すると色々と見ることができます。</p><h3>Peingチームに導入した post-commit レビューのルール</h3><ul><li>レビューは週一でみんなで気になったプルリクを選んで話しあう</li><li>リリース前にレビューが欲しい人は依頼できる</li><li>データベースの変更を行う場合は必ずレビューを行う</li><li>自身のリリースでバグが発生した場合は自分でロールバックを行う</li></ul><h3>導入することによって解決をしたかったこと</h3><ol><li>自分のリリースに責任を持ってもらう</li><li>リリースの高速化</li><li>リリース前にレビューすることが必要なのか検証</li></ol><p>上記の3点です。</p><p>理由は以下にまとめます。</p><h4>自分のリリースに責任を持ってもらう</h4><p>リリース後に本番環境を確認することを期待しました。</p><p>リリース後に実装者が確認をせずバグが放置されていることがたまにありました。</p><p>これはリリースした人間が検証環境での確認とコードレビューの結果から本番環境に反映されても大丈夫と思っていることが原因と考えました。</p><p>データ量の差や検証環境では存在しないデータが本番環境にはあります。そこも悪いですが現状用意できてないです。</p><h4>リリースの高速化</h4><p>レビューを週一で行うことでレビューの時間を減らし作業に集中できることでリリースの高速化することを期待しました。</p><p>高速化されることで様々な施策を試すことが可能になり、サービスの価値を今より早く高めることができると考えました。</p><h4>リリース前にレビューすることが必要なのか検証</h4><p>今までと同じ方法で開発を進めるより様々な方法を試してその結果で開発体制を決めたいと考えています。</p><p>実施する前から決めつけるのではなく実施したことによって得た知見から判断するためです。</p><h3>導入した結果</h3><h4>良かったこと</h4><ul><li>レビューの時間が減りリリース回数が先月比で2倍に増えた</li><li>リリースに責任を持つことがどういうことか理解してもらえた</li></ul><h4>悪かったこと</h4><ul><li>バグが発生するであろうコードがマージされていた</li><li>リリース後に確認されずバグが発生している時があった</li></ul><p>リリースが増えた背景には Branch protection rule に Require branches to be up to date before merging を適用していたのですが、それを外したのでこちらの影響もあります。</p><p>一ヶ月だけの期間だったので十分な計測はできてないかもしれませんが、変更前よりも状況が悪くなっているとチームで相談した時に出てきたのでpre-commitレビューに戻すことを決めました。</p><p>私自身がやりたいことをしっかり伝えることができていなかったと反省しました。</p><p>それと同時に解決すべき問題は開発体制を変えるだけでは解決できる問題ではないことがわかりました。</p><h3>結論</h3><p>post-commitレビューを試すことができて良かったと考えています。</p><p>結果は期待したものとは違いましたが知見を増やすことはできました。</p><p>どんどん新しいものは試していきたいと考えています。</p><h4>おまけ</h4><p>新しいことにどんどん挑戦するジラフで一緒に働きませんか？</p><p>いろんなポジションの方を募集しています！</p><p>最近は関西にもオフィスがあります！</p><p>興味がある方はこちらのフォームにお願いします！</p><p><a href="https://recruit.jiraffe.co.jp/entry">株式会社ジラフ 採用サイト</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaa11a946788" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>