From 051beaa8fd828145a97a5dddc96f7a01b979e839 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Wed, 25 Oct 2023 08:17:28 -0400 Subject: [PATCH] feat: deploy bankless.community to cloudflare pages (#27) * Add cloudflare pages * Fix README (there is no Makefile so `make` doesn't work) * Fix cloudflare pages formatting using pre-commit * Convert plaintext secrets to senstive variables --- .gitignore | 3 ++ README.md | 17 +++++-- .../cloudflare/.terraform.lock.hcl | 24 --------- bankless-community/cloudflare/pages.tf | 51 +++++++++++++++++++ bankless-community/cloudflare/providers.tf | 2 +- bankless-community/cloudflare/variables.tf | 4 ++ 6 files changed, 72 insertions(+), 29 deletions(-) delete mode 100644 bankless-community/cloudflare/.terraform.lock.hcl create mode 100644 bankless-community/cloudflare/pages.tf diff --git a/.gitignore b/.gitignore index 00237ad..ac9ada7 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ override.tf.json # IDE dirs .idea/ + +# python +venv/ diff --git a/README.md b/README.md index fdbd3c6..146d64e 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,21 @@ We're currently using Root First structure, meaning each folder contains a compl ├──── cloudflare # Contains DNS Records for BanklessCard.xyz └── README.md +## Prerequisites + +* [Terraform](https://www.terraform.io/downloads.html) +* [pre-commit](https://pre-commit.com/) + +Make sure you have `pre-commit`, and `terraform` in your `$PATH`. + ## Terraform Cloud All infrastructure changes will automatically plan but require approval from infosec.bankless.community memeber. ## pre-commit -This repo uses Yelp's [pre-commit](https://pre-commit.com/) to manage some pre-commit hooks automatically. -In order to use the hooks, make sure you have `pre-commit`, and `terraform` in your `$PATH`. -Once in your path you should run `make` in order to configure it. If you push commits that fail pre-commit, your PR will -not pass tests +Configure pre-commit hooks before making changes. +If you push commits that fail pre-commit, your PR will not pass tests. + +```bash +pre-commit install +``` diff --git a/bankless-community/cloudflare/.terraform.lock.hcl b/bankless-community/cloudflare/.terraform.lock.hcl deleted file mode 100644 index 689a8aa..0000000 --- a/bankless-community/cloudflare/.terraform.lock.hcl +++ /dev/null @@ -1,24 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/cloudflare/cloudflare" { - version = "3.24.0" - constraints = "3.24.0" - hashes = [ - "h1:S6jnHPGYgTIa/8xh0BN5xt+snOvyYn7D1HX6nAnCFdE=", - "zh:190408c7f17a4bcb6eef4faaf3cbcd7bc71ffe2da0bae53bf198267b386e1eca", - "zh:2a17671e6d567c488c4b748a318ff3a49ce5a395b2a850ce18327ac110f24ca4", - "zh:2d00a73e3baa3c620d10cdc448c04210c11d3dbdfc7b327d225cb9e37c760d65", - "zh:328238bb6541b7373ffb499826def6a5105a23f4362d275aea08f4be18a5456b", - "zh:360c01f73fb1aae93021957fcd384cda7f675d77918ff29563644d2cced5537c", - "zh:4a8a8b81429d25c8480fac90bae06132b0be3d506941b14cbc383ce71a66e7b5", - "zh:62991a8f5eab1d30ffdfe2ef440cda200230ca39338df478ef26f1da7ea7b13b", - "zh:7c8b54bebd905cdc995a77665f7ea2fe9a416446c78a7630b79c66eb4285ae61", - "zh:8ba7d300a3a01d71ff932674b8669ce4c06ca6e6b1ad4bc6814decde0885292c", - "zh:95277d0edd3caab4ba47becf6aecbc27df25df6f3a630972efa4626d38fa570f", - "zh:cef1d2f45d731e60fca9bf42eafdc4a3e78954882c4d1f26f8e4bf985db854ce", - "zh:e9724344b49945fcbb87f336c958c0fbb00fe524c1cb59545417f81a442b43d9", - "zh:ed314269d7e343c84433d285f6865191441b706a35ee2083f4d1f454aa33d06f", - "zh:feaa86c9f0101ae10eb7491f262ed85e9d7a235763faec6e143a5563747dd4af", - ] -} diff --git a/bankless-community/cloudflare/pages.tf b/bankless-community/cloudflare/pages.tf new file mode 100644 index 0000000..cdeaf61 --- /dev/null +++ b/bankless-community/cloudflare/pages.tf @@ -0,0 +1,51 @@ +resource "cloudflare_pages_project" "deployment_configs" { + account_id = local.cloudflare_account_id + name = local.cloudflare_account_name + production_branch = "main" + + source { + type = "github" + config { + owner = local.cloudflare_account_name + repo_name = "bankless-website" + production_branch = "main" + pr_comments_enabled = true + deployments_enabled = true + production_deployment_enabled = true + preview_deployment_setting = "all" + } + } + + build_config { + build_command = "npx next build" + destination_dir = "out" + root_dir = "" + } + + deployment_configs { + preview { + environment_variables = { + ENVIRONMENT = "preview" + } + secrets = { + NEXT_PUBLIC_ALCHEMY_API_KEY = var.alchemy_api_key + NEXT_PUBLIC_BLOCKNATIVE_API_KEY = var.blocknative_api_key + NEXT_PUBLIC_INFURA_PROJECT_ID = var.infura_project_id + NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID = var.walletconnect_project_id + } + always_use_latest_compatibility_date = true + } + production { + environment_variables = { + ENVIRONMENT = "production" + } + secrets = { + NEXT_PUBLIC_ALCHEMY_API_KEY = var.alchemy_api_key + NEXT_PUBLIC_BLOCKNATIVE_API_KEY = var.blocknative_api_key + NEXT_PUBLIC_INFURA_PROJECT_ID = var.infura_project_id + NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID = var.walletconnect_project_id + } + always_use_latest_compatibility_date = true + } + } +} diff --git a/bankless-community/cloudflare/providers.tf b/bankless-community/cloudflare/providers.tf index 89f6ff4..ff07858 100644 --- a/bankless-community/cloudflare/providers.tf +++ b/bankless-community/cloudflare/providers.tf @@ -2,7 +2,7 @@ terraform { required_providers { cloudflare = { source = "cloudflare/cloudflare" - version = "3.24.0" + version = "4.9.0" } } } diff --git a/bankless-community/cloudflare/variables.tf b/bankless-community/cloudflare/variables.tf index 0838897..b0009e4 100644 --- a/bankless-community/cloudflare/variables.tf +++ b/bankless-community/cloudflare/variables.tf @@ -1,3 +1,7 @@ variable "cloudflare_api_token" { sensitive = true } +variable "alchemy_api_key" { sensitive = true } +variable "blocknative_api_key" { sensitive = true } +variable "infura_project_id" { sensitive = true } +variable "walletconnect_project_id" { sensitive = true }