メインコンテンツへ移動

Catalogue Website in Docker with OpenTofu

設定ファイルのリストを、Docker 上の nginx から配信する 1 ページのカタログ Web サイトに変換。「in stock」と「sold out」のラベル、設定の検証付き。

  • OpenTofu
  • Docker provider (kreuzwerker/docker)
  • HTTP provider (hashicorp/http)
  • nginx (alpine image)
  • Docker Desktop

スクリーンショット

スクリーンショット 1 / 5:Catalogue Website in Docker with OpenTofu のタイトル カード: キャッチ コピー、出力を含む実際の tofu apply の最後の部分、スマートフォンに表示したカタログ。

Catalogue Website in Docker with OpenTofu のタイトル カード: キャッチ コピー、出力を含む実際の tofu apply の最後の部分、スマートフォンに表示したカタログ。

買い切り価格

  • ₹249+GST(合計 ₹293.82)
  • $5
  • お支払いが確認されると、すぐにライブラリからダウンロードできます。
  • このプロジェクトの今後のリリースもすべて、追加費用なしで含まれます。
最新リリース
1.0.0 · 2026/11/29
ライセンス
Source Code Licence

概要

自分のコンピューター上で、terraform.tfvars の項目リストから 1 ページのカタログ Web サイトを作成し、Docker 上の nginx から配信する OpenTofu 構成の完全なソース コードです。何かを作成する前にすべての設定を検証し、項目のテキストを HTML 用にエスケープします。apply は nginx が応答するまで待ち、チェックでサイトが 200 を返すことを確認します。macOS と Docker Desktop で検証済みです。

カタログ ページを一度手で書くだけなら、すぐに済みます。しかし、変化するリストに合わせて最新の状態に保ち、名前に & 記号が含まれてもページが崩れないようにし、1 つのコマンドで起動も削除もできるようにするには、もっと手間がかかります。Catalogue Website in Docker with OpenTofu® は、まさにそれを実現する構成で、macOS と Docker Desktop での実際の実行で検証しています。

できること

  • リストからページを作成。 項目を terraform.tfvars に書き込みます。各項目には、名前、詳細行(省略可)、入手可能かどうかを指定します。ページはテンプレートから生成され、各項目の後ろに「in stock」または「sold out」のラベルが付きます。
  • 起動も削除もコマンド 1 つ。 tofu apply は公式の nginx:1.31-alpine イメージをダウンロードしてコンテナーを起動します。tofu destroy はコンテナーとイメージを削除します。
  • 文言もラベルも自由に。 タイトル、紹介文、2 つのラベルは設定で指定するため、同じコードで本、メニュー、商品など、何でも一覧にできます。
  • 既定では非公開。 サイトは 127.0.0.1:8080 で待ち受けるため、開けるのは自分のコンピューターだけです。設定を 1 つ変えれば、ネットワークに公開できます。

ミスを早く見つける設計

  • すべての設定を最初に検証。 1~200 件の項目、一意の名前、長さの制限、ポート(1024~65535)、アドレス、イメージは、何かを作成する前に検証され、それぞれにわかりやすいメッセージが表示されます。
  • テキストでページが崩れない。 すべての名前、詳細、タイトル、紹介文は HTML 用にエスケープされるため、Tea & Biscuits も書いたとおりに表示されます。
  • apply はサイトが正常になるまで待機。 コンテナー内のヘルス チェックが nginx にページを要求し、tofu apply は nginx が応答して初めて完了します。
  • apply のたびにチェック。 check ブロックがサイトにリクエストを送り、200 で応答しない場合は警告します。

拡張しやすいコード

  • 小さく読みやすい。 短い .tf ファイルが 6 つあり、それぞれが 1 つの役割を担います。加えて、templates/ にページのテンプレートとそのスタイル シートがあります。
  • 活用できる出力。 アドレス、すべての項目名、入手可能な項目の名前を出力します。
  • バージョン固定で再現可能。 OpenTofu と 2 つのプロバイダーのバージョン制約に加え、macOS(Apple silicon と Intel)、Linux(x86-64 と Arm)、Windows 用のチェックサムを含むロック ファイルがあります。
  • すべての設定を 1 つのサンプル ファイルに。 terraform.tfvars.example をコピーして、必要な部分を変更するだけです。

含まれないもの

  • ホスティングは含まれません。 サイトは自分のコンピューター上で動きます。サーバーやクラウドへの配置はお任せします。
  • HTTPS はありません。 nginx は、選んだポートで通常の HTTP を配信します。
  • ショップ機能はありません。 項目を一覧表示しますが、注文や支払いは受け付けません。

4 つの手順で実行

  1. OpenTofu 1.13 以降をインストールし、Docker を起動します。Mac では Docker Desktop の既定のソケットを有効にするか、docker_host を設定します。
  2. ダウンロードしたファイルを展開し、そのフォルダーでターミナルを開きます。
  3. tofu init、続いて tofu apply を実行し、yes と入力します。
  4. ブラウザーで http://127.0.0.1:8080/ を開きます。

How to Set Up and Run the Catalogue Website in Docker with OpenTofu (新しいタブで開きます)(英語)では、すべての手順をスクリーンショット付きで紹介しています。

コードがリストを組み立てる仕組みは、OpenTofu Tutorial — Part 5: Locals, Expressions and tofu console (新しいタブで開きます)(英語)で確認できます。これは無料の OpenTofu Tutorial for Beginners (新しいタブで開きます)(英語)の一部です。

OpenTofu® は LF Projects, LLC の登録商標です。Docker は Docker, Inc. の商標です。その他の名称は、それぞれの所有者の商標です。

無料チュートリアルシリーズ

OpenTofu Tutorial for Beginners

作りながら学びたい方へ。ブログの無料ステップガイドで、このプロジェクトの作り方を順を追って紹介しています。

シリーズを読む (新しいタブで開きます)

手に入るもの

アーカイブの中身が一目でわかります。

  • 完全なソース コードのバージョン 1.0.0: OpenTofu ファイル 6 つ、ページ テンプレート、スタイル シート
  • terraform.tfvars のリストから生成され、各項目に詳細行(省略可)と「in stock」または「sold out」のラベルが付くカタログ ページ
  • 設定の検証: 1~200 件の項目、一意の名前、長さの制限、ポート、アドレス、nginx イメージ
  • すべての名前、詳細、タイトル、紹介文の HTML エスケープ
  • ヘルス チェック付きの nginx コンテナーと、サイトが応答するまで待つ apply
  • apply のたびに、サイトが 200 で応答することを確認する check ブロック
  • アドレス、すべての項目名、入手可能な項目を示す出力
  • macOS、Linux、Windows 用のプロバイダーのチェックサムを含むロック ファイル
  • 設定のサンプル ファイル、.gitignore、.gitattributes ファイル
  • 要件、すべての設定、出力、トラブルシューティングをまとめた README

使用している技術

開発と動作確認に使った実行環境とバージョンです。

  • OpenTofu1.13.9
  • Docker provider (kreuzwerker/docker)4.7.0
  • HTTP provider (hashicorp/http)3.6.3
  • nginx (alpine image)1.31.10
  • Docker Desktop4.100.1

アーカイブの中身

展開したあとに手元に残るファイル構成です。

catalogue-website-docker-opentofu/

  • templates/
    • index.html.tftpl
    • style.css
  • .gitattributes
  • .gitignore
  • .terraform.lock.hcl
  • README.md
  • checks.tf
  • main.tf
  • outputs.tf
  • providers.tf
  • terraform.tfvars.example
  • variables.tf
  • versions.tf

必要になるもの

動かすために必要なアカウントやサービスです。あとから驚くことはありません。

  • OpenTofu 1.13 以降(2.0 未満)
  • Docker: macOS または Windows では Docker Desktop、Linux では Docker Engine
  • Mac の場合: 有効にした Docker Desktop の既定のソケット、または docker_host に設定した Docker のアドレス
  • コンピューター上の空きポート(既定は 8080)
  • 項目のリスト(書店のサンプル リスト付属)

リリース

これまでのすべてのバージョンを新しい順に並べています。

  1. 1.0.0最新

    完全なソース コードの最初のリリースです。

    • terraform.tfvars のリストから 1 ページのカタログを作成し、Docker 上の nginx 1.31 から配信します(既定は 127.0.0.1:8080)。
    • 何かを作成する前にすべての設定を検証し、項目のテキストを HTML 用にエスケープして、サイトが応答するまで待ちます。
    • ページ テンプレート、スタイル シート、設定のサンプル ファイル、macOS、Linux、Windows 用のロック ファイルを含みます。

Source Code Licence

利用できる範囲

What you may and may not do with the source code you buy.

ライセンスの全文を読む
  1. What this licence covers

This licence governs every file included in a product you buy from Dewiride Store: source code, configuration, database scripts, sample data, documentation and any other file in the download. It takes effect when your payment is confirmed and applies to every release of that product that reaches your library. Files that reach your library through an annual updates membership are governed in exactly the same way.

It forms part of the Terms of Sale and Use. Where a product page states different or additional licence terms for that product, those terms prevail for that product. The membership page may likewise state different or additional licence terms for the files a membership carries, and those terms then prevail for those files.

  1. The licence we grant you

We grant you a perpetual, worldwide, non-exclusive, non-transferable licence to use, reproduce, adapt, translate and modify the files, and to include the result in your own work, on the conditions set out below.

Perpetual means it does not expire. Worldwide means it is not limited to any country. Non-exclusive means we license the same product to other customers. Non-transferable means you cannot pass it on to someone else.

The licence is granted to you — either you personally, or the organisation you identified when buying. Everyone working within that organisation may use the files for that organisation’s projects. Nobody outside it may.

  1. What you may do
  • Use and change the files in your own projects, commercial or otherwise, with no limit on the number of projects.
  • Build a product or a service on them and charge your own customers for it.
  • Deploy the result for a client, as part of work you are doing for that client.
  • Distribute the result in compiled, deployed or otherwise non-source form.
  • Keep as many back-up copies as you reasonably need.
  • Study, observe and test how the code works, and obtain the information you need to make it work with your own software.

The last two are yours by law under sections 52(1)(aa) to (ac) of the Indian Copyright Act, 1957, and nothing in this licence is intended to take them away.

  1. What you may not do
  • Resell, sublicense, redistribute or publish the files themselves, in whole or in substantial part, in source form.
  • Include them in a template, starter kit, course, tutorial repository or component library that you sell or give away, where the code is the thing being supplied.
  • Share your account, your download links or your invoices with anyone outside your organisation.
  • Publish the files in a public repository, or in any other place where they can be obtained without buying them.
  • Remove or obscure the copyright and attribution notices in the source files.
  • Use the files to build something whose main purpose is to compete with Dewiride Store as a supplier of the same code.

The distinction that matters is simple: you may sell what you build with the code; you may not sell the code.

  1. Third-party components

Our products depend on open-source libraries, frameworks and services that we did not write. Those remain under their own licences, which we do not and cannot change. Where a product includes or requires such a component, its licence is named in the product’s documentation, and complying with it is your responsibility.

  1. Releases

Every release of a product you own is covered by this same licence and appears in your library at no extra cost. A release you have already downloaded remains licensed to you even if we later stop publishing the product. A release that reached your library through an annual updates membership is licensed to you on these same terms, and stays licensed after the period that carried it has ended.

  1. Ownership

We keep ownership of the files and of the copyright in them. You own whatever you create with them: your changes, your additions and the product you build are yours.

  1. If this licence ends

This licence ends if you materially breach it and do not put the breach right within thirty days of us asking you to in writing. It also ends if your payment is reversed or refunded, because the purchase it depends on no longer stands. Where a membership period is refunded or reversed, the licence ends for the releases that period carried and for nothing else: anything you bought separately, or that another period carried, is unaffected.

If it ends, you must stop using the files and delete the copies you hold. Work you had already delivered to a client before that point may continue in use, so that ending this licence never breaks something your own customer relies on.

  1. No warranty beyond the description

The warranties and limits in section 19 and section 20 of the Terms of Sale and Use apply to this licence as well.

  1. Governing law

This licence is governed by the law of India, and section 24 of the Terms of Sale and Use applies to any dispute about it. If a translation and the English version differ in meaning, the English version governs.