NUTMEG
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 20230320_NUTMEGにステージング環境を導入する (例:20210901_LT会を開催しました) ###### tags: `ブログ記事` - [x] 公開(ブログ公開担当者がいじるやつ) 太字斜体で書いてある内容を埋めて行ってください. 文章,画像は太字斜体の下の行に入れてください. 最初に書く時はREADMEを読んだら読むといいと思います. <br> ## 表示されない情報 ***書いた人の名前(自己紹介文と同じ名前)*** { つさば } ***記事の簡単な説明(検索した時にタイトルの下に出てくる文章)*** { NUTMEGのプロダクトメンバーが誰でも簡単に立ち上げられるステージング環境をCloudflared(Cloudflare Argo Tunnel)を使用して構築しました。DockerコンテナとDocker Composeを使用することで簡単に環境を立ち上げられます。これはNUTMEGインフラチームが悩まされていた開発・本番環境差異で起こるバグ問題の解決に貢献します。 } <br> ## 表示される部分 ***サムネイル画像*** { ![](https://i.imgur.com/nvEYIDn.jpg) } ***カテゴリ*** 以下の中から該当しそうなカテゴリを選択してください ※一つだけ選択してください - [ ] 対外活動 - [x] 活動の様子 - [ ] メンバーの趣味 ***タグ*** 以下の中から該当しそうなカテゴリを選択してください.当てはまる物がない場合は適宜追加してください. 言語 - [ ] HTML - [ ] CSS - [ ] Python - [ ] Go - [ ] Ruby - [ ] JavaScript - [ ] TypeScript - [ ] Dart - [ ] Rust - [ ] Kotlin - [ ] Swift フレームワーク・ライブラリ - [ ] Ruby on rails - [ ] Vue.js - [ ] Nuxt.js - [ ] React.js - [ ] Next.js - [ ] Gin - [ ] Flluter ツール - [ ] GitHub - [ ] ターミナル - [ ] WSL - [ ] Ubuntu - [x] Docker - [ ] Raspberry Pi - [ ] Figma 分野 - [ ] Web-design - [ ] API関係 --- ***以下に本文を記載してください*** こんにちは。 NUTMEGでNUTMEGクラウドの開発・運用を行っているM1大浦です。 これまでNUTMEGでの開発を円滑に進めるために様々なインフラ開発を行ってきました。その中でも,最近行った「簡易的なステージング環境を構築した話」について紹介させていただきます。 # ステージング環境とは ステージング環境とはシステム開発において最終的なテストを行う環境のことです。 リリースに向けて本番を想定した環境を用意し,実際に使ってみることでバグが存在しないことを確認します。ステージング環境で問題が発生しないことを確認出来たら本番環境にデプロイを行います。 簡単に言うとリハーサル会場のようなものです。 # 導入経緯 これまでのNUTMEGには,テスト環境やステージング環境がなく,開発環境とデプロイ環境の差異により,問題が起きることが多くありました。そのたびNUTMEGインフラチームは時間を削ってインシデント対応を行うというのがいつもの流れでした。 ステージング環境やテスト環境を作ることで,この問題は解決できますが,それを運用するためにインフラチームの負担が増えるのは本末転倒です。 そこで,「NUTMEGのプロダクトメンバー自身が簡単に立ち上げられるステージング環境があれば」と思い立ったのが経緯です。 # 使用技術 ステージング環境の立ち上げには**Cloudflared**(旧 Cloudflare Argo Tunnel)を使用しました。 ![cloudflared](https://i.imgur.com/qXbqNWw.png) Cloudflaredは,Cloudflareのネットワークとの間にトンネルを作成するツールです。これにより,自身のサーバーのポートを開放せずに公開することが可能となっています。 NUTMEGのプロダクトはほぼすべて,`Docker`,`Docker Compose`を使用しており,開発者は`docker compose up`のコマンドで開発環境の立ち上げを行っています。 Cloudflaredが同時に立ち上がる`docker-compose.stage.yml`を作成することで,開発環境を立ち上げるのと同じ労力でステージング環境を立ち上げることができます。 開発者の労力はそのまま,インフラチームのインシデント対応が減ってみんなハッピーというのが思い描く**新時代**です。 # 構築方法 最初の構築はすこし大変ですが,一度行ってしまえばどこの誰でもステージング環境を立ち上げることができます。 楽するために努力するは私の座右の銘です。 がんばりましょう。 ## ステージング用のdocker-composeファイルを作成 NUTMEGでは開発に`Docker`,`Docker Compose`を使用しています。 既存の`docker-compose.yml`を参考に`docker-compose.stage.yml`を作成し,cloudflareのサービスを追加します。 設定項目は以下の通りです。 - `cloudflare/cloudflared:latest` コンテナを使用 - `./cloudflare/stage`を作成 - `/home/nonroot/.cloudflared`にマウント - 起動時にtunnelを起動 `docker-compose.stage.yml` ```yaml version: '3' services: cloudflare: image: 'cloudflare/cloudflared:latest' container_name: "cloudflare" volumes: ['./cloudflare/stage:/home/nonroot/.cloudflared'] command: tunnel run service-1: ... service-2: ... service-3: ... ``` ここで`./cloudflare/stage`ディレクトリをDockerユーザーでも書き込み可能にしておきます。 ``` chmod o+rwx ./cloudflare/stage/ ``` ## Cloudflareの設定 あとはcloudflareの設定です。 ### ログイン cloudflare.com に移動しログインします。 ここではアカウント作成手順は省略します。 ### cloudflareを認証 以下のコマンドを入力し,立ち上げるcloudflareコンテナを認証します。 ```bash= docker compose -f docker-compose.stage.yml run --rm cloudflare tunnel login ``` コマンドを入力するとログインURLが表示されるのでログイン。 ``` # 出力 Please open the following URL and log in with your Cloudflare account: https://dash.cloudflare.com/argotunnel... Leave cloudflared running to download the cert automatically. ... ``` URLの先に飛ぶと以下の画面に遷移し,使用したいドメインで認証。 ![](https://i.imgur.com/rOynYak.png) 以上でcloudflareの認証が完了します。 認証情報は`./cloudflare/stage/cert.pem`に保存されます。 ### Tunnelの作成 次にトンネルを作成します。 名前通りコンテナとClouflareをつなぐトンネルです。 これによって,外部からのアクセスを可能にします。 今回はNUTMEGで開発しているgroup-manager-2のステージング環境を作成するため,`<tunnel-name>`は`gm2-stg`という名前に設定しました。 ```bash= docker compose -f docker-compose.stage.yml run --rm cloudflare tunnel create <tunnel-name> ``` 以上が正常に完了すると`./cloudflare/stage/<tunnel-id>.json`が保存されます。 ### DNS・リバースプロキシの設定 最後にDNS・リバースプロキシの設定です。 `cloudflare/stage/config.yml`に設定ファイルを作成します。 `hostname`に対して接続するサービスを指定します。 > 例:service-1.stg.nutfes.net にアクセスすると`docker-compose.stage.yml`の`service-1`の8080番ポートに飛ぶ。 `cloudflare/stage/config.yml` ```yaml= tunnel: <tunnel-id> credentials-file: /home/nonroot/.cloudflared/<tunnel-id>.json protocol: http2 ingress: - hostname: service-1.stg.nutfes.net service: http://service-1:8080 - hostname: service-2.stg.nutfes.net service: http://service-2:8000 - hostname: service-3.stg.nutfes.net service: http://service-3:3000 - service: http_status:404 ``` configで設定したすべてのhostmameに対して以下のコマンドを実行し,CloudflareのDNSを設定します。 ```bash= docker compose -f docker-compose.stage.yml run --rm cloudflare tunnel route dns <tunnel-name> <hostname(example.hoge.net)> ``` ## 起動 以上の設定を済ませてしまえば,今後は以下コマンドで起動するだけです。 ```bash= docker compose -f docker-compose.stage.yml up ``` うまくできていれば以下のログが確認できるはずです。 ```bash INF Connection <tunnel-id> registered with protocol: http2 ``` ブラウザで`<hostname>`を確認してみるとちゃんと表示できますね。 ![](https://i.imgur.com/OoKUV0U.png) ## 最後に 以上がNUTMEGにステージング環境を導入した経緯とその方法でした。 NUTMEGのでの開発→デプロイのプロセスがスムーズになり,バグ対応も迅速化されることに期待します。 私たちNUTMEGインフラチームはNUTMEGメンバーが**使いやすいインフラ**を構築することを目標として日々活動しています。今後も使いやすいインフラを目指して,様々な技術に挑戦していきたいと思います。

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully