From 19887efd222ac8ed40338a28d2c09ba765b51a77 Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Thu, 16 Mar 2023 21:14:39 -0700 Subject: [PATCH] auto upload website to DO bucket --- Makefile | 9 ++++++--- infra/main/main.tf | 45 +++++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 0883f3c..d65a1d6 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ KEYS := \ default: \ toolchain \ $(patsubst %,$(KEY_DIR)/%.asc,$(KEYS)) \ - $(OUT_DIR)/.well-known/openpgpkey \ + $(OUT_DIR)/website/.well-known/openpgpkey \ apply .PHONY: @@ -29,10 +29,10 @@ credentials: \ $(KEY_DIR)/%.asc: $(call fetch_pgp_key,$(basename $(notdir $@))) -$(OUT_DIR)/.well-known/openpgpkey: +$(OUT_DIR)/website/.well-known/openpgpkey: $(call toolchain," \ sq wkd \ - generate $(OUT_DIR) distrust.co \ + generate $(OUT_DIR)/website distrust.co \ <(cat $(patsubst %,$(KEY_DIR)/%.asc,$(KEYS))) \ ") @@ -71,6 +71,9 @@ apply: \ $(OUT_DIR)/terraform \ infra/main/.terraform env -C infra/main $(TERRAFORM) apply \ + -var environment=$(ENVIRONMENT) \ + -var namespace=$(ENVIRONMENT) \ + -var region=$(REGION) \ -var-file ../../$< $(CACHE_DIR)/secrets: diff --git a/infra/main/main.tf b/infra/main/main.tf index fd7564e..63309a1 100644 --- a/infra/main/main.tf +++ b/infra/main/main.tf @@ -1,28 +1,25 @@ -# Create local directories as scratch space -resource "local_file" "openpgpkey" { - filename = ".well-known/openpgpkey/policy" - content = "" -} -resource "local_file" "hu" { - filename = ".well-known/openpgpkey/hu/.keep" - content = "" - depends_on = [local_file.openpgpkey] -} -resource "local_file" "static_dir" { - filename = "static/.keep" - content = "" +variable "environment" {} +variable "namespace" {} +variable "region" {} +variable "out_dir" { + type = string + default = "/home/build/out" } -# Create local files as scratch space -resource "local_file" "policy" { - filename = ".well-known/openpgpkey/policy" - content = "" - depends_on = [local_file.openpgpkey] +resource "random_id" "suffix" { + byte_length = 8 } -# Upload files to Digital Ocean -## The Digital Ocean Spaces API is compatible with Amazon S3 -# resource "local_exec" "s3cmd" { -# command = "s3cmd put --recursive --acl-public --guess-mime-type --verbose static/ s3://static-site/" -# depends_on = [local_file.index_html, local_file.static_dir] -# } \ No newline at end of file +resource "digitalocean_spaces_bucket" "website" { + name = "website-${random_id.suffix.hex}" + region = var.region +} + +resource "digitalocean_spaces_bucket_object" "website" { + for_each = fileset("${var.out_dir}/website", "*") + region = var.region + bucket = digitalocean_spaces_bucket.website.name + source = "${var.out_dir}/website/${each.value}" + key = each.value + etag = filemd5("${var.out_dir}/website/${each.value}") +}