diff --git a/.github/workflows/tf_apply_staging.yml b/.github/workflows/tf_apply_staging.yml index 84600ef6..3c1b5b9a 100644 --- a/.github/workflows/tf_apply_staging.yml +++ b/.github/workflows/tf_apply_staging.yml @@ -1,4 +1,4 @@ -name: 'Terraform apply staging' +name: "Terraform apply staging" on: workflow_dispatch: @@ -6,9 +6,9 @@ on: branches: - main paths: - - 'terragrunt/**' - - '!terragrunt/env/staging/**' - - '.github/workflows/tf_apply_staging.yml' + - "terragrunt/**" + - "!terragrunt/env/staging/**" + - ".github/workflows/tf_apply_staging.yml" env: AWS_REGION: ca-central-1 @@ -37,7 +37,7 @@ jobs: - name: Configure aws credentials using OIDC uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2 with: - role-to-assume: arn:aws:iam::992382783569:role/react-answers-apply + role-to-assume: arn:aws:iam::730335533085:role/ai-answers-apply role-session-name: TFApply aws-region: ${{ env.AWS_REGION }} diff --git a/.github/workflows/tf_plan_staging.yml b/.github/workflows/tf_plan_staging.yml index 9983bd4e..2121d785 100644 --- a/.github/workflows/tf_plan_staging.yml +++ b/.github/workflows/tf_plan_staging.yml @@ -1,12 +1,12 @@ -name: 'Terraform plan staging' +name: "Terraform plan staging" on: workflow_dispatch: pull_request: paths: - - 'terragrunt/**' - - '!terragrunt/env/staging/**' - - '.github/workflows/tf_plan_staging.yml' + - "terragrunt/**" + - "!terragrunt/env/staging/**" + - ".github/workflows/tf_plan_staging.yml" env: AWS_REGION: ca-central-1 @@ -42,7 +42,7 @@ jobs: - name: Configure aws credentials using OIDC uses: aws-actions/configure-aws-credentials@v4.0.2 with: - role-to-assume: arn:aws:iam::992382783569:role/react-answers-plan + role-to-assume: arn:aws:iam::730335533085:role/ai-answers-plan role-session-name: TFPlan aws-region: ${{ env.AWS_REGION }} @@ -50,7 +50,7 @@ jobs: uses: cds-snc/terraform-plan@v3.2.2 with: comment-delete: true - comment-title: 'Staging: ${{ matrix.module }}' + comment-title: "Staging: ${{ matrix.module }}" directory: ./terragrunt/env/staging/${{ matrix.module }} github-token: ${{ secrets.GITHUB_TOKEN }} terragrunt: true diff --git a/Dockerfile.client b/Dockerfile.client index f585d215..8892999b 100644 --- a/Dockerfile.client +++ b/Dockerfile.client @@ -1,31 +1,18 @@ -# Build stage -FROM node:18-alpine as build +# Use a Node.js image for the React app +FROM node:lts +# Set the working directory inside the container WORKDIR /app -# Copy package files -COPY package*.json ./ - # Install dependencies -RUN npm ci - -# Copy source code -COPY . . - -# Build the app -RUN npm run build - -# Production stage -FROM nginx:alpine - -# Copy built assets from build stage -COPY --from=build /app/build /usr/share/nginx/html +COPY package.json package-lock.json ./ +RUN npm install -# Copy nginx config -COPY nginx.conf /etc/nginx/conf.d/default.conf +# Copy all files +COPY ./ ./ -# Expose port 80 -EXPOSE 80 +# Expose port 3000 for the React development server +EXPOSE 3000 -# Start nginx -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +# Start the React development server +CMD ["npm", "start"] \ No newline at end of file diff --git a/Dockerfile.server b/Dockerfile.server index f8121b56..b4e0d62d 100644 --- a/Dockerfile.server +++ b/Dockerfile.server @@ -1,25 +1,25 @@ -# Build stage -FROM node:18-alpine +# Use a Node.js image for the server +FROM node:lts -WORKDIR /app +# Set the working directory to match devcontainer workspace +WORKDIR /workspace -# Copy package files for both root and server -COPY package*.json ./ -COPY server/package*.json ./server/ +# Copy all required directories maintaining the project structure +COPY api/ ./api/ +COPY config/ ./config/ +COPY models/ ./models/ +COPY agents/ ./agents/ +COPY server/ ./server/ -# Install dependencies for both -RUN npm ci -RUN cd server && npm ci +# Copy package files and install dependencies +COPY package.json package-lock.json ./ +RUN npm install -# Copy source code -COPY . . +# Set working directory to server for starting the app +WORKDIR /workspace/server -# Environment variables will be provided at runtime -ENV PORT=3001 -ENV NODE_ENV=production - -# Expose the port +# Expose the backend server port (3001 by default) EXPOSE 3001 -# Start the server -CMD ["node", "server/server.js"] \ No newline at end of file +# Start the backend server +CMD ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..1c3e82b0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,62 @@ +services: + client: + build: + context: . + dockerfile: Dockerfile.client + container_name: ai-answers-client + ports: + - '3000:3000' + depends_on: + - server + + server: + build: + context: . + dockerfile: Dockerfile.server + container_name: ai-answers-server + volumes: + - .:/workspace:cached + - server-node-modules:/workspace/server/node_modules + - root-node-modules:/workspace/node_modules + ports: + - '3001:3001' + environment: + - MONGODB_URI=mongodb://admin:password@mongodb:27017/?authSource=admin + depends_on: + - mongodb + + mongodb: + image: mongo:latest + container_name: mongodb + ports: + - '27017:27017' + volumes: + - mongo-data:/data/db + environment: + MONGO_INITDB_ROOT_USERNAME: admin + MONGO_INITDB_ROOT_PASSWORD: password + + mongo-express: + image: mongo-express:latest + container_name: mongo-express + ports: + - '9191:8081' + environment: + ME_CONFIG_MONGODB_ENABLE_ADMIN: 'true' + ME_CONFIG_MONGODB_ADMINUSERNAME: 'admin' + ME_CONFIG_MONGODB_ADMINPASSWORD: 'password' + ME_CONFIG_BASICAUTH_USERNAME: 'admin' + ME_CONFIG_BASICAUTH_PASSWORD: 'password' + ME_CONFIG_MONGODB_SERVER: mongodb + ME_CONFIG_MONGODB_URL: 'mongodb://admin:password@mongodb:27017/?authSource=admin' + depends_on: + - mongodb + +volumes: + mongo-data: + server-node-modules: + root-node-modules: + +networks: + default: + name: ai-answers-network diff --git a/docker/docker-compose-mongodb.yml b/docker/docker-compose-mongodb.yml deleted file mode 100644 index 8eb9ca16..00000000 --- a/docker/docker-compose-mongodb.yml +++ /dev/null @@ -1,29 +0,0 @@ -services: - mongodb: - image: mongo:latest - container_name: mongodb - ports: - - "27017:27017" - volumes: - - mongo-data:/data/db - environment: - MONGO_INITDB_ROOT_USERNAME: admin - MONGO_INITDB_ROOT_PASSWORD: password - - mongo-express: - image: mongo-express:latest - container_name: mongo-express - ports: - - "9191:8081" - environment: - ME_CONFIG_MONGODB_ENABLE_ADMIN: "true" - ME_CONFIG_MONGODB_ADMINUSERNAME: "admin" - ME_CONFIG_MONGODB_ADMINPASSWORD: "password" - ME_CONFIG_BASICAUTH_USERNAME: "admin" - ME_CONFIG_BASICAUTH_PASSWORD: "password" - ME_CONFIG_MONGODB_SERVER: mongodb - ME_CONFIG_MONGODB_URL: "mongodb://admin:password@mongodb:27017/" - depends_on: - - mongodb -volumes: - mongo-data: diff --git a/package-lock.json b/package-lock.json index 5165e106..2f1c99cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "react-answers", + "name": "ai-answers", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "react-answers", + "name": "ai-answers", "version": "0.1.0", "dependencies": { "@anthropic-ai/sdk": "^0.33.1", diff --git a/package.json b/package.json index 57584500..9952719e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "react-answers", + "name": "ai-answers", "version": "0.1.0", "type": "module", "private": true, diff --git a/terragrunt/aws/ecr/ecr.tf b/terragrunt/aws/ecr/ecr.tf index d5ab52b8..f103740f 100644 --- a/terragrunt/aws/ecr/ecr.tf +++ b/terragrunt/aws/ecr/ecr.tf @@ -1,5 +1,5 @@ -resource "aws_ecr_repository" "react_answers" { - name = "react-answers" +resource "aws_ecr_repository" "ai_answers" { + name = "ai-answers" image_tag_mutability = "MUTABLE" image_scanning_configuration { diff --git a/terragrunt/aws/ecr/outputs.tf b/terragrunt/aws/ecr/outputs.tf index cefbfa04..c93761cc 100644 --- a/terragrunt/aws/ecr/outputs.tf +++ b/terragrunt/aws/ecr/outputs.tf @@ -1,9 +1,9 @@ output "ecr_repository_url" { description = "URL of the React Answers ECR" - value = aws_ecr_repository.react_answers.repository_url + value = aws_ecr_repository.ai_answers.repository_url } output "ecr_repository_arn" { description = "Arn of the ECR Repository" - value = aws_ecr_repository.react_answers.arn + value = aws_ecr_repository.ai_answers.arn } \ No newline at end of file diff --git a/terragrunt/aws/hosted_zone/outputs.tf b/terragrunt/aws/hosted_zone/outputs.tf index 18ee7fa6..ca76c7a1 100644 --- a/terragrunt/aws/hosted_zone/outputs.tf +++ b/terragrunt/aws/hosted_zone/outputs.tf @@ -1,4 +1,4 @@ output "hosted_zone_id" { description = "Route53 hosted zone ID that will hold our DNS records" - value = aws_route53_zone.react_answers.zone_id + value = aws_route53_zone.ai_answers.zone_id } \ No newline at end of file diff --git a/terragrunt/aws/hosted_zone/route_53.tf b/terragrunt/aws/hosted_zone/route_53.tf index cb138c02..02f6b3e6 100644 --- a/terragrunt/aws/hosted_zone/route_53.tf +++ b/terragrunt/aws/hosted_zone/route_53.tf @@ -2,7 +2,7 @@ # Hosted zone for React Answers app # -resource "aws_route53_zone" "react_answers" { +resource "aws_route53_zone" "ai_answers" { name = var.domain tags = { diff --git a/terragrunt/aws/network/outputs.tf b/terragrunt/aws/network/outputs.tf index 7d991263..c65ae8d9 100644 --- a/terragrunt/aws/network/outputs.tf +++ b/terragrunt/aws/network/outputs.tf @@ -1,21 +1,21 @@ output "vpc_id" { description = "The VPC id" - value = module.react_answers_vpc.vpc_id + value = module.ai_answers_vpc.vpc_id } output "vpc_private_subnet_ids" { description = "List of the React Answers app VPC private subnet ids" - value = module.react_answers_vpc.private_subnet_ids + value = module.ai_answers_vpc.private_subnet_ids } output "vpc_public_subnet_ids" { description = "List of the React Answers App VPC public subnet ids" - value = module.react_answers_vpc.public_subnet_ids + value = module.ai_answers_vpc.public_subnet_ids } output "vpc_cidr_block" { description = "List of cidr block ips for the React Answers VPC" - value = module.react_answers_vpc.cidr_block + value = module.ai_answers_vpc.cidr_block } diff --git a/terragrunt/aws/network/security_groups.tf b/terragrunt/aws/network/security_groups.tf index ced08a8f..cc3f6b0c 100644 --- a/terragrunt/aws/network/security_groups.tf +++ b/terragrunt/aws/network/security_groups.tf @@ -17,7 +17,7 @@ resource "aws_security_group" "app" { description = "Security Group for the React Answers App" # ID of the VPC where this SG will be created - vpc_id = module.react_answers_vpc.vpc_id + vpc_id = module.ai_answers_vpc.vpc_id # Ensures Terraform removes associated rules upon SG destruction or modification revoke_rules_on_delete = true diff --git a/terragrunt/aws/network/vpc.tf b/terragrunt/aws/network/vpc.tf index 1cc188d7..c1e72ea2 100644 --- a/terragrunt/aws/network/vpc.tf +++ b/terragrunt/aws/network/vpc.tf @@ -3,7 +3,7 @@ # # Use the terraform-modules/vpc module to create the VPC for the react answers app -module "react_answers_vpc" { +module "ai_answers_vpc" { source = "github.com/cds-snc/terraform-modules//vpc?ref=v10.2.2" name = var.product_name billing_tag_value = var.billing_tag_value diff --git a/terragrunt/env/root.hcl b/terragrunt/env/root.hcl index a6811cfb..d0ee6789 100644 --- a/terragrunt/env/root.hcl +++ b/terragrunt/env/root.hcl @@ -5,7 +5,7 @@ locals { # DO NOT CHANGE ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING inputs = { - product_name = "react-answers" + product_name = "ai-answers" account_id = "${local.vars.inputs.account_id}" domain = "${local.vars.inputs.domain}" env = "${local.vars.inputs.env}" diff --git a/terragrunt/env/staging/ecr/.terraform.lock.hcl b/terragrunt/env/staging/ecr/.terraform.lock.hcl index b3226c1f..6c22b66b 100644 --- a/terragrunt/env/staging/ecr/.terraform.lock.hcl +++ b/terragrunt/env/staging/ecr/.terraform.lock.hcl @@ -5,6 +5,7 @@ provider "registry.terraform.io/hashicorp/aws" { version = "5.84.0" constraints = "~> 5.0" hashes = [ + "h1:OJ53RNte7HLHSMxSkzu1S6H8sC0T8qnCAOcNLjjtMpc=", "h1:dwpeFUdcxgXVAc0JSqO57xf0/r2qOBLPloombCQWFz8=", "zh:078f77438aba6ec8bf9154b7d223e5c71c48d805d6cd3bcf9db0cc1e82668ac3", "zh:1f6591ff96be00501e71b792ed3a5a14b21ff03afec9a1c4a3fd9300e6e5b674", diff --git a/terragrunt/env/staging/env_vars.hcl b/terragrunt/env/staging/env_vars.hcl index 538e3f2f..253c21bb 100644 --- a/terragrunt/env/staging/env_vars.hcl +++ b/terragrunt/env/staging/env_vars.hcl @@ -1,6 +1,6 @@ inputs = { - account_id = "992382783569" + account_id = "730335533085" env = "staging" - cost_center_code = "react-answers-staging" - domain = "react-answers.cdssandbox.xyz" + cost_center_code = "ai-answers-staging" + domain = "ai-answers.cdssandbox.xyz" } \ No newline at end of file