From 0a756c42a9e1ac0cb54e3a5d52a40df0f9194912 Mon Sep 17 00:00:00 2001 From: edinstance Date: Fri, 30 May 2025 13:10:35 +0100 Subject: [PATCH 01/11] refactor: moved terraform gitlab ci to github --- .github/workflows/infrastructure.yml | 26 ++++++++++++++++++++++++++ .gitlab-ci.yml | 14 -------------- CICD/gitlab/terraform.yml | 13 ------------- 3 files changed, 26 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/infrastructure.yml delete mode 100644 CICD/gitlab/terraform.yml diff --git a/.github/workflows/infrastructure.yml b/.github/workflows/infrastructure.yml new file mode 100644 index 00000000..411baf18 --- /dev/null +++ b/.github/workflows/infrastructure.yml @@ -0,0 +1,26 @@ +name: Infrastructure Lint +on: + pull_request: + +jobs: + lint-and-security-scan: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ./infrastructure + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup TFLint + uses: terraform-linters/setup-tflint@v4.1.1 + + - name: Initialise TFLint + run: tflint --init + + - name: Run TFLint + run: tflint --recursive + + \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2f745b9b..1304e7a8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,17 +12,3 @@ trigger_backend_workflow: stage: triggers trigger: include: product/CICD/gitlab/backend.yml - -# This will be included after issues with the runners are resolved - -# Run Terraform workflow if there are changes in the terraform directory -# trigger_terraform_workflow: -# stage: triggers -# rules: -# - if: '$CI_COMMIT_REF_NAME == "main" || $CI_COMMIT_REF_NAME == "development" || $CI_COMMIT_REF_NAME == "terraform-updates"' -# changes: -# - product/infrastructure/* -# when: on_success -# - when: manual -# trigger: -# include: product/.gitlab/workflows/terraform.yml \ No newline at end of file diff --git a/CICD/gitlab/terraform.yml b/CICD/gitlab/terraform.yml deleted file mode 100644 index b8c7e143..00000000 --- a/CICD/gitlab/terraform.yml +++ /dev/null @@ -1,13 +0,0 @@ -stages: - - lint - -before_script: - - echo "Setting up the environment..." - - cd ./infrastructure - -terraform_init: - stage: lint - image: hashicorp/terraform:latest - script: - - terraform init - From c4aaf39445bd92400a72ed944dafc11f4491fa37 Mon Sep 17 00:00:00 2001 From: edinstance Date: Fri, 30 May 2025 13:10:42 +0100 Subject: [PATCH 02/11] feat!: fixed lint issues --- infrastructure/remote/modules/cicd/main.tf | 9 +++++++++ infrastructure/remote/modules/cicd/secrets.tf | 1 - infrastructure/remote/modules/cicd/variables.tf | 5 ----- infrastructure/remote/modules/cognito/main.tf | 9 +++++++++ infrastructure/remote/modules/ecr/main.tf | 10 ++++++++++ infrastructure/remote/modules/ecs/main.tf | 9 +++++++++ infrastructure/remote/modules/elasticache/main.tf | 9 +++++++++ infrastructure/remote/modules/elasticache/variables.tf | 5 ----- infrastructure/remote/modules/iam/ecs.tf | 2 +- infrastructure/remote/modules/iam/main.tf | 9 +++++++++ infrastructure/remote/modules/kafka/main.tf | 9 +++++++++ infrastructure/remote/modules/networking/main.tf | 9 +++++++++ infrastructure/remote/modules/rds/main.tf | 9 +++++++++ infrastructure/remote/modules/route53/certificates.tf | 4 ++-- infrastructure/remote/modules/route53/main.tf | 9 +++++++++ infrastructure/remote/modules/route53/routes.tf | 2 +- infrastructure/remote/modules/s3/main.tf | 9 +++++++++ infrastructure/remote/modules/ses/main.tf | 10 ++++++++++ infrastructure/remote/modules/ssm/main.tf | 9 +++++++++ infrastructure/remote/variables.tf | 10 +++++----- infrastructure/shared/dynamodb/main.tf | 9 +++++++++ infrastructure/shared/s3/images-bucket.tf | 10 ++++++++++ 22 files changed, 147 insertions(+), 20 deletions(-) create mode 100644 infrastructure/remote/modules/cicd/main.tf create mode 100644 infrastructure/remote/modules/cognito/main.tf create mode 100644 infrastructure/remote/modules/ecs/main.tf create mode 100644 infrastructure/remote/modules/elasticache/main.tf create mode 100644 infrastructure/remote/modules/iam/main.tf create mode 100644 infrastructure/remote/modules/kafka/main.tf create mode 100644 infrastructure/remote/modules/networking/main.tf create mode 100644 infrastructure/remote/modules/rds/main.tf create mode 100644 infrastructure/remote/modules/route53/main.tf create mode 100644 infrastructure/remote/modules/s3/main.tf create mode 100644 infrastructure/remote/modules/ssm/main.tf create mode 100644 infrastructure/shared/dynamodb/main.tf diff --git a/infrastructure/remote/modules/cicd/main.tf b/infrastructure/remote/modules/cicd/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/remote/modules/cicd/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/remote/modules/cicd/secrets.tf b/infrastructure/remote/modules/cicd/secrets.tf index 9516dec7..a22ce642 100644 --- a/infrastructure/remote/modules/cicd/secrets.tf +++ b/infrastructure/remote/modules/cicd/secrets.tf @@ -1,4 +1,3 @@ -data "aws_region" "current" {} resource "aws_secretsmanager_secret" "gitlab_credentials" { name = "GITLAB_CREDENTIALS_${var.environment}" diff --git a/infrastructure/remote/modules/cicd/variables.tf b/infrastructure/remote/modules/cicd/variables.tf index e0a77391..9f45436f 100644 --- a/infrastructure/remote/modules/cicd/variables.tf +++ b/infrastructure/remote/modules/cicd/variables.tf @@ -8,11 +8,6 @@ variable "environment" { } } -variable "aws_region" { - description = "The AWS region to deploy to" - type = string -} - variable "aws_account_id" { description = "The AWS account ID" type = string diff --git a/infrastructure/remote/modules/cognito/main.tf b/infrastructure/remote/modules/cognito/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/remote/modules/cognito/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/remote/modules/ecr/main.tf b/infrastructure/remote/modules/ecr/main.tf index 1b6aabc6..5643dd52 100644 --- a/infrastructure/remote/modules/ecr/main.tf +++ b/infrastructure/remote/modules/ecr/main.tf @@ -1,3 +1,13 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} + resource "aws_ecr_repository" "ecr_repo" { name = var.name image_tag_mutability = "IMMUTABLE" diff --git a/infrastructure/remote/modules/ecs/main.tf b/infrastructure/remote/modules/ecs/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/remote/modules/ecs/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/remote/modules/elasticache/main.tf b/infrastructure/remote/modules/elasticache/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/remote/modules/elasticache/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/remote/modules/elasticache/variables.tf b/infrastructure/remote/modules/elasticache/variables.tf index ee365fb2..7483b524 100644 --- a/infrastructure/remote/modules/elasticache/variables.tf +++ b/infrastructure/remote/modules/elasticache/variables.tf @@ -9,11 +9,6 @@ variable "environment" { } } -variable "availability_zones" { - description = "The availability zones for the database" - type = list(string) -} - variable "private_subnet_ids" { description = "The IDs of the private subnets" type = list(string) diff --git a/infrastructure/remote/modules/iam/ecs.tf b/infrastructure/remote/modules/iam/ecs.tf index 8abe1ea5..b23437e8 100644 --- a/infrastructure/remote/modules/iam/ecs.tf +++ b/infrastructure/remote/modules/iam/ecs.tf @@ -119,7 +119,7 @@ resource "aws_iam_policy" "ecs_dynamodb_admin_logs_policy" { "dynamodb:BatchWriteItem", "dynamodb:DescribeTable" ] - Resource = "${var.admin_access_logs_table_arn}" + Resource = var.admin_access_logs_table_arn }, ] diff --git a/infrastructure/remote/modules/iam/main.tf b/infrastructure/remote/modules/iam/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/remote/modules/iam/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/remote/modules/kafka/main.tf b/infrastructure/remote/modules/kafka/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/remote/modules/kafka/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/remote/modules/networking/main.tf b/infrastructure/remote/modules/networking/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/remote/modules/networking/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/remote/modules/rds/main.tf b/infrastructure/remote/modules/rds/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/remote/modules/rds/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/remote/modules/route53/certificates.tf b/infrastructure/remote/modules/route53/certificates.tf index 268f652c..60731e4e 100644 --- a/infrastructure/remote/modules/route53/certificates.tf +++ b/infrastructure/remote/modules/route53/certificates.tf @@ -1,10 +1,10 @@ resource "aws_acm_certificate" "acm_certificate" { - domain_name = var.environment == "prod" ? "${var.domain}" : "${var.environment}.${var.domain}" + domain_name = var.environment == "prod" ? var.domain : "${var.environment}.${var.domain}" validation_method = "DNS" subject_alternative_names = [ - "www.${var.environment == "prod" ? "${var.domain}" : "${var.environment}.${var.domain}"}", + "www.${var.environment == "prod" ? var.domain : "${var.environment}.${var.domain}"}", ] lifecycle { diff --git a/infrastructure/remote/modules/route53/main.tf b/infrastructure/remote/modules/route53/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/remote/modules/route53/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/remote/modules/route53/routes.tf b/infrastructure/remote/modules/route53/routes.tf index fddfd198..47dd5339 100644 --- a/infrastructure/remote/modules/route53/routes.tf +++ b/infrastructure/remote/modules/route53/routes.tf @@ -2,7 +2,7 @@ # Record to the alb resource "aws_route53_record" "route_53_alb_record" { zone_id = aws_route53_zone.route_53_hosted_zone.zone_id - name = var.environment == "prod" ? "${var.domain}" : "${var.environment}.${var.domain}" + name = var.environment == "prod" ? var.domain : "${var.environment}.${var.domain}" type = "A" alias { diff --git a/infrastructure/remote/modules/s3/main.tf b/infrastructure/remote/modules/s3/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/remote/modules/s3/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/remote/modules/ses/main.tf b/infrastructure/remote/modules/ses/main.tf index 3fbed97a..124bd279 100644 --- a/infrastructure/remote/modules/ses/main.tf +++ b/infrastructure/remote/modules/ses/main.tf @@ -1,3 +1,13 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} + data "aws_region" "current" {} resource "aws_ses_domain_identity" "ses_domain" { diff --git a/infrastructure/remote/modules/ssm/main.tf b/infrastructure/remote/modules/ssm/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/remote/modules/ssm/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/remote/variables.tf b/infrastructure/remote/variables.tf index dcf3716a..983dd0c3 100644 --- a/infrastructure/remote/variables.tf +++ b/infrastructure/remote/variables.tf @@ -61,11 +61,11 @@ variable "backend_image_tag" { default = "latest" } -variable "apollo_gateway_image_tag" { - description = "The tag of the apollo gateway Docker image to deploy" - type = string - default = "latest" -} +# variable "apollo_gateway_image_tag" { +# description = "The tag of the apollo gateway Docker image to deploy" +# type = string +# default = "latest" +# } # SSM variable "nextauth_secret" { diff --git a/infrastructure/shared/dynamodb/main.tf b/infrastructure/shared/dynamodb/main.tf new file mode 100644 index 00000000..b408648f --- /dev/null +++ b/infrastructure/shared/dynamodb/main.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} \ No newline at end of file diff --git a/infrastructure/shared/s3/images-bucket.tf b/infrastructure/shared/s3/images-bucket.tf index 80fdbc74..1bd7a9d9 100644 --- a/infrastructure/shared/s3/images-bucket.tf +++ b/infrastructure/shared/s3/images-bucket.tf @@ -1,3 +1,13 @@ +terraform { + required_version = ">= 1.9" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.60.0" + } + } +} + resource "aws_s3_bucket" "images_bucket" { bucket = "${var.environment}-subshop-images-bucket" force_destroy = true From 538b9416a99d6c7349b8d28805d1406cabfe921e Mon Sep 17 00:00:00 2001 From: edinstance Date: Fri, 30 May 2025 15:06:24 +0100 Subject: [PATCH 03/11] fix: fixed lint issues --- frontend/src/components/ui/Sidebar.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/ui/Sidebar.tsx b/frontend/src/components/ui/Sidebar.tsx index cbf5a814..995a45b0 100644 --- a/frontend/src/components/ui/Sidebar.tsx +++ b/frontend/src/components/ui/Sidebar.tsx @@ -42,10 +42,10 @@ export function Sidebar() { const userBilling = useQuery(GET_USER_BILLING); const accountId = userBilling.data?.getUserBilling?.accountId; - + // Filter out the Items page from sidebar links if no account ID exists - const filteredSidebarLinks = sidebarLinks.filter(link => - link.name !== "Items" || accountId + const filteredSidebarLinks = sidebarLinks.filter( + (link) => link.name !== "Items" || accountId, ); return ( From bd51c41390333bc6680cfcae7684aae60a406b75 Mon Sep 17 00:00:00 2001 From: edinstance Date: Fri, 30 May 2025 15:07:02 +0100 Subject: [PATCH 04/11] refactor: moved frontend gitlab cicd to github --- .github/workflows/frontend.yml | 67 ++++++++++++++++++++++++++++ .github/workflows/infrastructure.yml | 2 +- .gitlab-ci.yml | 6 --- CICD/gitlab/frontend.yml | 34 -------------- 4 files changed, 68 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/frontend.yml delete mode 100644 CICD/gitlab/frontend.yml diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml new file mode 100644 index 00000000..d2ba5c52 --- /dev/null +++ b/.github/workflows/frontend.yml @@ -0,0 +1,67 @@ +name: Lint and Test Frontend +on: + pull_request: + workflow_dispatch: + +jobs: + lint-frontend: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./frontend + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20.x + + - name: Install dependencies + run: npm ci + + - name: Set environment variables + run: | + cp .env.example .env + + - name: Lint frontend + run: npm run lint + + component-tests: + runs-on: ubuntu-latest + needs: lint-frontend + defaults: + run: + working-directory: ./frontend + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20.x + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Set test environment variables + run: | + export API_KEY="Test" + + - name: Build frontend Docker image for tests + run: docker build -t frontend-test-image . + + - name: Bring up Docker Compose services + run: docker compose up -d + + - name: Cypress.io component tests + uses: cypress-io/github-action@v6.5.0 + with: + wait-on: http://localhost:3000/api/health + wait-on-timeout: 120 + command: npm run cy:run:ct diff --git a/.github/workflows/infrastructure.yml b/.github/workflows/infrastructure.yml index 411baf18..0b933d95 100644 --- a/.github/workflows/infrastructure.yml +++ b/.github/workflows/infrastructure.yml @@ -3,7 +3,7 @@ on: pull_request: jobs: - lint-and-security-scan: + lint-and-security-scan-infrastructure: runs-on: ubuntu-latest defaults: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1304e7a8..8f41478d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,12 +1,6 @@ stages: - triggers -# Create a trigger for running the frontend workflow -trigger_frontend_workflow: - stage: triggers - trigger: - include: product/CICD/gitlab/frontend.yml - # Create a trigger for running the backend workflow trigger_backend_workflow: stage: triggers diff --git a/CICD/gitlab/frontend.yml b/CICD/gitlab/frontend.yml deleted file mode 100644 index c28b40e9..00000000 --- a/CICD/gitlab/frontend.yml +++ /dev/null @@ -1,34 +0,0 @@ -image: node:23-alpine - -stages: - - lint - - test - -default: - cache: - key: $CI_COMMIT_REF_SLUG - paths: - - .npm/ - before_script: - - cd ./frontend/ - - echo "Installing dependencies..." - - npm ci --cache .npm --prefer-offline - -lint_frontend: - stage: lint - script: - - echo "Running frontend linting..." - - npm run lint - -knip_frontend: - stage: lint - script: - - echo "Running frontend knip..." - - export API_KEY="Test" # Added mock api key for knip - - npm run knip - -component_test_frontend: - stage: test - script: - - echo "Running frontend component tests..." - - npm run cy:run:ct \ No newline at end of file From 2276872b8528488a68e8201defa4c9cbe1090c63 Mon Sep 17 00:00:00 2001 From: edinstance Date: Fri, 30 May 2025 15:41:11 +0100 Subject: [PATCH 05/11] refactor: moved gitlab cicd to github --- .github/workflows/backend.yml | 56 +++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 8 ----- CICD/gitlab/backend.yml | 31 ------------------- 3 files changed, 56 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/backend.yml delete mode 100644 .gitlab-ci.yml delete mode 100644 CICD/gitlab/backend.yml diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 00000000..43291583 --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,56 @@ +name: Backend Lint and Unit Tests + +on: + pull_request: + workflow_dispatch: + + +env: + TEST_COGNITO_JWT_URL: ${{ secrets.TEST_COGNITO_JWT_URL }} + +jobs: + lint-backend: + runs-on: ubuntu-latest + container: + image: maven:3.9.9-amazoncorretto-21-alpine + + defaults: + run: + working-directory: ./backend/application/ + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run backend linting (Checkstyle) + run: | + echo "Running backend linting..." + mvn -f ./backendService/pom.xml clean checkstyle:check + echo "Backend linting passed" + + unit-test-backend: + runs-on: ubuntu-latest + needs: lint-backend + container: + image: maven:3.9.9-amazoncorretto-21-alpine + + defaults: + run: + working-directory: ./backend/application/ + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Prepare application.yml for tests + run: | + echo "Copying the test-application.yml into a application.yml file..." + cp ./backendService/src/main/resources/test-application.example.yml ./backendService/src/main/resources/application.yml + cp ./backendService/src/test/resources/application.example.yml ./backendService/src/test/resources/application.yml + echo "Copying completed" + + - name: Run unit tests + run: | + echo "Running unit tests..." + mvn -f ./backendService/pom.xml clean test -DTEST_COGNITO_JWT_URL=$TEST_COGNITO_JWT_URL + echo "Unit tests passed" \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 8f41478d..00000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,8 +0,0 @@ -stages: - - triggers - -# Create a trigger for running the backend workflow -trigger_backend_workflow: - stage: triggers - trigger: - include: product/CICD/gitlab/backend.yml diff --git a/CICD/gitlab/backend.yml b/CICD/gitlab/backend.yml deleted file mode 100644 index 50c7b8b6..00000000 --- a/CICD/gitlab/backend.yml +++ /dev/null @@ -1,31 +0,0 @@ -stages: - - build - - test - -before_script: - - echo "Setting up the environment..." - - cd ./backend/ - -lint_backend: - stage: test - image: maven:3.9.9-amazoncorretto-21-alpine - script: - - echo "Running backend linting..." - - cd ./application/ - - mvn clean checkstyle:check - - echo "Backend linting passed" - -unit_test_backend: - stage: test - image: maven:3.9.9-amazoncorretto-21-alpine - variables: - TEST_COGNITO_JWT_URL: $TEST_COGNITO_JWT_URL - script: - - echo "Copying the test-application.yml into a application.yml file..." - - cp ./application/backendService/src/main/resources/test-application.example.yml ./application/backendService/src/main/resources/application.yml - - cp ./application/backendService/src/test/resources/application.example.yml ./application/backendService/src/test/resources/application.yml - - echo "Copying completed" - - echo "Running unit tests..." - - cd ./application/ - - mvn -f ./backendService/pom.xml clean test -DTEST_COGNITO_JWT_URL=$TEST_COGNITO_JWT_URL - - echo "Unit tests passed" From 604885a79383db213b86a74df9f18c9dc123ccd1 Mon Sep 17 00:00:00 2001 From: edinstance Date: Fri, 30 May 2025 15:48:15 +0100 Subject: [PATCH 06/11] fix: formatting and env setup --- .github/workflows/backend.yml | 17 ++++++++--------- .github/workflows/frontend.yml | 4 ++-- .github/workflows/infrastructure.yml | 2 -- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 43291583..397436de 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -4,9 +4,8 @@ on: pull_request: workflow_dispatch: - env: - TEST_COGNITO_JWT_URL: ${{ secrets.TEST_COGNITO_JWT_URL }} + TEST_COGNITO_JWT_URL: ${{ secrets.TEST_COGNITO_JWT_URL }} jobs: lint-backend: @@ -44,13 +43,13 @@ jobs: - name: Prepare application.yml for tests run: | - echo "Copying the test-application.yml into a application.yml file..." - cp ./backendService/src/main/resources/test-application.example.yml ./backendService/src/main/resources/application.yml - cp ./backendService/src/test/resources/application.example.yml ./backendService/src/test/resources/application.yml - echo "Copying completed" + echo "Copying the test-application.yml into a application.yml file..." + cp ./backendService/src/main/resources/test-application.example.yml ./backendService/src/main/resources/application.yml + cp ./backendService/src/test/resources/application.example.yml ./backendService/src/test/resources/application.yml + echo "Copying completed" - name: Run unit tests run: | - echo "Running unit tests..." - mvn -f ./backendService/pom.xml clean test -DTEST_COGNITO_JWT_URL=$TEST_COGNITO_JWT_URL - echo "Unit tests passed" \ No newline at end of file + echo "Running unit tests..." + mvn -f ./backendService/pom.xml clean test -DTEST_COGNITO_JWT_URL=$TEST_COGNITO_JWT_URL + echo "Unit tests passed" diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index d2ba5c52..d5703740 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -24,7 +24,7 @@ jobs: - name: Set environment variables run: | - cp .env.example .env + echo "API_KEY=Test" >> $GITHUB_ENV - name: Lint frontend run: npm run lint @@ -51,7 +51,7 @@ jobs: - name: Set test environment variables run: | - export API_KEY="Test" + echo "API_KEY=Test" >> $GITHUB_ENV - name: Build frontend Docker image for tests run: docker build -t frontend-test-image . diff --git a/.github/workflows/infrastructure.yml b/.github/workflows/infrastructure.yml index 0b933d95..4bd5f325 100644 --- a/.github/workflows/infrastructure.yml +++ b/.github/workflows/infrastructure.yml @@ -22,5 +22,3 @@ jobs: - name: Run TFLint run: tflint --recursive - - \ No newline at end of file From d0d3c18855e25e9605e73d7bae8a49a102c16783 Mon Sep 17 00:00:00 2001 From: edinstance Date: Fri, 30 May 2025 15:50:56 +0100 Subject: [PATCH 07/11] fix: removed cache from setup node --- .github/workflows/frontend.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index d5703740..35ca63ee 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -44,7 +44,6 @@ jobs: uses: actions/setup-node@v4 with: node-version: 20.x - cache: npm - name: Install dependencies run: npm ci From d37b82558698ac63c23aa145d6a94befa773df88 Mon Sep 17 00:00:00 2001 From: edinstance Date: Fri, 30 May 2025 16:28:29 +0100 Subject: [PATCH 08/11] fix: remove docker step from frontend workflow --- .github/workflows/frontend.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 35ca63ee..638fcb0c 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -52,12 +52,6 @@ jobs: run: | echo "API_KEY=Test" >> $GITHUB_ENV - - name: Build frontend Docker image for tests - run: docker build -t frontend-test-image . - - - name: Bring up Docker Compose services - run: docker compose up -d - - name: Cypress.io component tests uses: cypress-io/github-action@v6.5.0 with: From 5a49835dde7888aafa179ff79dc80c4e1e1d75b1 Mon Sep 17 00:00:00 2001 From: edinstance Date: Fri, 30 May 2025 16:28:39 +0100 Subject: [PATCH 09/11] fix: fixed stripe issues --- frontend/src/app/api/billing/payments/route.ts | 1 - frontend/src/app/api/billing/subscriptions/route.ts | 1 - frontend/src/utils/stripe.ts | 4 +--- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/frontend/src/app/api/billing/payments/route.ts b/frontend/src/app/api/billing/payments/route.ts index f6f1f708..817d1419 100644 --- a/frontend/src/app/api/billing/payments/route.ts +++ b/frontend/src/app/api/billing/payments/route.ts @@ -1,4 +1,3 @@ -// File: app/api/billing/subscriptions/route.ts (for App Router) import stripe from "@/utils/stripe"; import { NextRequest, NextResponse } from "next/server"; diff --git a/frontend/src/app/api/billing/subscriptions/route.ts b/frontend/src/app/api/billing/subscriptions/route.ts index 35fc79e1..34ff8c20 100644 --- a/frontend/src/app/api/billing/subscriptions/route.ts +++ b/frontend/src/app/api/billing/subscriptions/route.ts @@ -1,4 +1,3 @@ -// File: app/api/billing/subscriptions/route.ts (for App Router) import stripe, { findExistingSubscriptionByCustomerId } from "@/utils/stripe"; import { NextRequest, NextResponse } from "next/server"; import Stripe from "stripe"; diff --git a/frontend/src/utils/stripe.ts b/frontend/src/utils/stripe.ts index b73bb773..daecf9bd 100644 --- a/frontend/src/utils/stripe.ts +++ b/frontend/src/utils/stripe.ts @@ -3,9 +3,7 @@ import Stripe from "stripe"; if (!process.env.STRIPE_SECRET_KEY) { throw new Error("Stripe secret key is not configured."); } -const stripe = new Stripe( - "sk_test_51QNhlTGlnq0aqIkWUh4pGdNEkLo6qGgkXU885vaJexq15ykuThU9JDTxo77RTjCqNxRP6QkW30y7cZEIOLEpn6KD00uBKttude", -); +const stripe = new Stripe(process.env.STRIPE_SECRET_KEY); export default stripe; /** From aa6e11c95365130023b082172f92b2acbe84f1f9 Mon Sep 17 00:00:00 2001 From: edinstance Date: Fri, 30 May 2025 17:00:58 +0100 Subject: [PATCH 10/11] fix: added working dir to cypress --- .github/workflows/frontend.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 638fcb0c..3b10d352 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -57,4 +57,5 @@ jobs: with: wait-on: http://localhost:3000/api/health wait-on-timeout: 120 + working-directory: ./frontend command: npm run cy:run:ct From 7e8c12e24022181bb8a35ff594eaaaa52c6e1fad Mon Sep 17 00:00:00 2001 From: edinstance Date: Fri, 30 May 2025 17:06:25 +0100 Subject: [PATCH 11/11] fix: removed wait on for component tests --- .github/workflows/frontend.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 3b10d352..95fceb8a 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -55,7 +55,5 @@ jobs: - name: Cypress.io component tests uses: cypress-io/github-action@v6.5.0 with: - wait-on: http://localhost:3000/api/health - wait-on-timeout: 120 working-directory: ./frontend command: npm run cy:run:ct