From ebf4a8687c7d705ac72340b85ad1ed05c79682d6 Mon Sep 17 00:00:00 2001 From: billmetangmo <25366207+billmetangmo@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:09:45 +0000 Subject: [PATCH] feat: add demo again --- .github/workflows/deploy_push.yml | 2 +- infra/api/lambda.py | 21 ++++ infra/main.tf | 48 +++++--- infra/templates/demo.tmpl | 175 ++++++++++++++++++++++++++++++ 4 files changed, 227 insertions(+), 19 deletions(-) create mode 100644 infra/templates/demo.tmpl diff --git a/.github/workflows/deploy_push.yml b/.github/workflows/deploy_push.yml index 45db91a3..b1f99ad9 100644 --- a/.github/workflows/deploy_push.yml +++ b/.github/workflows/deploy_push.yml @@ -139,7 +139,7 @@ jobs: if: github.ref_name != 'master' run: | cd infra - aws s3 sync ../html s3://mtchoun-mouh-$GITHUB_REF_NAME-mtchoun-mouh.mongulu.cm --exclude "index.html" --delete + aws s3 sync ../html s3://mtchoun-mouh-$GITHUB_REF_NAME-mtchoun-mouh.mongulu.cm --exclude "index.html" --exclude "demo.html" --delete - name: "website: check readiness" uses: APina03/wait_for_response@master with: diff --git a/infra/api/lambda.py b/infra/api/lambda.py index 52f94d78..0b86c716 100644 --- a/infra/api/lambda.py +++ b/infra/api/lambda.py @@ -52,6 +52,27 @@ def register_handler(event, context): } ), } + + else: + + os.environ['LINKS_TABLE'] = "Links" + Scan_reponse = Scan_Users(name.lower(), "Users") + image_url = Scan_reponse[0]["URLImage"] + print(image_url) + + return { + "statusCode": 200, + "headers": { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Headers": "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token", + "Access-Control-Allow-Methods": "GET,OPTIONS,POST,PUT", + }, + "body": json.dumps( + { + "message": f" {image_url}", + } + ), + } except Exception as e: capture_exception(e) raise diff --git a/infra/main.tf b/infra/main.tf index a08c576d..2dfe2b80 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -1,5 +1,22 @@ locals { requirements_path = "api/requirements.txt" + url = join("/", [aws_api_gateway_deployment.test.invoke_url, aws_api_gateway_resource.resource.path_part]) + + demo_page = templatefile("templates/demo.tmpl", { + url = local.url + contact = var.MAINTAINER_MAIL + }) + + index_page = templatefile("templates/index.tmpl", { + url = local.url + contact = var.MAINTAINER_MAIL + }) + + terratag_added_main = { "environment" = "mtchoun-mouh-master", "project" = "mtchoun-mouh" } + + # If your backend is not Terraform Cloud, the value is ${terraform.workspace} + # otherwise the value retrieved is that of the TFC_WORKSPACE_NAME with trimprefix + workspace = var.TFC_WORKSPACE_NAME != "" ? trimprefix("${var.TFC_WORKSPACE_NAME}", "mtchoun-mouh-") : "${terraform.workspace}" } resource "aws_s3_bucket" "images" { @@ -266,19 +283,9 @@ resource "aws_api_gateway_deployment" "test" { stage_name = (terraform.workspace == "mtchoun-mouh-master") ? var.stage_name : "${terraform.workspace}-${var.stage_name}" } -locals { - - url = join("/", [aws_api_gateway_deployment.test.invoke_url, aws_api_gateway_resource.resource.path_part]) - - index_page = templatefile("templates/index.tmpl", { - url = local.url - contact = var.MAINTAINER_MAIL - }) - - # If your backend is not Terraform Cloud, the value is ${terraform.workspace} - # otherwise the value retrieved is that of the TFC_WORKSPACE_NAME with trimprefix - workspace = var.TFC_WORKSPACE_NAME != "" ? trimprefix("${var.TFC_WORKSPACE_NAME}", "mtchoun-mouh-") : "${terraform.workspace}" - +resource "local_file" "demo_page" { + content = local.demo_page + filename = "../html/demo.html" } resource "local_file" "index_page" { @@ -287,7 +294,7 @@ resource "local_file" "index_page" { } // Terraform cloud have the file but the CI no so we upload it from terraform cloud -resource "aws_s3_bucket_object" "example_file" { +resource "aws_s3_bucket_object" "index_page" { bucket = aws_s3_bucket.website.id key = "index.html" source = "../html/index.html" @@ -296,6 +303,15 @@ resource "aws_s3_bucket_object" "example_file" { depends_on = [local_file.index_page] } +resource "aws_s3_bucket_object" "demo_page" { + bucket = aws_s3_bucket.website.id + key = "demo.html" + source = "../html/demo.html" + content_type = "text/html" + + depends_on = [local_file.demo_page] +} + # Inspired from https://frama.link/GFCHrjEL module "cors" { source = "squidfunk/api-gateway-enable-cors/aws" @@ -324,7 +340,3 @@ resource "aws_lambda_permission" "allow_cloudwatch_to_call_check_foo" { principal = "events.amazonaws.com" source_arn = aws_cloudwatch_event_rule.scheduler.arn } - -locals { - terratag_added_main = { "environment" = "mtchoun-mouh-master", "project" = "mtchoun-mouh" } -} diff --git a/infra/templates/demo.tmpl b/infra/templates/demo.tmpl new file mode 100644 index 00000000..8cbe906f --- /dev/null +++ b/infra/templates/demo.tmpl @@ -0,0 +1,175 @@ + + + + + + + + + + + + Mtchoun' mouh + + + + + + + +
+
+ Logo cameroun +
+

Si vous êtes là c'est que vous voulez une démonstration. Pas de soucis 🙂

+

Nous vous proposons donc de choisir un nom au hasard dans le communiqué du 22/09/2020. + Pour cela rien de plus simple: rendez vous juste sur la page du consulat + et entrez ci-dessous celui-ci choisi. +

+ NOTEZ BIEN + + + +
+ + + +

Retournez en page d'accueil

+ +
+ Logo cameroun +
+

© 2020 - Contact

+
+ + + + + \ No newline at end of file