From e3ad19f526eb629b69ec0805b77e138852ad9154 Mon Sep 17 00:00:00 2001 From: martintomas Date: Tue, 5 Dec 2023 09:53:42 +0100 Subject: [PATCH] feat: Configure CMS to use DO bucket --- cms/config/plugins.ts | 15 +- cms/package.json | 3 +- infrastructure/base/main.tf | 5 + infrastructure/base/modules/env/main.tf | 30 +++- infrastructure/base/modules/env/variables.tf | 5 + .../base/modules/github_values/main.tf | 9 + yarn.lock | 165 +++++++++++++++++- 7 files changed, 223 insertions(+), 9 deletions(-) diff --git a/cms/config/plugins.ts b/cms/config/plugins.ts index 2a4629f..cf2b578 100644 --- a/cms/config/plugins.ts +++ b/cms/config/plugins.ts @@ -1,5 +1,5 @@ -module.exports = { +module.exports = ({env}) => ({ documentation: { config: { "x-strapi-config": { @@ -40,4 +40,15 @@ module.exports = { enabled: true, resolve: './src/plugins/map-field' }, -}; + upload: { + config: { + provider: "strapi-provider-upload-do", + providerOptions: { + key: env('DO_SPACE_ACCESS_KEY'), + secret: env('DO_SPACE_SECRET_KEY'), + endpoint: env('DO_SPACE_ENDPOINT'), + space: env('DO_SPACE_BUCKET'), + } + }, + }, +}); diff --git a/cms/package.json b/cms/package.json index d823d17..a8d6854 100644 --- a/cms/package.json +++ b/cms/package.json @@ -18,7 +18,8 @@ "@strapi/strapi": "4.11.2", "pg": "8.8.0", "strapi-plugin-import-export-entries": "^1.21.0", - "strapi-plugin-populate-deep": "^3.0.0" + "strapi-plugin-populate-deep": "^3.0.0", + "strapi-provider-upload-do": "^3.6.9" }, "devDependencies": { "typescript": "5.1.3" diff --git a/infrastructure/base/main.tf b/infrastructure/base/main.tf index 2b00545..9c7e91d 100644 --- a/infrastructure/base/main.tf +++ b/infrastructure/base/main.tf @@ -43,6 +43,10 @@ locals { CMS_URL = "${module.staging.app_url}/cms/" STRAPI_ADMIN_API_BASE_URL = "${module.staging.app_url}/cms/api" STRAPI_ADMIN_MAPBOX_ACCESS_TOKEN = var.mapbox_api_token + DO_SPACE_ACCESS_KEY = var.do_spaces_client_id + DO_SPACE_SECRET_KEY = var.do_spaces_secret_key + DO_SPACE_ENDPOINT = "https://${var.do_region}.digitaloceanspaces.com" + DO_SPACE_BUCKET = "${var.project_name}-staging-cms" # Database DATABASE_CLIENT = "postgres" @@ -90,6 +94,7 @@ module "staging" { do_app_instance_count = var.do_app_instance_count do_app_image_tag = var.do_app_image_tag do_space_name = "${var.project_name}-staging" + do_cms_space_name = "${var.project_name}-staging-cms" } resource "digitalocean_spaces_bucket_cors_configuration" "staging_cors" { diff --git a/infrastructure/base/modules/env/main.tf b/infrastructure/base/modules/env/main.tf index 27fb3e2..6a1a16e 100644 --- a/infrastructure/base/modules/env/main.tf +++ b/infrastructure/base/modules/env/main.tf @@ -1,3 +1,12 @@ +terraform { + required_providers { + digitalocean = { + source = "digitalocean/digitalocean" + version = "~> 2.0" + } + } +} + module "postgresql" { source = "../postgresql" @@ -16,7 +25,14 @@ module "space" { do_project_name = var.do_project_name do_region = var.do_region do_space_name = var.do_space_name - do_space_acl = var.do_space_acl +} + +module "space_cms" { + source = "../space" + + do_project_name = var.do_project_name + do_region = var.do_region + do_space_name = var.do_cms_space_name } module "app" { @@ -30,3 +46,15 @@ module "app" { do_app_instance_count = var.do_app_instance_count do_app_image_tag = var.do_app_image_tag } + +resource "digitalocean_spaces_bucket_cors_configuration" "space_cms_cors" { + bucket = module.space_cms.space_id + region = var.do_region + + cors_rule { + allowed_headers = ["*"] + allowed_methods = ["GET", "HEAD", "PUT", "POST", "DELETE"] + allowed_origins = ["*"] + max_age_seconds = 3000 + } +} diff --git a/infrastructure/base/modules/env/variables.tf b/infrastructure/base/modules/env/variables.tf index 8c8dc77..c5a6ccc 100644 --- a/infrastructure/base/modules/env/variables.tf +++ b/infrastructure/base/modules/env/variables.tf @@ -56,3 +56,8 @@ variable "do_space_acl" { description = "ACL rules for spaces" default = "private" } + +variable "do_cms_space_name" { + type = string + description = "Name of the space" +} diff --git a/infrastructure/base/modules/github_values/main.tf b/infrastructure/base/modules/github_values/main.tf index d3b33ff..c4c9fb4 100644 --- a/infrastructure/base/modules/github_values/main.tf +++ b/infrastructure/base/modules/github_values/main.tf @@ -1,3 +1,12 @@ +terraform { + required_providers { + digitalocean = { + source = "digitalocean/digitalocean" + version = "~> 2.0" + } + } +} + resource "github_actions_secret" "github_secret" { for_each = var.secret_map diff --git a/yarn.lock b/yarn.lock index 088fe9a..67efc3b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2196,6 +2196,7 @@ __metadata: pg: 8.8.0 strapi-plugin-import-export-entries: ^1.21.0 strapi-plugin-populate-deep: ^3.0.0 + strapi-provider-upload-do: ^3.6.9 typescript: 5.1.3 languageName: unknown linkType: soft @@ -7666,6 +7667,24 @@ __metadata: languageName: node linkType: hard +"aws-sdk@npm:2.1350.0": + version: 2.1350.0 + resolution: "aws-sdk@npm:2.1350.0" + dependencies: + buffer: 4.9.2 + events: 1.1.1 + ieee754: 1.1.13 + jmespath: 0.16.0 + querystring: 0.2.0 + sax: 1.2.1 + url: 0.10.3 + util: ^0.12.4 + uuid: 8.0.0 + xml2js: 0.4.19 + checksum: ac9989328ba714147c8086ca74528df40635b8a57caf809ae5f2c271542dd030579e227402ef0db4f013deebd25a760c1239b3cc89c1dbc4300c0c54b0cd0a3f + languageName: node + linkType: hard + "axe-core@npm:=4.7.0": version: 4.7.0 resolution: "axe-core@npm:4.7.0" @@ -7815,7 +7834,7 @@ __metadata: languageName: node linkType: hard -"base64-js@npm:^1.3.1": +"base64-js@npm:^1.0.2, base64-js@npm:^1.3.1": version: 1.5.1 resolution: "base64-js@npm:1.5.1" checksum: 669632eb3745404c2f822a18fc3a0122d2f9a7a13f7fb8b5823ee19d1d2ff9ee5b52c53367176ea4ad093c332fd5ab4bd0ebae5a8e27917a4105a4cfc86b1005 @@ -8072,6 +8091,17 @@ __metadata: languageName: node linkType: hard +"buffer@npm:4.9.2": + version: 4.9.2 + resolution: "buffer@npm:4.9.2" + dependencies: + base64-js: ^1.0.2 + ieee754: ^1.1.4 + isarray: ^1.0.0 + checksum: 8801bc1ba08539f3be70eee307a8b9db3d40f6afbfd3cf623ab7ef41dffff1d0a31de0addbe1e66e0ca5f7193eeb667bfb1ecad3647f8f1b0750de07c13295c3 + languageName: node + linkType: hard + "buffer@npm:^5.1.0, buffer@npm:^5.5.0": version: 5.7.1 resolution: "buffer@npm:5.7.1" @@ -10819,6 +10849,13 @@ __metadata: languageName: node linkType: hard +"events@npm:1.1.1": + version: 1.1.1 + resolution: "events@npm:1.1.1" + checksum: 40431eb005cc4c57861b93d44c2981a49e7feb99df84cf551baed299ceea4444edf7744733f6a6667e942af687359b1f4a87ec1ec4f21d5127dac48a782039b9 + languageName: node + linkType: hard + "events@npm:^3.2.0": version: 3.3.0 resolution: "events@npm:3.3.0" @@ -12563,7 +12600,14 @@ __metadata: languageName: node linkType: hard -"ieee754@npm:^1.1.12, ieee754@npm:^1.1.13": +"ieee754@npm:1.1.13": + version: 1.1.13 + resolution: "ieee754@npm:1.1.13" + checksum: 102df1ba662e316e6160f7ce29c7c7fa3e04f2014c288336c5a9ff40bbcc2a27d209fa2a81ebfb33f28b1941021343d30e9ad8ee85a2d61f79f5936c35edc33d + languageName: node + linkType: hard + +"ieee754@npm:^1.1.12, ieee754@npm:^1.1.13, ieee754@npm:^1.1.4": version: 1.2.1 resolution: "ieee754@npm:1.2.1" checksum: 5144c0c9815e54ada181d80a0b810221a253562422e7c6c3a60b1901154184f49326ec239d618c416c1c5945a2e197107aee8d986a3dd836b53dffefd99b5e7e @@ -12825,6 +12869,16 @@ __metadata: languageName: node linkType: hard +"is-arguments@npm:^1.0.4": + version: 1.1.1 + resolution: "is-arguments@npm:1.1.1" + dependencies: + call-bind: ^1.0.2 + has-tostringtag: ^1.0.0 + checksum: 7f02700ec2171b691ef3e4d0e3e6c0ba408e8434368504bb593d0d7c891c0dbfda6d19d30808b904a6cb1929bca648c061ba438c39f296c2a8ca083229c49f27 + languageName: node + linkType: hard + "is-array-buffer@npm:^3.0.1, is-array-buffer@npm:^3.0.2": version: 3.0.2 resolution: "is-array-buffer@npm:3.0.2" @@ -13245,7 +13299,7 @@ __metadata: languageName: node linkType: hard -"is-typed-array@npm:^1.1.10, is-typed-array@npm:^1.1.12, is-typed-array@npm:^1.1.9": +"is-typed-array@npm:^1.1.10, is-typed-array@npm:^1.1.12, is-typed-array@npm:^1.1.3, is-typed-array@npm:^1.1.9": version: 1.1.12 resolution: "is-typed-array@npm:1.1.12" dependencies: @@ -13342,7 +13396,7 @@ __metadata: languageName: node linkType: hard -"isarray@npm:1.0.0, isarray@npm:~1.0.0": +"isarray@npm:1.0.0, isarray@npm:^1.0.0, isarray@npm:~1.0.0": version: 1.0.0 resolution: "isarray@npm:1.0.0" checksum: f032df8e02dce8ec565cf2eb605ea939bdccea528dbcf565cdf92bfa2da9110461159d86a537388ef1acef8815a330642d7885b29010e8f7eac967c9993b65ab @@ -13446,6 +13500,13 @@ __metadata: languageName: node linkType: hard +"jmespath@npm:0.16.0": + version: 0.16.0 + resolution: "jmespath@npm:0.16.0" + checksum: 2d602493a1e4addfd1350ac8c9d54b1b03ed09e305fd863bab84a4ee1f52868cf939dd1a08c5cdea29ce9ba8f86875ebb458b6ed45dab3e1c3f2694503fb2fd9 + languageName: node + linkType: hard + "joi@npm:17.6.0": version: 17.6.0 resolution: "joi@npm:17.6.0" @@ -17264,6 +17325,13 @@ __metadata: languageName: node linkType: hard +"punycode@npm:1.3.2": + version: 1.3.2 + resolution: "punycode@npm:1.3.2" + checksum: b8807fd594b1db33335692d1f03e8beeddde6fda7fbb4a2e32925d88d20a3aa4cd8dcc0c109ccaccbd2ba761c208dfaaada83007087ea8bfb0129c9ef1b99ed6 + languageName: node + linkType: hard + "punycode@npm:^2.1.0": version: 2.3.1 resolution: "punycode@npm:2.3.1" @@ -17320,6 +17388,13 @@ __metadata: languageName: node linkType: hard +"querystring@npm:0.2.0": + version: 0.2.0 + resolution: "querystring@npm:0.2.0" + checksum: 8258d6734f19be27e93f601758858c299bdebe71147909e367101ba459b95446fbe5b975bf9beb76390156a592b6f4ac3a68b6087cea165c259705b8b4e56a69 + languageName: node + linkType: hard + "queue-microtask@npm:^1.2.2": version: 1.2.3 resolution: "queue-microtask@npm:1.2.3" @@ -18574,6 +18649,20 @@ __metadata: languageName: node linkType: hard +"sax@npm:1.2.1": + version: 1.2.1 + resolution: "sax@npm:1.2.1" + checksum: 8dca7d5e1cd7d612f98ac50bdf0b9f63fbc964b85f0c4e2eb271f8b9b47fd3bf344c4d6a592e69ecf726d1485ca62cd8a52e603bbc332d18a66af25a9a1045ad + languageName: node + linkType: hard + +"sax@npm:>=0.6.0": + version: 1.3.0 + resolution: "sax@npm:1.3.0" + checksum: 238ab3a9ba8c8f8aaf1c5ea9120386391f6ee0af52f1a6a40bbb6df78241dd05d782f2359d614ac6aae08c4c4125208b456548a6cf68625aa4fe178486e63ecd + languageName: node + linkType: hard + "scheduler@npm:^0.23.0": version: 0.23.0 resolution: "scheduler@npm:0.23.0" @@ -19330,6 +19419,16 @@ __metadata: languageName: node linkType: hard +"strapi-provider-upload-do@npm:^3.6.9": + version: 3.6.9 + resolution: "strapi-provider-upload-do@npm:3.6.9" + dependencies: + aws-sdk: 2.1350.0 + urijs: 1.19.6 + checksum: d23441527213b99ffebbb075bd5a2fba001894c06490677ed3368dd0083aa430aff84ea5f523446654b92750673ae97fc1dd26117fe9343dd5a6034a19a4fa8e + languageName: node + linkType: hard + "stream-chain@npm:2.2.5, stream-chain@npm:^2.2.5": version: 2.2.5 resolution: "stream-chain@npm:2.2.5" @@ -20606,6 +20705,13 @@ __metadata: languageName: node linkType: hard +"urijs@npm:1.19.6": + version: 1.19.6 + resolution: "urijs@npm:1.19.6" + checksum: 78b841e6f6a4abfad8c75e9e497fa5ea51527ea484cb24d3ac9f26338a57dcd41c10d14e11a94fe4699706350d2f03502a02ad712b3940fc6efe2178d9082f00 + languageName: node + linkType: hard + "urijs@npm:^1.19.11": version: 1.19.11 resolution: "urijs@npm:1.19.11" @@ -20627,6 +20733,16 @@ __metadata: languageName: node linkType: hard +"url@npm:0.10.3": + version: 0.10.3 + resolution: "url@npm:0.10.3" + dependencies: + punycode: 1.3.2 + querystring: 0.2.0 + checksum: 7b83ddb106c27bf9bde8629ccbe8d26e9db789c8cda5aa7db72ca2c6f9b8a88a5adf206f3e10db78e6e2d042b327c45db34c7010c1bf0d9908936a17a2b57d05 + languageName: node + linkType: hard + "use-callback-ref@npm:^1.3.0": version: 1.3.0 resolution: "use-callback-ref@npm:1.3.0" @@ -20702,6 +20818,19 @@ __metadata: languageName: node linkType: hard +"util@npm:^0.12.4": + version: 0.12.5 + resolution: "util@npm:0.12.5" + dependencies: + inherits: ^2.0.3 + is-arguments: ^1.0.4 + is-generator-function: ^1.0.7 + is-typed-array: ^1.1.3 + which-typed-array: ^1.1.2 + checksum: 705e51f0de5b446f4edec10739752ac25856541e0254ea1e7e45e5b9f9b0cb105bc4bd415736a6210edc68245a7f903bf085ffb08dd7deb8a0e847f60538a38a + languageName: node + linkType: hard + "utila@npm:~0.4": version: 0.4.0 resolution: "utila@npm:0.4.0" @@ -20723,6 +20852,15 @@ __metadata: languageName: node linkType: hard +"uuid@npm:8.0.0": + version: 8.0.0 + resolution: "uuid@npm:8.0.0" + bin: + uuid: dist/bin/uuid + checksum: 56d4e23aa7ac26fa2db6bd1778db34cb8c9f5a10df1770a27167874bf6705fc8f14a4ac414af58a0d96c7653b2bd4848510b29d1c2ef8c91ccb17429c1872b5e + languageName: node + linkType: hard + "uuid@npm:^8.3.2": version: 8.3.2 resolution: "uuid@npm:8.3.2" @@ -21097,7 +21235,7 @@ __metadata: languageName: node linkType: hard -"which-typed-array@npm:^1.1.11, which-typed-array@npm:^1.1.13, which-typed-array@npm:^1.1.9": +"which-typed-array@npm:^1.1.11, which-typed-array@npm:^1.1.13, which-typed-array@npm:^1.1.2, which-typed-array@npm:^1.1.9": version: 1.1.13 resolution: "which-typed-array@npm:1.1.13" dependencies: @@ -21272,6 +21410,23 @@ __metadata: languageName: node linkType: hard +"xml2js@npm:0.4.19": + version: 0.4.19 + resolution: "xml2js@npm:0.4.19" + dependencies: + sax: ">=0.6.0" + xmlbuilder: ~9.0.1 + checksum: ca8b2fee430d450a18947786bfd7cd1a353ee00fc6fd550acbc8a8e65f1b4df5e9786fcb2990c1a5514ecd554d445fb74e1d716b3a4fcfffc10554aeb5db482b + languageName: node + linkType: hard + +"xmlbuilder@npm:~9.0.1": + version: 9.0.7 + resolution: "xmlbuilder@npm:9.0.7" + checksum: 8193bb323806a002764f013bea0c6e9ff2dc26fd29109408761b16b59a8ad2214c2abe8e691755fd8b525586e3a0e1efeb92335947d7b0899032b779f1705a53 + languageName: node + linkType: hard + "xtend@npm:^4.0.0, xtend@npm:~4.0.1": version: 4.0.2 resolution: "xtend@npm:4.0.2"