Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add ecr #21

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/tf_apply_staging.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: 'Terraform apply staging'
name: "Terraform apply staging"

on:
workflow_dispatch:
push:
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
Expand Down Expand Up @@ -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 }}

Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/tf_plan_staging.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,15 +42,15 @@ jobs:
- name: Configure aws credentials using OIDC
uses: aws-actions/[email protected]
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 }}

- name: Terraform plan
uses: cds-snc/[email protected]
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
35 changes: 11 additions & 24 deletions Dockerfile.client
Original file line number Diff line number Diff line change
@@ -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;"]
# Start the React development server
CMD ["npm", "start"]
36 changes: 18 additions & 18 deletions Dockerfile.server
Original file line number Diff line number Diff line change
@@ -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"]
# Start the backend server
CMD ["npm", "start"]
62 changes: 62 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 0 additions & 29 deletions docker/docker-compose-mongodb.yml

This file was deleted.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "react-answers",
"name": "ai-answers",
"version": "0.1.0",
"type": "module",
"private": true,
Expand Down
4 changes: 2 additions & 2 deletions terragrunt/aws/ecr/ecr.tf
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions terragrunt/aws/ecr/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion terragrunt/aws/hosted_zone/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion terragrunt/aws/hosted_zone/route_53.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 4 additions & 4 deletions terragrunt/aws/network/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}


Expand Down
2 changes: 1 addition & 1 deletion terragrunt/aws/network/security_groups.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion terragrunt/aws/network/vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion terragrunt/env/root.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions terragrunt/env/staging/ecr/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions terragrunt/env/staging/env_vars.hcl
Original file line number Diff line number Diff line change
@@ -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"
}
Loading