From d1bf3545f939fb644e13ec4b884019177a904d56 Mon Sep 17 00:00:00 2001 From: bluecco Date: Mon, 4 Nov 2024 16:14:37 +0100 Subject: [PATCH 1/3] chore: .env for releases --- .env.dev | 4 ++++ .env.hydrogen | 4 ++++ .env.prod | 4 ++++ .env.staging | 5 +++++ 4 files changed, 17 insertions(+) create mode 100644 .env.dev create mode 100644 .env.hydrogen create mode 100644 .env.prod create mode 100644 .env.staging diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..8e27843 --- /dev/null +++ b/.env.dev @@ -0,0 +1,4 @@ +# Development +NODE_ENV=production +NEXT_PUBLIC_WEB_WALLET_URL=https://web-v2.hydrogen.argent47.net +NEXT_PUBLIC_CHAIN_ID=SN_SEPOLIA \ No newline at end of file diff --git a/.env.hydrogen b/.env.hydrogen new file mode 100644 index 0000000..0ee7b44 --- /dev/null +++ b/.env.hydrogen @@ -0,0 +1,4 @@ +# Hydrogen +NODE_ENV=production +NEXT_PUBLIC_WEB_WALLET_URL=https://web-v2.hydrogen.argent47.net +NEXT_PUBLIC_CHAIN_ID=SN_SEPOLIA \ No newline at end of file diff --git a/.env.prod b/.env.prod new file mode 100644 index 0000000..e29ff66 --- /dev/null +++ b/.env.prod @@ -0,0 +1,4 @@ +# Main +NODE_ENV=production +NEXT_PUBLIC_WEB_WALLET_URL=https://web.argent.xyz +NEXT_PUBLIC_CHAIN_ID=SN_MAIN \ No newline at end of file diff --git a/.env.staging b/.env.staging new file mode 100644 index 0000000..43d5772 --- /dev/null +++ b/.env.staging @@ -0,0 +1,5 @@ +# Staging + +NODE_ENV=production +NEXT_PUBLIC_WEB_WALLET_URL=https://web-v2.staging.argent47.net +NEXT_PUBLIC_CHAIN_ID=SN_MAIN \ No newline at end of file From 1746cc3a721a81590715404bf8bb20f2cc3a4f88 Mon Sep 17 00:00:00 2001 From: bluecco Date: Mon, 4 Nov 2024 16:17:00 +0100 Subject: [PATCH 2/3] chore: infra files --- Jenkinsfile.infra | 62 +++++++++++++++++++++++++++ infrastructure/.terraform-version | 1 + infrastructure/amplify.tf | 62 +++++++++++++++++++++++++++ infrastructure/config/dev.tfvars | 5 +++ infrastructure/config/hydrogen.tfvars | 5 +++ infrastructure/config/prod.tfvars | 6 +++ infrastructure/config/staging.tfvars | 5 +++ infrastructure/main.tf | 50 +++++++++++++++++++++ infrastructure/variables.tf | 10 +++++ 9 files changed, 206 insertions(+) create mode 100644 Jenkinsfile.infra create mode 100644 infrastructure/.terraform-version create mode 100644 infrastructure/amplify.tf create mode 100644 infrastructure/config/dev.tfvars create mode 100644 infrastructure/config/hydrogen.tfvars create mode 100644 infrastructure/config/prod.tfvars create mode 100644 infrastructure/config/staging.tfvars create mode 100644 infrastructure/main.tf create mode 100644 infrastructure/variables.tf diff --git a/Jenkinsfile.infra b/Jenkinsfile.infra new file mode 100644 index 0000000..48f6b3a --- /dev/null +++ b/Jenkinsfile.infra @@ -0,0 +1,62 @@ +pipeline { + agent { + docker { + image 'hashicorp/terraform:1.9' + args '--entrypoint=""' + } + } + + parameters { + credentials( + name: 'AWS_CREDENTIALS', + credentialType: 'com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsImpl', + description: 'AWS Credentials', + required: true + ) + + choice(name: 'TYPE', choices: ['plan', 'apply'], description: 'Plan or Apply') + } + + stages { + stage('Execute Terraform') { + steps { + dir("infrastructure/") { + withFolderProperties { + withCredentials([string(credentialsId: "webwallet-github-token", variable: 'WEBWALLET_GITHUB_TOKEN'), + string(credentialsId: "gsap-npm-token", variable: 'GSAP_NPM_TOKEN')]) { + withAWS(region: "eu-west-1", credentials: '${AWS_CREDENTIALS}', role: "${AWS_INFRA_DEPLOY_ROLE}", roleAccount: "${AWS_INFRA_ACCOUNT_ID}") { + ansiColor('xterm') { + sh "rm -rf .terraform/" + sh "terraform init" + sh "terraform workspace select ${ENVIRONMENT}" + sh "terraform init" + script{ + + if (params.TYPE == 'plan') { + echo "You selected plan!" + sh """ + terraform plan \ + -var-file=config/${ENVIRONMENT}.tfvars \ + -var 'github_token=$WEBWALLET_GITHUB_TOKEN' \ + -var 'gsap_npm_token=$GSAP_NPM_TOKEN' + """ + } + if (params.TYPE == 'apply') { + echo "You selected apply!" + sh """ + terraform apply -auto-approve \ + -var-file=config/${ENVIRONMENT}.tfvars \ + -var 'github_token=$WEBWALLET_GITHUB_TOKEN' \ + -var 'gsap_npm_token=$GSAP_NPM_TOKEN' + """ + } + } + } + } + } + } + } + } + } + } +} diff --git a/infrastructure/.terraform-version b/infrastructure/.terraform-version new file mode 100644 index 0000000..6f2d365 --- /dev/null +++ b/infrastructure/.terraform-version @@ -0,0 +1 @@ +1.9.2 \ No newline at end of file diff --git a/infrastructure/amplify.tf b/infrastructure/amplify.tf new file mode 100644 index 0000000..bc98b15 --- /dev/null +++ b/infrastructure/amplify.tf @@ -0,0 +1,62 @@ +resource "aws_amplify_app" "app" { + name = "demo-dapp-starknet-${var.environment}" + repository = "https://github.com/argentlabs/demo-dapp-starknet" + access_token = var.github_token + platform = "WEB_COMPUTE" + + build_spec = <<-EOT + version: 1 + frontend: + phases: + preBuild: + commands: + - nvm install $VERSION_NODE_20 + - nvm use $VERSION_NODE_20 + - corepack enable && corepack enable pnpm + - pnpm config set //npm.greensock.com/:_authToken=$GSAP_NPM_TOKEN + - pnpm install + - pnpm config delete //npm.greensock.com/:_authToken=$GSAP_NPM_TOKEN + build: + commands: + - pnpm build:${var.environment} + artifacts: + baseDirectory: .next + files: + - '**/*' + cache: + paths: + - node_modules/**/* + - .next/cache/**/* + EOT + + + enable_auto_branch_creation = false + + environment_variables = merge({ + for k, v in { + _CUSTOM_IMAGE = "amplify:al2023", + GSAP_NPM_TOKEN = var.gsap_npm_token, + } : k => v if v != null + }) +} + +resource "aws_amplify_branch" "branch" { + app_id = aws_amplify_app.app.id + branch_name = var.branch + + display_name = terraform.workspace + framework = "Next.js - SSR" + + enable_auto_build = true + enable_performance_mode = var.enable_performance_mode +} + +resource "aws_amplify_domain_association" "domain_association" { + app_id = aws_amplify_app.app.id + domain_name = "${var.domain_name}" + + sub_domain { + branch_name = aws_amplify_branch.branch.branch_name + prefix = "gift" + } +} diff --git a/infrastructure/config/dev.tfvars b/infrastructure/config/dev.tfvars new file mode 100644 index 0000000..9535424 --- /dev/null +++ b/infrastructure/config/dev.tfvars @@ -0,0 +1,5 @@ +workspace_iam_role = "arn:aws:iam::694716557937:role/TerraformRole" + +branch = "develop" +environment = "dev" +domain_name = "dev.argent47.net" diff --git a/infrastructure/config/hydrogen.tfvars b/infrastructure/config/hydrogen.tfvars new file mode 100644 index 0000000..90e3431 --- /dev/null +++ b/infrastructure/config/hydrogen.tfvars @@ -0,0 +1,5 @@ +workspace_iam_role = "arn:aws:iam::551208209252:role/TerraformRole" + +branch = "hydrogen" +environment = "hydrogen" +domain_name = "hydrogen.argent47.net" diff --git a/infrastructure/config/prod.tfvars b/infrastructure/config/prod.tfvars new file mode 100644 index 0000000..861daf2 --- /dev/null +++ b/infrastructure/config/prod.tfvars @@ -0,0 +1,6 @@ +workspace_iam_role = "arn:aws:iam::372157827898:role/TerraformRole" + +branch = "main" +environment = "prod" +domain_name = "argent.xyz" +enable_performance_mode = "true" diff --git a/infrastructure/config/staging.tfvars b/infrastructure/config/staging.tfvars new file mode 100644 index 0000000..7792eb7 --- /dev/null +++ b/infrastructure/config/staging.tfvars @@ -0,0 +1,5 @@ +workspace_iam_role = "arn:aws:iam::911160948013:role/TerraformRole" + +branch = "staging" +environment = "staging" +domain_name = "staging.argent47.net" diff --git a/infrastructure/main.tf b/infrastructure/main.tf new file mode 100644 index 0000000..56f852b --- /dev/null +++ b/infrastructure/main.tf @@ -0,0 +1,50 @@ +terraform { + required_version = ">= 1.9" + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.58" + } + } + + backend "s3" { + bucket = "terraform.infra.eu-west-1.argent47.net" + workspace_key_prefix = "workspace-demo-dapp-starknet" + key = "tfstate.json" + dynamodb_table = "argent-infra-terraform" + region = "eu-west-1" + } +} + +data "terraform_remote_state" "main" { + backend = "s3" + + workspace = terraform.workspace + + config = { + bucket = "terraform.infra.eu-west-1.argent47.net" + workspace_key_prefix = "workspace" + key = "tfstate.json" + region = "eu-west-1" + } +} + +locals { + environment = terraform.workspace + role = var.workspace_iam_role +} + +provider "aws" { + region = "eu-west-1" + + assume_role { + role_arn = local.role + } +} + +data "aws_vpc" "vpc" { + id = data.terraform_remote_state.main.outputs.vpc_id +} + +data "aws_caller_identity" "current" {} diff --git a/infrastructure/variables.tf b/infrastructure/variables.tf new file mode 100644 index 0000000..8e16a39 --- /dev/null +++ b/infrastructure/variables.tf @@ -0,0 +1,10 @@ +// Build variables +variable "workspace_iam_role" {} +variable "environment" {} +variable "branch" {} +variable "domain_name" {} +variable "github_token" {} +variable "gsap_npm_token" {} +variable "enable_performance_mode" { + default = false +} From f27f8a1b8c6eb2156d89fb0877ea90c862d6ee97 Mon Sep 17 00:00:00 2001 From: bluecco Date: Mon, 4 Nov 2024 16:18:04 +0100 Subject: [PATCH 3/3] chore: fix infra --- infrastructure/amplify.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/amplify.tf b/infrastructure/amplify.tf index bc98b15..da7113b 100644 --- a/infrastructure/amplify.tf +++ b/infrastructure/amplify.tf @@ -57,6 +57,6 @@ resource "aws_amplify_domain_association" "domain_association" { sub_domain { branch_name = aws_amplify_branch.branch.branch_name - prefix = "gift" + prefix = "demo-dapp-starknet" } }