From 347a52f71ff6c0c96a3246e539d9455a52fedbb1 Mon Sep 17 00:00:00 2001 From: Brian Heise Date: Sat, 22 Jun 2024 19:58:55 +0900 Subject: [PATCH 01/13] move extra index content to index.md and enable japanese --- static-site/config.toml | 49 ++------------------------------ static-site/content/_index.jp.md | 27 +++++++++--------- static-site/content/_index.md | 26 +++++++++-------- static-site/templates/index.html | 9 +++--- 4 files changed, 35 insertions(+), 76 deletions(-) diff --git a/static-site/config.toml b/static-site/config.toml index 52f43a2..b2eec5a 100644 --- a/static-site/config.toml +++ b/static-site/config.toml @@ -1,57 +1,12 @@ -# The URL the site will be built for base_url = "https://www.tokyorust.org" - -# Whether to automatically compile all Sass files in the sass directory compile_sass = true - -# Whether to build a search index to be used later on by a JavaScript library build_search_index = true - default_language = "en" [markdown] -# Whether to do syntax highlighting -# Theme can be customised by setting the `highlight_theme` variable to a theme supported by Zola highlight_code = true +[languages.jp] + [extra] -# Put all your custom variables here events_page_link = "https://www.meetup.com/tokyo-rust-meetup/" - -# about_us = """\ -# We are a voluntary organization (任意団体) based in Tokyo, Japan. \ -# Our mission is to maintain and grow an English-speaking community of Rust users and enthusiasts. \ -# We do our best to accommodate Japanese speakers, although our default language is English. \ -# Rustaceans of all skill levels are welcome to join our ranks! \ -# """ -[extra.jp] -about_us = """\ -私たちは、日本の東京に拠点を置く任意団体です。 \ -私たちの使命は、Rust ユーザーと愛好家の英語圏コミュニティを維持し、成長させることです。 \ -デフォルト言語は英語ですが、日本語話者に対応できるよう最善を尽くします。 \ -あらゆるスキルレベルのRustaceanが私たちのランクに加わることを歓迎します! -""" -join_next_event = "Join our next event!" - -[[extra.jp.card]] -title = "titleeeeeeeeee" -content = "content" - -[extra.en] -about_us = """\ - a community of people who share your interest in the Rust programming language! -""" -join_next_event = "Join our next event!" -cards_header = "Monthly Presentations" - -[[extra.en.card]] -title = "Expand Your Knowledge" -content = "Learn more about the language itself, programming practices, and projects." - -[[extra.en.card]] -title = "Meet Likeminded People" -content = "Socialize other Rust enthusiasts and developers, share ideas, and make friends." - -[[extra.en.card]] -title = "Free Food and Drinks" -content = "Each event includes free pizza and beer." diff --git a/static-site/content/_index.jp.md b/static-site/content/_index.jp.md index 97d4941..bd43c4e 100644 --- a/static-site/content/_index.jp.md +++ b/static-site/content/_index.jp.md @@ -2,20 +2,21 @@ title = "東京ラスト" [extra] -# about_us = """\ -# Join a community of people who share your interest in the Rust programming language! -# """ -# extra.jp.join_next_event = "Join oussssssssssssssr next event!" +about_us = """\ +Rust プログラミング言語への興味を共有する人々のコミュニティです。 +""" +join_next_event = "次のイベントにご参加ください!" +cards_header = "月例プレゼンテーション" -# [[extra.landing_cards]] -# title = "aa" -# content = "aa" +[[extra.card]] +title = "知識を広げる" +content = "言語自体、プログラミングの実践、プロジェクトについて詳しく学びます。" -# [[extra.landing_cards]] -# title = "" -# content = "" +[[extra.card]] +title = "同じ志を持つ人々と出会う" +content = "他の Rust 愛好家や開発者と交流し、アイデアを共有し、友達を作りましょう。" -# [[extra.landing_cards]] -# title = "" -# content = "" +[[extra.card]] +title = "無料の食べ物と飲み物" +content = "各イベントには無料のピザとビールが含まれます。" +++ \ No newline at end of file diff --git a/static-site/content/_index.md b/static-site/content/_index.md index c539129..ea2ed48 100644 --- a/static-site/content/_index.md +++ b/static-site/content/_index.md @@ -2,19 +2,21 @@ title = "Tokyo Rust" [extra] +about_us = """\ +A community of people who share your interest in the Rust programming language! +""" +join_next_event = "Join our next event!" +cards_header = "Monthly Presentations" +[[extra.card]] +title = "Expand Your Knowledge" +content = "Learn more about the language itself, programming practices, and projects." -# [[extra.landing_cards]] -# title = "aa" -# content = "aa" - -# [[extra.landing_cards]] -# title = "" -# content = "" - -# [[extra.landing_cards]] -# title = "" -# content = "" - +[[extra.card]] +title = "Meet Likeminded People" +content = "Socialize other Rust enthusiasts and developers, share ideas, and make friends." +[[extra.card]] +title = "Free Food and Drinks" +content = "Each event includes free pizza and beer." +++ \ No newline at end of file diff --git a/static-site/templates/index.html b/static-site/templates/index.html index 664caca..8c2baba 100644 --- a/static-site/templates/index.html +++ b/static-site/templates/index.html @@ -4,11 +4,12 @@

{{ section.title }}

-

{{ config.extra[lang].about_us }}

+ +

{{ section.extra.about_us }}

@@ -16,9 +17,9 @@

{{ section.t
-

{{ config.extra[lang].cards_header }}

+

{{ section.extra.cards_header }}

- {% for card in config.extra[lang].card %} + {% for card in section.extra.card %} {{ macros::landing_card(title=card.title, content=card.content) }} {% endfor %}
From b6379b8ce68e44e34faac3dc1b326af4199f771b Mon Sep 17 00:00:00 2001 From: Brian Heise Date: Sun, 23 Jun 2024 10:17:36 +0900 Subject: [PATCH 02/13] move hardcoded text to config --- static-site/config.toml | 52 +++++++++++++++++++++++++- static-site/content/_index.jp.md | 4 +- static-site/templates/base.html | 34 +++++++++-------- static-site/templates/footer.html | 49 +++++------------------- static-site/templates/macros.tera.html | 8 ++++ static-site/templates/navbar.html | 19 ++++------ 6 files changed, 95 insertions(+), 71 deletions(-) diff --git a/static-site/config.toml b/static-site/config.toml index b2eec5a..b189326 100644 --- a/static-site/config.toml +++ b/static-site/config.toml @@ -2,11 +2,61 @@ base_url = "https://www.tokyorust.org" compile_sass = true build_search_index = true default_language = "en" +title = "Tokyo Rust" +description = """ +We are an English-speaking community of Rust users and enthusiasts. +Rustaceans of all skill levels are welcome to join our ranks! +""" [markdown] highlight_code = true +[translations] [languages.jp] +title = "東京Rust" +description = """ +私たちは、Rust ユーザーと愛好家が集まる英語を話すコミュニティです。 +あらゆるスキルレベルのRustaceanが私たちのランクに加わることを歓迎します! +""" [extra] -events_page_link = "https://www.meetup.com/tokyo-rust-meetup/" +events_page_link = "https://guild.host/tokyo-rust/events/upcoming/" +donate_link = "https://donate.stripe.com/test_14k1731CJ4GK4YodQQ/" +tokyo_rust_icon = "/tokyo-rust-outline-opt.svg" + +[[extra.socials]] +name = "meetup" +icon = "/meetup.svg" +url = "https://www.meetup.com/tokyo-rust-meetup/" + +[[extra.socials]] +name = "youtube" +icon = "/youtube.svg" +url = "https://www.youtube.com/@tokyo-rust-org" + +[[extra.socials]] +name = "guildhost" +icon = "/guild-host.png" +url = "https://guild.host/tokyo-rust" + +[[extra.socials]] +name = "github" +icon = "/github-icon.png" +url = "https://github.com/tokyo-rust" + +[[extra.socials]] +name = "linkedin" +icon = "/linkedin-icon.png" +url = "https://www.linkedin.com/company/99059952" + +[extra.translations.en] +home = "Home" +events = "Events" +donate = "Donate" +commercial_disclosure = "Commercial Disclosure" + +[extra.translations.jp] +home = "ホーム" +events = "イベント" +donate = "寄付" +commercial_disclosure = "特定商取引法に基づく表記" diff --git a/static-site/content/_index.jp.md b/static-site/content/_index.jp.md index bd43c4e..da1aed1 100644 --- a/static-site/content/_index.jp.md +++ b/static-site/content/_index.jp.md @@ -1,11 +1,11 @@ +++ -title = "東京ラスト" +title = "東京Rust" [extra] about_us = """\ Rust プログラミング言語への興味を共有する人々のコミュニティです。 """ -join_next_event = "次のイベントにご参加ください!" +join_next_event = "次のイベントにご参!" cards_header = "月例プレゼンテーション" [[extra.card]] diff --git a/static-site/templates/base.html b/static-site/templates/base.html index aa66bd8..83a75fb 100644 --- a/static-site/templates/base.html +++ b/static-site/templates/base.html @@ -1,20 +1,22 @@ {% import "macros.tera.html" as macros %} - - - - - - Tokyo Rust - - - {% include "navbar.html" %} -
-
{% block content %} {% endblock %}
-
- {% include "footer.html" %} - - - + + + + + + {{ config.title }} + + + + {% include "navbar.html" %} +
+
{% block content %} {% endblock %}
+
+ {% include "footer.html" %} + + + + \ No newline at end of file diff --git a/static-site/templates/footer.html b/static-site/templates/footer.html index 82465d3..d4476f2 100644 --- a/static-site/templates/footer.html +++ b/static-site/templates/footer.html @@ -1,50 +1,19 @@ - \ No newline at end of file diff --git a/static-site/templates/macros.tera.html b/static-site/templates/macros.tera.html index cb48088..3068fff 100644 --- a/static-site/templates/macros.tera.html +++ b/static-site/templates/macros.tera.html @@ -21,3 +21,11 @@
{{ title }}
{{ url }}index.html {%- endif -%} {% endmacro get_url -%} + +{% macro social_link(name, url, icon) %} +
  • + + {{ name }} icon + +
  • +{% endmacro social_link %} \ No newline at end of file diff --git a/static-site/templates/navbar.html b/static-site/templates/navbar.html index 5853078..5b60b95 100644 --- a/static-site/templates/navbar.html +++ b/static-site/templates/navbar.html @@ -8,22 +8,17 @@
    - + \ No newline at end of file From a5045125a85a2ff89d2c7e0065eb6a7f693fab61 Mon Sep 17 00:00:00 2001 From: Brian Heise Date: Sun, 23 Jun 2024 10:20:38 +0900 Subject: [PATCH 03/13] remove trailing slash on stripe donate link --- static-site/config.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static-site/config.toml b/static-site/config.toml index b189326..0f5defd 100644 --- a/static-site/config.toml +++ b/static-site/config.toml @@ -21,7 +21,7 @@ description = """ [extra] events_page_link = "https://guild.host/tokyo-rust/events/upcoming/" -donate_link = "https://donate.stripe.com/test_14k1731CJ4GK4YodQQ/" +donate_link = "https://donate.stripe.com/test_14k1731CJ4GK4YodQQ" tokyo_rust_icon = "/tokyo-rust-outline-opt.svg" [[extra.socials]] From ba7507eca8736b264acbb86ae4b964ae94b2dd35 Mon Sep 17 00:00:00 2001 From: Brian Heise Date: Sun, 23 Jun 2024 10:39:30 +0900 Subject: [PATCH 04/13] add ci a action to build site and test links when PR is opened --- .github/actions/build-static.yaml | 23 ++++++++++++++++++++ .github/actions/check-links.yaml | 12 +++++++++++ .github/workflows/ci.yaml | 22 +++++++++++++++++++ .github/workflows/publish_static.yaml | 31 ++++----------------------- 4 files changed, 61 insertions(+), 27 deletions(-) create mode 100644 .github/actions/build-static.yaml create mode 100644 .github/actions/check-links.yaml create mode 100644 .github/workflows/ci.yaml diff --git a/.github/actions/build-static.yaml b/.github/actions/build-static.yaml new file mode 100644 index 0000000..0688ff9 --- /dev/null +++ b/.github/actions/build-static.yaml @@ -0,0 +1,23 @@ +name: Build Static Site +description: Build the Tokyo Rust static website +runs: + using: composite + steps: + - name: Install Zola + id: install-zola + uses: taiki-e/install-action@v2 + with: + tool: zola@0.17.2 + + - name: Setup Node + id: setup-node + uses: actions/setup-node@v4 + + - name: Install Node Packages + id: install-node-packages + run: cd static-site && npm install + + - name: Build Static Site + id: build-static-site + working-directory: ./static-site + run: zola build diff --git a/.github/actions/check-links.yaml b/.github/actions/check-links.yaml new file mode 100644 index 0000000..056f24c --- /dev/null +++ b/.github/actions/check-links.yaml @@ -0,0 +1,12 @@ +name: Test Static Site Links +description: Test a built static site locally (not the deployed version) +runs: + using: composite + steps: + - name: Check Links + id: lychee + uses: lycheeverse/lychee-action@v1 + with: + args: --base ./static-site/public ./static-site/public + jobSummary: true + fail: true diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..1fd8c34 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,22 @@ +name: Build Site and Test Links +on: + workflow_dispatch: + pull_request: + branches: + - main + paths: + - static-site/** + +jobs: + deploy: + name: Build and Test Links + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Build The Site + id: build + uses: "./.github/actions/build-static" + + - name: Check Links + id: lychee + uses: "./.github/actions/check-links" diff --git a/.github/workflows/publish_static.yaml b/.github/workflows/publish_static.yaml index f3fa679..fa37edf 100644 --- a/.github/workflows/publish_static.yaml +++ b/.github/workflows/publish_static.yaml @@ -13,36 +13,13 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: - - name: Checkout - uses: actions/checkout@v4 - id: checkout - - - name: Install Zola - id: install-zola - uses: taiki-e/install-action@v2 - with: - tool: zola@0.17.2 - - - name: Setup Node - id: setup-node - uses: actions/setup-node@v4 - - - name: Install Node Packages - id: install-node-packages - run: cd static-site && npm install - - - name: Build Static Site - id: build-static-site - working-directory: ./static-site - run: zola build + - name: Build The Site + id: build + uses: "./.github/actions/build-static" - name: Check Links id: lychee - uses: lycheeverse/lychee-action@v1 - with: - args: --base ./static-site/public ./static-site/public - jobSummary: true - fail: true + uses: "./.github/actions/check-links" - name: Configure AWS Credentials id: configure-aws-creds From 4d3da29909034cd8e93dec771c8991a2849042cf Mon Sep 17 00:00:00 2001 From: Brian Heise Date: Sun, 23 Jun 2024 10:43:10 +0900 Subject: [PATCH 05/13] fix naming --- .github/actions/{build-static.yaml => build-static/action.yaml} | 0 .github/actions/{check-links.yaml => check-links/action.yaml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/actions/{build-static.yaml => build-static/action.yaml} (100%) rename .github/actions/{check-links.yaml => check-links/action.yaml} (100%) diff --git a/.github/actions/build-static.yaml b/.github/actions/build-static/action.yaml similarity index 100% rename from .github/actions/build-static.yaml rename to .github/actions/build-static/action.yaml diff --git a/.github/actions/check-links.yaml b/.github/actions/check-links/action.yaml similarity index 100% rename from .github/actions/check-links.yaml rename to .github/actions/check-links/action.yaml From 1e6e44788e3428a4611cee9cd9e427e2d6b4632b Mon Sep 17 00:00:00 2001 From: Brian Heise Date: Sun, 23 Jun 2024 10:45:46 +0900 Subject: [PATCH 06/13] add checkout --- .github/workflows/ci.yaml | 4 ++++ .github/workflows/publish_static.yaml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1fd8c34..61bdcac 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,6 +13,10 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: + - name: Checkout + uses: actions/checkout@v4 + id: checkout + - name: Build The Site id: build uses: "./.github/actions/build-static" diff --git a/.github/workflows/publish_static.yaml b/.github/workflows/publish_static.yaml index fa37edf..ed5a121 100644 --- a/.github/workflows/publish_static.yaml +++ b/.github/workflows/publish_static.yaml @@ -13,6 +13,10 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: + - name: Checkout + uses: actions/checkout@v4 + id: checkout + - name: Build The Site id: build uses: "./.github/actions/build-static" From 84cc6b3a64cb23d3ca113898758d78828de60725 Mon Sep 17 00:00:00 2001 From: Brian <31160338+toadslop@users.noreply.github.com> Date: Sun, 23 Jun 2024 10:47:27 +0900 Subject: [PATCH 07/13] Update action.yaml --- .github/actions/build-static/action.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/build-static/action.yaml b/.github/actions/build-static/action.yaml index 0688ff9..52bf417 100644 --- a/.github/actions/build-static/action.yaml +++ b/.github/actions/build-static/action.yaml @@ -2,6 +2,7 @@ name: Build Static Site description: Build the Tokyo Rust static website runs: using: composite + shell: bash steps: - name: Install Zola id: install-zola From 7698ee6a08ed2e71b2d13f5d0b7d8005c564c96a Mon Sep 17 00:00:00 2001 From: Brian <31160338+toadslop@users.noreply.github.com> Date: Sun, 23 Jun 2024 10:47:44 +0900 Subject: [PATCH 08/13] Update action.yaml --- .github/actions/check-links/action.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/check-links/action.yaml b/.github/actions/check-links/action.yaml index 056f24c..a36622d 100644 --- a/.github/actions/check-links/action.yaml +++ b/.github/actions/check-links/action.yaml @@ -2,6 +2,7 @@ name: Test Static Site Links description: Test a built static site locally (not the deployed version) runs: using: composite + shell: bash steps: - name: Check Links id: lychee From a4ac63b2a54767389edb9ffc565edd3e0de82630 Mon Sep 17 00:00:00 2001 From: Brian <31160338+toadslop@users.noreply.github.com> Date: Sun, 23 Jun 2024 10:49:35 +0900 Subject: [PATCH 09/13] Update action.yaml --- .github/actions/build-static/action.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/build-static/action.yaml b/.github/actions/build-static/action.yaml index 52bf417..b3ae9aa 100644 --- a/.github/actions/build-static/action.yaml +++ b/.github/actions/build-static/action.yaml @@ -2,7 +2,6 @@ name: Build Static Site description: Build the Tokyo Rust static website runs: using: composite - shell: bash steps: - name: Install Zola id: install-zola @@ -16,9 +15,11 @@ runs: - name: Install Node Packages id: install-node-packages + shell: bash run: cd static-site && npm install - name: Build Static Site id: build-static-site + shell: bash working-directory: ./static-site run: zola build From 14a619241e8a67036b3558486c86b8afd198fa29 Mon Sep 17 00:00:00 2001 From: Brian <31160338+toadslop@users.noreply.github.com> Date: Sun, 23 Jun 2024 10:49:47 +0900 Subject: [PATCH 10/13] Update action.yaml --- .github/actions/check-links/action.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/check-links/action.yaml b/.github/actions/check-links/action.yaml index a36622d..056f24c 100644 --- a/.github/actions/check-links/action.yaml +++ b/.github/actions/check-links/action.yaml @@ -2,7 +2,6 @@ name: Test Static Site Links description: Test a built static site locally (not the deployed version) runs: using: composite - shell: bash steps: - name: Check Links id: lychee From 0dd25f7252c42effef8551b991a2141e9842da2b Mon Sep 17 00:00:00 2001 From: Brian <31160338+toadslop@users.noreply.github.com> Date: Sun, 23 Jun 2024 10:52:07 +0900 Subject: [PATCH 11/13] Update action.yaml --- .github/actions/check-links/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/check-links/action.yaml b/.github/actions/check-links/action.yaml index 056f24c..b3b433a 100644 --- a/.github/actions/check-links/action.yaml +++ b/.github/actions/check-links/action.yaml @@ -7,6 +7,6 @@ runs: id: lychee uses: lycheeverse/lychee-action@v1 with: - args: --base ./static-site/public ./static-site/public + args: --accept 200,429 --base ./static-site/public ./static-site/public jobSummary: true fail: true From 4186cbcc3f95990085b693699a1cd5fce1a9a475 Mon Sep 17 00:00:00 2001 From: 38911BytesFree <38911BytesFree@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:17:07 +0900 Subject: [PATCH 12/13] Updates to enable tokyorust.org URL - renamed terraform s3 bucket resource tokyo-rust www_tokyorust - added a new s3 resource root_tokyorust configured to redirect to www.tokyorust.org - added an A record to route53 for the root domain --- infrastructure/static-site.tf | 58 +++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/infrastructure/static-site.tf b/infrastructure/static-site.tf index 4599b88..11160ed 100644 --- a/infrastructure/static-site.tf +++ b/infrastructure/static-site.tf @@ -6,7 +6,7 @@ locals { domain_name = "www.${local.host_name}" } -resource "aws_s3_bucket" "tokyo-rust" { +resource "aws_s3_bucket" "www_tokyorust" { bucket = local.domain_name tags = { @@ -15,8 +15,25 @@ resource "aws_s3_bucket" "tokyo-rust" { } } +resource "aws_s3_bucket" "root_tokyorust" { + bucket = local.host_name + + tags = { + tokyorust = "" + static = "" + } +} + + resource "aws_s3_bucket_website_configuration" "example" { + bucket = aws_s3_bucket.root_tokyorust.id + + redirect_all_requests_to { + host_name = "${local.domain_name}" + } +} + resource "aws_s3_bucket_policy" "cloudfront_access_policy" { - bucket = aws_s3_bucket.tokyo-rust.id + bucket = aws_s3_bucket.www_tokyorust.id policy = data.aws_iam_policy_document.allow_cloudfront_read_access.json } @@ -36,8 +53,8 @@ data "aws_iam_policy_document" "allow_cloudfront_read_access" { effect = "Allow" resources = [ - aws_s3_bucket.tokyo-rust.arn, - "${aws_s3_bucket.tokyo-rust.arn}/*", + aws_s3_bucket.www_tokyorust.arn, + "${aws_s3_bucket.www_tokyorust.arn}/*", ] condition { @@ -63,7 +80,7 @@ resource "aws_cloudfront_origin_access_identity" "tokyorust" { resource "aws_cloudfront_distribution" "s3_distribution" { origin { - domain_name = aws_s3_bucket.tokyo-rust.bucket_domain_name + domain_name = aws_s3_bucket.www_tokyorust.bucket_domain_name origin_id = local.s3_origin_id origin_access_control_id = aws_cloudfront_origin_access_control.tokyorust.id @@ -72,7 +89,7 @@ resource "aws_cloudfront_distribution" "s3_distribution" { # } } - aliases = [local.domain_name] + aliases = [local.domain_name, local.host_name] restrictions { geo_restriction { @@ -86,6 +103,7 @@ resource "aws_cloudfront_distribution" "s3_distribution" { } enabled = true + comment = "CloudFront distribution for ${local.domain_name}" default_root_object = "index.html" http_version = "http2" is_ipv6_enabled = true @@ -104,7 +122,7 @@ resource "aws_cloudfront_distribution" "s3_distribution" { default_ttl = 86400 max_ttl = 31536000 cache_policy_id = aws_cloudfront_cache_policy.tokyorust.id - } + } price_class = "PriceClass_200" @@ -115,7 +133,7 @@ resource "aws_cloudfront_distribution" "s3_distribution" { } resource "aws_cloudfront_cache_policy" "tokyorust" { - name = "tokyo-tust-static-site-cache-policy" + name = "tokyo-rust-static-site-cache-policy" parameters_in_cache_key_and_forwarded_to_origin { cookies_config { @@ -140,7 +158,7 @@ resource "aws_route53_zone" "tokyorust" { } } -resource "aws_route53_record" "tokyorust" { +resource "aws_route53_record" "www_tokyorust" { zone_id = aws_route53_zone.tokyorust.id name = local.domain_name type = "A" @@ -151,6 +169,17 @@ resource "aws_route53_record" "tokyorust" { } } +resource "aws_route53_record" "root_tokyorust" { + zone_id = aws_route53_zone.tokyorust.id + name = local.host_name + type = "A" + alias { + name = aws_cloudfront_distribution.s3_distribution.domain_name + zone_id = aws_cloudfront_distribution.s3_distribution.hosted_zone_id + evaluate_target_health = false + } +} + resource "aws_iam_policy" "tokyorust-static-deployer" { name = "tokyo-rust-static-deployer" description = "Necessary permissions to deploy the Tokyo Rust static site" @@ -170,8 +199,10 @@ resource "aws_iam_policy" "tokyorust-static-deployer" { "s3:DeleteObject" ], Resource = [ - "${aws_s3_bucket.tokyo-rust.arn}", - "${aws_s3_bucket.tokyo-rust.arn}/*", + "${aws_s3_bucket.www_tokyorust.arn}", + "${aws_s3_bucket.www_tokyorust.arn}/*", + "${aws_s3_bucket.root_tokyorust.arn}", + "${aws_s3_bucket.root_tokyorust.arn}/*", ] }, { @@ -179,7 +210,8 @@ resource "aws_iam_policy" "tokyorust-static-deployer" { Effect = "Allow", Action = [ "cloudfront:GetInvalidation", - "cloudfront:CreateInvalidation"], + "cloudfront:CreateInvalidation" + ], Resource = "*" } ] @@ -202,7 +234,7 @@ resource "aws_iam_user_policy_attachment" "tokyorust-static-deployer" { } resource "aws_s3_bucket_website_configuration" "tokyorust" { - bucket = aws_s3_bucket.tokyo-rust.id + bucket = aws_s3_bucket.www_tokyorust.id index_document { suffix = "index.html" From 9b4fdc983da29dd145fd141cbebdd5a64e6d1bb8 Mon Sep 17 00:00:00 2001 From: 38911BytesFree <38911BytesFree@users.noreply.github.com> Date: Mon, 22 Jul 2024 20:34:14 +0900 Subject: [PATCH 13/13] Updates to enable tokyorust.org URL - removed the resource "aws_iam_policy" "tokyorust-static-deployer" - renamed s3_distribution to www_distribution - created a second cloudfront root_distribution for the tokyorust.org bucket - added a bucket policy for the tokyorust.org bucket - updated the route53 entry for tokyorust.org to point to the new distribution --- infrastructure/static-site.tf | 160 ++++++++++++++++++++++------------ 1 file changed, 103 insertions(+), 57 deletions(-) diff --git a/infrastructure/static-site.tf b/infrastructure/static-site.tf index 11160ed..f53a077 100644 --- a/infrastructure/static-site.tf +++ b/infrastructure/static-site.tf @@ -24,7 +24,7 @@ resource "aws_s3_bucket" "root_tokyorust" { } } - resource "aws_s3_bucket_website_configuration" "example" { + resource "aws_s3_bucket_website_configuration" "root_tokyorust" { bucket = aws_s3_bucket.root_tokyorust.id redirect_all_requests_to { @@ -32,12 +32,7 @@ resource "aws_s3_bucket" "root_tokyorust" { } } -resource "aws_s3_bucket_policy" "cloudfront_access_policy" { - bucket = aws_s3_bucket.www_tokyorust.id - policy = data.aws_iam_policy_document.allow_cloudfront_read_access.json -} - -data "aws_iam_policy_document" "allow_cloudfront_read_access" { +data "aws_iam_policy_document" "www_tokyorust_allow_cloudfront_read_access" { version = "2012-10-17" statement { actions = [ @@ -60,12 +55,51 @@ data "aws_iam_policy_document" "allow_cloudfront_read_access" { condition { test = "StringEquals" variable = "aws:SourceArn" - values = [aws_cloudfront_distribution.s3_distribution.arn] + values = [aws_cloudfront_distribution.www_distribution.arn] } } } +data "aws_iam_policy_document" "root_tokyorust_allow_cloudfront_read_access" { + version = "2012-10-17" + statement { + actions = [ + "s3:GetObject", + "s3:ListBucket", + ] + + principals { + type = "Service" + identifiers = ["cloudfront.amazonaws.com"] + } + + effect = "Allow" + + resources = [ + aws_s3_bucket.root_tokyorust.arn, + "${aws_s3_bucket.root_tokyorust.arn}/*", + ] + + condition { + test = "StringEquals" + variable = "aws:SourceArn" + values = [aws_cloudfront_distribution.root_distribution.arn] + } + + } +} + +resource "aws_s3_bucket_policy" "www_tokyorust_cloudfront_access_policy" { + bucket = aws_s3_bucket.www_tokyorust.id + policy = data.aws_iam_policy_document.www_tokyorust_allow_cloudfront_read_access.json +} + +resource "aws_s3_bucket_policy" "root_tokyorust_cloudfront_access_policy" { + bucket = aws_s3_bucket.root_tokyorust.id + policy = data.aws_iam_policy_document.root_tokyorust_allow_cloudfront_read_access.json +} + resource "aws_cloudfront_origin_access_control" "tokyorust" { name = "Tokyo-Rust-Access" description = "The access control for the Tokyo Rust website." @@ -78,7 +112,7 @@ resource "aws_cloudfront_origin_access_identity" "tokyorust" { comment = "Access identity for Tokyo Rust static site" } -resource "aws_cloudfront_distribution" "s3_distribution" { +resource "aws_cloudfront_distribution" "www_distribution" { origin { domain_name = aws_s3_bucket.www_tokyorust.bucket_domain_name origin_id = local.s3_origin_id @@ -89,7 +123,7 @@ resource "aws_cloudfront_distribution" "s3_distribution" { # } } - aliases = [local.domain_name, local.host_name] + aliases = [local.domain_name] restrictions { geo_restriction { @@ -132,6 +166,61 @@ resource "aws_cloudfront_distribution" "s3_distribution" { } } +resource "aws_cloudfront_distribution" "root_distribution" { + origin { + domain_name = aws_s3_bucket_website_configuration.root_tokyorust.website_endpoint + origin_id = local.s3_origin_id + + custom_origin_config { + origin_protocol_policy = "http-only" + http_port = "80" + https_port = "443" + origin_ssl_protocols = ["TLSv1.2"] + } + + # s3_origin_config { + # origin_access_identity = aws_cloudfront_origin_access_identity.tokyorust.cloudfront_access_identity_path + # } + } + + aliases = [local.host_name] + + restrictions { + geo_restriction { + restriction_type = "none" + } + } + + viewer_certificate { + acm_certificate_arn = local.ssl_cert_arn + ssl_support_method = "sni-only" + } + + enabled = true + comment = "CloudFront distribution for ${local.host_name}" + default_root_object = "index.html" + http_version = "http2" + is_ipv6_enabled = true + + default_cache_behavior { + compress = true + viewer_protocol_policy = "redirect-to-https" + cached_methods = ["GET", "HEAD"] + target_origin_id = local.s3_origin_id + allowed_methods = ["GET", "HEAD"] + default_ttl = 86400 + max_ttl = 31536000 + cache_policy_id = aws_cloudfront_cache_policy.tokyorust.id + } + + price_class = "PriceClass_200" + + tags = { + tokyorust = "" + static = "" + } +} + resource "aws_cloudfront_cache_policy" "tokyorust" { name = "tokyo-rust-static-site-cache-policy" @@ -163,8 +252,8 @@ resource "aws_route53_record" "www_tokyorust" { name = local.domain_name type = "A" alias { - name = aws_cloudfront_distribution.s3_distribution.domain_name - zone_id = aws_cloudfront_distribution.s3_distribution.hosted_zone_id + name = aws_cloudfront_distribution.www_distribution.domain_name + zone_id = aws_cloudfront_distribution.www_distribution.hosted_zone_id evaluate_target_health = false } } @@ -174,50 +263,12 @@ resource "aws_route53_record" "root_tokyorust" { name = local.host_name type = "A" alias { - name = aws_cloudfront_distribution.s3_distribution.domain_name - zone_id = aws_cloudfront_distribution.s3_distribution.hosted_zone_id + name = aws_cloudfront_distribution.root_distribution.domain_name + zone_id = aws_cloudfront_distribution.root_distribution.hosted_zone_id evaluate_target_health = false } } -resource "aws_iam_policy" "tokyorust-static-deployer" { - name = "tokyo-rust-static-deployer" - description = "Necessary permissions to deploy the Tokyo Rust static site" - - policy = jsonencode({ - Version = "2012-10-17", - Statement = [ - { - Sid = "AccessToWebsiteBuckets", - Effect = "Allow", - Action = [ - "s3:PutBucketWebsite", - "s3:PutObject", - "s3:PutObjectAcl", - "s3:GetObject", - "s3:ListBucket", - "s3:DeleteObject" - ], - Resource = [ - "${aws_s3_bucket.www_tokyorust.arn}", - "${aws_s3_bucket.www_tokyorust.arn}/*", - "${aws_s3_bucket.root_tokyorust.arn}", - "${aws_s3_bucket.root_tokyorust.arn}/*", - ] - }, - { - Sid = "AccessToCloudfront", - Effect = "Allow", - Action = [ - "cloudfront:GetInvalidation", - "cloudfront:CreateInvalidation" - ], - Resource = "*" - } - ] - }) -} - resource "aws_iam_user" "tokyorust-static-deployer" { name = "tokyorust-static-deployer" path = "/" @@ -228,11 +279,6 @@ resource "aws_iam_user" "tokyorust-static-deployer" { } } -resource "aws_iam_user_policy_attachment" "tokyorust-static-deployer" { - user = aws_iam_user.tokyorust-static-deployer.name - policy_arn = aws_iam_policy.tokyorust-static-deployer.arn -} - resource "aws_s3_bucket_website_configuration" "tokyorust" { bucket = aws_s3_bucket.www_tokyorust.id