Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
272e295
initial working branch
GarethF531 Aug 21, 2025
75cb535
terraform
GarethF531 Aug 25, 2025
610fd20
name changes
GarethF531 Aug 25, 2025
4514934
commit
GarethF531 Sep 2, 2025
31ef9d2
Docker Wroking
GarethF531 Sep 2, 2025
3870d8f
Terraform
GarethF531 Sep 2, 2025
e5aa3c8
Added circleci config for building and deploying
GarethF531 Sep 2, 2025
7ae8725
Simplified circleci workflow
GarethF531 Sep 2, 2025
0bd0c97
Updated circleci
GarethF531 Sep 2, 2025
0c6c6b1
fix yaml
GarethF531 Sep 2, 2025
8d0161f
Fixed aws_init ref
GarethF531 Sep 2, 2025
3b0bfcb
updated tf refs
GarethF531 Sep 2, 2025
bb82883
Update default pipeline
GarethF531 Sep 2, 2025
bee1acd
Fixed app_name
GarethF531 Sep 2, 2025
b457a32
re-added steps to create ecr repository
GarethF531 Sep 2, 2025
116bb7b
Removed log in to codeartifact
GarethF531 Sep 2, 2025
3c74a13
added necessary orbs
GarethF531 Sep 2, 2025
9bee8a3
fixed order of actions in pipeline
GarethF531 Sep 2, 2025
a506f3b
Refacgtored folders
GarethF531 Sep 2, 2025
159a416
Fix terraform formatting
SMR-AV Sep 2, 2025
3cb7874
Fixed up ecr repo tf
SMR-AV Sep 2, 2025
39f5595
Fixed build executor for build and push
SMR-AV Sep 2, 2025
334e75b
Fixed yaml error
SMR-AV Sep 2, 2025
3b17108
Fixed build-image to reference build-and-push
SMR-AV Sep 2, 2025
f1fc544
Fix in build-and-push
SMR-AV Sep 2, 2025
14d32f0
Added context path for docker build
SMR-AV Sep 2, 2025
a721dd9
Added approval step before deploying
SMR-AV Sep 2, 2025
38b2280
Fixed up the references to the ecr repo
SMR-AV Sep 2, 2025
c9a0816
Fixed app name
SMR-AV Sep 2, 2025
fc4ac24
Fixed image tag format
SMR-AV Sep 2, 2025
9d080bc
Addedd config for client and server repo
SMR-AV Sep 2, 2025
d0647c0
Went back to one repo and used tags to differentiate the images
SMR-AV Sep 2, 2025
90a7b79
Added logging to check repo url
SMR-AV Sep 2, 2025
ca3d3ef
Added logging for project repository url
SMR-AV Sep 2, 2025
2ab4438
Used hard-coded ecr url host for now
SMR-AV Sep 2, 2025
5e0ff5f
Tried using variables to create separate ecr repositories
SMR-AV Sep 2, 2025
e93ac62
Tried using image name to create ECR repo
SMR-AV Sep 2, 2025
48de6b9
SHoould be the final fix for the ECR repo names
SMR-AV Sep 2, 2025
cafa43c
Gave up and just used the app names
SMR-AV Sep 2, 2025
26b7fcb
Gave up and just used the app names
SMR-AV Sep 2, 2025
5f359b8
Removed unused vars for ECR creation
SMR-AV Sep 2, 2025
830730f
Updated workspace for tf plan
SMR-AV Sep 2, 2025
6003134
Fixed variable formatting and fixed terraform path
SMR-AV Sep 2, 2025
7116d82
Removed tf vars which have no value
SMR-AV Sep 2, 2025
ed10757
Terraform plan fixes
SMR-AV Sep 3, 2025
c3a45ad
Renamed app_names which were too long
SMR-AV Sep 3, 2025
29ec3c0
Fixed env to make alb dns correct
SMR-AV Sep 3, 2025
af45953
Fixed the container image urls
SMR-AV Sep 15, 2025
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
314 changes: 220 additions & 94 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,114 +1,240 @@
# This config is equivalent to both the '.circleci/extended/orb-free.yml' and the base '.circleci/config.yml'
version: 2.1
version: "2.1"

# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
# See: https://circleci.com/docs/2.0/orb-intro/
orbs:
node: circleci/node@4.7
cypress: cypress-io/cypress@1
node: circleci/node@5.1.0
aws-ecr: circleci/aws-ecr@9.0
aws-cli: circleci/aws-cli@3.1
terraform-helper: anyvan/terraform-helper@1
aws: anyvan/aws_auth_config@1
deployments: anyvan/deployments@1
aws-ecr-helper: anyvan/aws-ecr-helper@2
aws-tunnel-helper: anyvan/aws-tunnel-helper@2
anyvan_github_ssh_key: anyvan/ssh_key_github@1

parameters:
region:
default: eu-west-1
type: string
modules:
default: v0.0.79
type: string
terraform_version:
default: "1.9.5"
type: string
jira_ticket_number:
type: string
default: $(echo $CIRCLE_BRANCH | sed -ne 's/[A-Z]*-\([0-9]*\)-.*/\1/p')
image_tag:
type: string
default: $CIRCLE_SHA1
workflow:
type: string
default: "deploy_to_pr_env"
app_name:
type: string
default: "twilio-webchat-widget"
ecr_repo_host:
type: string
default: "331151898531.dkr.ecr.eu-west-1.amazonaws.com"


executors:
with-chrome:
base:
docker:
- image: 'cypress/browsers:node14.17.0-chrome91-ff89'
- image: cimg/base:current

jobs:
cleanUp:
docker:
- image: cimg/node:14.18.1
steps:
- checkout
- run:
command: npm install twilio --no-save
name: Install Twilio client
- run:
command: |
yarn e2eCleanupExistingTasks \
accountSid=$TWILIO_ACCOUNT_SID \
authToken=$TWILIO_AUTH_TOKEN \
name: Cleanup existing tasks
runUnitTests:
node-docker:
docker:
- image: cimg/node:14.18.1
steps:
- checkout
- node/install-packages:
pkg-manager: yarn-berry
with-cache: true
- run:
command: yarn test:nowatch
name: Run YARN tests
cypressTestsOnSauce:
- image: cimg/node:20.19.2
resource_class: small

iac-base:
docker:
- image: cimg/node:lts
- image: $AWS_ECR_CIRCLECI_IMAGES_REPOSITORY_HOST/base/iac-base:noble
aws_auth:
oidc_role_arn: arn:aws:iam::$HORIZONTAL_ACCOUNT:role/circleci_oidc_role

jobs:
build-and-push:
parameters:
image:
type: string
project-root:
type: string
env:
type: string
repository:
type: string
entry:
type: string
dockerfile:
type: string
executor: node-docker
steps:
- checkout
- attach_workspace:
at: ~/
- run:
name: "Install dependencies"
command: |
yarn install --frozen-lockfile
- run:
name: "Initialize accounts"
command: |
yarn bootstrap \
accountSid=$TWILIO_ACCOUNT_SID \
authToken=$TWILIO_AUTH_TOKEN \
addressSid=$TWILIO_ADDRESS_SID \
apiKey=$TWILIO_API_KEY \
apiSecret=$TWILIO_API_SECRET \
conversationsServiceSid=$TWILIO_CONVERSATIONS_SERVICE_SID
- run:
name: "Running Application"
background: true
command: |
yarn start & yarn server:ci
- run:
name: "Set Up Tunnel"
background: true
command: |
curl https://saucelabs.com/downloads/sc-4.7.1-linux.tar.gz -o saucelabs.tar.gz
tar -xzf saucelabs.tar.gz
cd sc-*
bin/sc -u ${SAUCE_USERNAME} -k ${SAUCE_ACCESS_KEY} --region ${SAUCE_REGION} --tunnel-name ${SAUCE_TUNNEL_IDENTIFIER}
- run:
name: "Install Sauce Labs saucectl"
name: Ensure docker-credential-helper is installed
command: |
curl -fsSL -o get_saucectl.sh https://saucelabs.github.io/saucectl/install && \
chmod 700 get_saucectl.sh && \
sudo ./get_saucectl.sh -b /usr/local/bin
sudo apt update && sudo apt install amazon-ecr-credential-helper
- setup_remote_docker:
docker_layer_caching: false
version: default
- run:
name: "Configure Sauce saucectl"
name: "Build and push image to ECR"
command: |
saucectl configure -u ${SAUCE_USERNAME} -a ${SAUCE_ACCESS_KEY}
- run:
name: "Run Cypress on Sauce"
command: |
saucectl run --tunnel-name ${SAUCE_TUNNEL_IDENTIFIER} -e TEST_EMAIL=${TEST_EMAIL}

PROJECT_REPOSITORY_URL=<< pipeline.parameters.ecr_repo_host >>/<< parameters.image >>
echo "Repository URL: $PROJECT_REPOSITORY_URL"
docker build -f << parameters.dockerfile >> -t "${PROJECT_REPOSITORY_URL}:${CIRCLE_SHA1}" .
docker push "${PROJECT_REPOSITORY_URL}:${CIRCLE_SHA1}"
tag_image:
executor:
name: aws-ecr/default
parameters:
additional_tag:
type: string
source_tag:
type: string
default: "$CIRCLE_SHA1"
steps:
- attach_workspace:
at: ~/
- anyvan_github_ssh_key/install_ssh_key
- aws-ecr/tag_image:
repo: "<< pipeline.parameters.app_name >>"
source_tag: "<< parameters.source_tag >>"
target_tag: "<< parameters.additional_tag >>"


workflows:
build:
# Default workflow - Deploy to PR Environment
deploy_to_pr_env:
when:
and:
- not:
equal: ["main", << pipeline.git.branch >>]
- not:
equal: ["", << pipeline.parameters.jira_ticket_number >>]
jobs:
- cleanUp
- runUnitTests:
- aws/init: &aws_init
name: "Log in to AWS"
context: anyvan
region: << pipeline.parameters.region >>
account: PRODUCTION HORIZONTAL TEST1
persist: .aws
# - aws-ecr-helper/create_aws_ecr: &create_ecr
# name: "Create AWS ECR Client repository"
# context: anyvan
# module_path: "iac/terraform/image_repository"
# app_name: twilio-webchat-client
# tf_version: << pipeline.parameters.terraform_version >>
# requires:
# - "Log in to AWS"
# - aws-ecr-helper/create_aws_ecr:
# <<: *create_ecr
# name: "Create AWS ECR Server repository"
# app_name: twilio-webchat-server
- aws-ecr-helper/ecr_login: &ecr_login
name: "Log in to AWS ECR"
context: anyvan
requires:
# - "Create AWS ECR Server repository"
# - "Create AWS ECR Client repository"
- "Log in to AWS"
# Build Server Image for PR Environment
- build-and-push:
name: build_webchat_server_pr
project-root: .
entry: .
repository: server
image: twilio-webchat-server
dockerfile: Dockerfile.server
env: development
requires:
- "Log in to AWS ECR"

# Build Client Image for PR Environment
- build-and-push:
name: build_webchat_client_pr
project-root: .
entry: .
repository: client
image: twilio-webchat-client
dockerfile: Dockerfile.client
env: development
requires:
- "Log in to AWS ECR"
- hold_pr:
type: approval
requires:
- build_webchat_client_pr
- build_webchat_server_pr
# Plan Terraform for PR Environment
- terraform-helper/plan: &plan
name: plan_webchat_widget_pr
context:
- anyvan
- twilio-flex-stage
workspace: << pipeline.parameters.app_name >>_branches<< pipeline.parameters.jira_ticket_number >>
var: >-
jira_ticket_number=<< pipeline.parameters.jira_ticket_number >>,
server_container_image_url=<< pipeline.parameters.ecr_repo_host >>/twilio-webchat-server:${CIRCLE_SHA1},
client_container_image_url=<< pipeline.parameters.ecr_repo_host >>/twilio-webchat-client:${CIRCLE_SHA1},
git_sha=$CIRCLE_SHA1,
terraform_version=<< pipeline.parameters.terraform_version >>
var_file: env/development.tfvars
modules_branch: << pipeline.parameters.modules >>
path: iac/terraform/
terraform_version: << pipeline.parameters.terraform_version >>
requires:
- hold_pr

# Apply Terraform for PR Environment
- terraform-helper/apply: &apply
name: apply_webchat_widget_pr
context: anyvan
workspace: << pipeline.parameters.app_name >>_branches<< pipeline.parameters.jira_ticket_number >>
modules_branch: << pipeline.parameters.modules >>
path: iac/terraform/
terraform_version: << pipeline.parameters.terraform_version >>
requires:
- cleanUp
- cypress/run:
- plan_webchat_widget_pr

pull_request_closed:
when:
and:
- equal: [pull_request_closed, << pipeline.parameters.workflow >>]
- not:
equal: [main, << pipeline.git.branch >>]
- not:
equal: ["", << pipeline.parameters.jira_ticket_number >>]
jobs:
- aws/init:
*aws_init
- terraform-helper/plan:
<<: *plan
name: "Plan destroy PR environment"
env: branches
destroy: true
var_file: env/branches.tfvars
workspace: << pipeline.parameters.app_name >>_branches<< pipeline.parameters.jira_ticket_number >>
requires:
- cleanUp
executor: with-chrome
post-install:
- run: "yarn bootstrap \
accountSid=$TWILIO_ACCOUNT_SID \
authToken=$TWILIO_AUTH_TOKEN \
addressSid=$TWILIO_ADDRESS_SID \
apiKey=$TWILIO_API_KEY \
apiSecret=$TWILIO_API_SECRET \
conversationsServiceSid=$TWILIO_CONVERSATIONS_SERVICE_SID
"
browser: chrome
yarn: true
start: 'yarn start & yarn server:ci' # start server before running tests
store_artifacts: true
- cypressTestsOnSauce:
- "Log in to AWS"
- terraform-helper/apply:
<<: *apply
name: "Apply Destroy of PR environment"
destroy: true
workspace: << pipeline.parameters.app_name >>_branches<< pipeline.parameters.jira_ticket_number >>
requires:
- cleanUp
- "Plan destroy PR environment"









22 changes: 22 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
node_modules
npm-debug.log
yarn-debug.log
yarn-error.log
.git
.gitignore
README.md
.env
.nyc_output
coverage
.nyc_output
.coverage
.cache
build
dist
.DS_Store
*.log
.vscode
.idea
*.swp
*.swo
*~
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-shadow": ["error"],
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/member-ordering": "off",
"import/no-duplicates": ["error"],
"spaced-comment": "warn",
"prefer-named-capture-group": "off"
Expand Down
Loading