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 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..da7113b --- /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 = "demo-dapp-starknet" + } +} 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 +}