From 57f2468caab0bc983771384a48e23c3683dd9190 Mon Sep 17 00:00:00 2001 From: Gabriel Montes Date: Thu, 28 Mar 2024 15:51:17 -0400 Subject: [PATCH 1/5] Remove deployment from Travis to AWS EB --- .travis.yml | 35 ------------ scripts/1-site | 145 ------------------------------------------------- 2 files changed, 180 deletions(-) delete mode 100644 .travis.yml delete mode 100755 scripts/1-site diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d5c9625..0000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -os: linux -dist: focal -addons: - apt: - packages: - - python3-pip - -language: node_js -node_js: - - '14' - -before_script: git remote set-branches --add origin master && git fetch - -script: npm run lint && npm run format:check && npm run deps:check && npm run test - -jobs: - include: - - stage: Test - - - stage: Deploy - - if: branch =~ ^(master|prod)$ - - script: skip - - before_deploy: - - pip3 install awsebcli --upgrade --user - - npm ci - - deploy: - provider: script - script: scripts/1-site - skip_cleanup: true - on: - all_branches: true diff --git a/scripts/1-site b/scripts/1-site deleted file mode 100755 index a2509bf..0000000 --- a/scripts/1-site +++ /dev/null @@ -1,145 +0,0 @@ -#!/bin/bash - -set -e - -# shellcheck disable=SC1091 -[ -f .env ] && . .env - -CONTACT=${CONTACT:-$(whoami)} -REGION=${REGION:-us-east-2} -STAGE=${STAGE:-staging} - -VERSION=$(git rev-parse HEAD | cut -c-7) - -if [ "$STAGE" = "prod" ]; then - NODE_ENV=production -else - NODE_ENV=$STAGE -fi - -# ------------------------------------------------------------------------------ - -function install-prod-deps-only() { - git submodule deinit --all -f - npx lerna clean --yes - npx lerna bootstrap -- --production --no-optional -} - -function replace-symlinked-deps() { - cp -RL node_modules node_modules_fixed - rm -rf node_modules - mv node_modules_fixed node_modules -} - -function eb-init() { - eb init "$1" \ - --platform "docker" \ - --region "$REGION" -} - -function eb-list() { - eb list \ - --region "$REGION" | { grep "$1" || true; } -} - -function eb-create() { - eb create "$1" \ - --elb-type application \ - --envvars "$2" \ - --instance_type "$3" \ - --region "$REGION" \ - --tags Contact="$CONTACT",Service=Pure -} - -function eb-status() { - eb status "$1" \ - --region "$REGION" | { grep "Status: Ready" || true; } -} - -function eb-deploy() { - # shellcheck disable=SC2046 - eb setenv $(echo "$2" | tr "," " ") \ - --environment "$1" \ - --region "$REGION" \ - --timeout 20 & - PID=$! - - RC=0 - while [ $RC -eq 0 ]; do - echo "Waiting for eb setenv to return..." - sleep 60 - kill -0 $PID 2>/dev/null && RC=$? || RC=$? - done - wait $PID && RC=$? || RC=$? - if [ ! $RC -eq 0 ]; then - exit $RC - fi - - while [ -z "$(eb-status "$1")" ]; do - echo "Waiting for $1 to be ready after setenv..." - sleep 60 - done - - eb deploy "$1" \ - --region "$REGION" \ - --timeout 20 & - PID=$! - - RC=0 - while [ $RC -eq 0 ]; do - echo "Waiting for eb deploy to return..." - sleep 60 - kill -0 $PID 2>/dev/null && RC=$? || RC=$? - done - wait $PID && RC=$? || RC=$? - if [ ! $RC -eq 0 ]; then - exit $RC - fi - - while [ -z "$(eb-status "$1")" ]; do - echo "Waiting for $1 to be ready after deploy..." - sleep 60 - done -} - -# ------------------------------------------------------------------------------ - -CHANGED=$(npx lerna list --all --since HEAD~1) - -if [ -z "$CHANGED" ]; then - echo "No packages have changes, skipping deploy" - exit 0 -fi - -echo "Cleaning up and installing production dependencies only" -install-prod-deps-only - -# ------------------------------------------------------------------------------ - -if [ -n "$(echo "$CHANGED" | { grep pure-finance-site || true; })" ]; then - echo "WEB SERVER" - cd site - - echo "Replacing local dependencies" - replace-symlinked-deps - - echo "Initalizing site" - SITE_EB_APP_NAME=pure-site - eb-init "$SITE_EB_APP_NAME" - - echo "Deploying web server" - SITE_EB_ENV_NAME=$SITE_EB_APP_NAME-$STAGE - SITE_EB_ENV_VARS="NODE_ENV=$NODE_ENV,NODE_URL=$NODE_URL,VERSION=$VERSION" - - ENVIRONMENT=$(eb-list "$SITE_EB_ENV_NAME") - if [ -z "$ENVIRONMENT" ]; then - echo "Creating environment" - eb-create "$SITE_EB_ENV_NAME" "$SITE_EB_ENV_VARS" m5.large - else - echo "Deploying to environment" - eb-deploy "$SITE_EB_ENV_NAME" "$SITE_EB_ENV_VARS" - fi - - echo "WEB SERVER DEPLOYED" - cd .. -fi From d7a9d85f360d8a2464939f67540eebbe4758f4b2 Mon Sep 17 00:00:00 2001 From: Gabriel Montes Date: Tue, 2 Apr 2024 14:04:25 -0400 Subject: [PATCH 2/5] Remove EB-related files --- .../alb-http-to-https-redirection-full.config | 31 ------------------- .../managed-platform-update.config | 7 ----- site/Dockerfile | 10 ------ 3 files changed, 48 deletions(-) delete mode 100644 site/.ebextensions/alb-http-to-https-redirection-full.config delete mode 100644 site/.ebextensions/managed-platform-update.config delete mode 100644 site/Dockerfile diff --git a/site/.ebextensions/alb-http-to-https-redirection-full.config b/site/.ebextensions/alb-http-to-https-redirection-full.config deleted file mode 100644 index a4df69c..0000000 --- a/site/.ebextensions/alb-http-to-https-redirection-full.config +++ /dev/null @@ -1,31 +0,0 @@ -Resources: - AWSEBV2LoadBalancerListener: - Properties: - DefaultActions: - - RedirectConfig: - Host: '#{host}' - Path: /#{path} - Port: '443' - Protocol: HTTPS - Query: '#{query}' - StatusCode: HTTP_301 - Type: redirect - LoadBalancerArn: - Ref: AWSEBV2LoadBalancer - Port: 80 - Protocol: HTTP - Type: AWS::ElasticLoadBalancingV2::Listener - AWSEBV2LoadBalancerListenerHTTPS: - Properties: - Certificates: - - CertificateArn: arn:aws:acm:us-east-2:477041904397:certificate/dcabdcfd-84d9-4bdf-847f-ae559f2c8d9a - DefaultActions: - - TargetGroupArn: - Ref: AWSEBV2LoadBalancerTargetGroup - Type: forward - LoadBalancerArn: - Ref: AWSEBV2LoadBalancer - Port: 443 - Protocol: HTTPS - SSLPolicy: ELBSecurityPolicy-FS-1-2-Res-2020-10 - Type: AWS::ElasticLoadBalancingV2::Listener diff --git a/site/.ebextensions/managed-platform-update.config b/site/.ebextensions/managed-platform-update.config deleted file mode 100644 index 20650f7..0000000 --- a/site/.ebextensions/managed-platform-update.config +++ /dev/null @@ -1,7 +0,0 @@ -option_settings: - aws:elasticbeanstalk:managedactions: - ManagedActionsEnabled: true - PreferredStartTime: "Tue:08:00" - aws:elasticbeanstalk:managedactions:platformupdate: - UpdateLevel: minor - InstanceRefreshEnabled: true diff --git a/site/Dockerfile b/site/Dockerfile deleted file mode 100644 index c9894a7..0000000 --- a/site/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM node:20 - -WORKDIR /usr/src/site - -COPY . . -RUN npm rebuild - -CMD ["npm", "run", "serve"] - -EXPOSE 3000 From c06bbecf1ddffc20be88787e7a7dce617aca3a3c Mon Sep 17 00:00:00 2001 From: Gabriel Montes Date: Thu, 28 Mar 2024 15:52:09 -0400 Subject: [PATCH 3/5] Update ignored files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index c05fb87..4b1c99a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,9 @@ .env*.local !site/.env .eslintcache +.idea .nyc_output +.vscode node_modules packages/**/coverage packages/**/dataset*.json From cc5f69c00448f728ffeaffde0771951380644356 Mon Sep 17 00:00:00 2001 From: Gabriel Montes Date: Thu, 28 Mar 2024 15:52:23 -0400 Subject: [PATCH 4/5] Improve NPM scripts --- package.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 13cb36c..07569df 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,14 @@ "license": "MIT", "author": "Gabriel Montes", "scripts": { + "build": "npm run lerna:run build", + "deps:check": "npm run lerna:run deps:check", "format:check": "prettier --check .", - "deps:check": "lerna run --stream --concurrency 1 deps:check", + "lerna:run": "lerna run --stream --concurrency 1", "lint": "eslint --cache --quiet .", "postinstall": "lerna bootstrap", - "test": "lerna run --stream --concurrency 1 test", - "test:e2e": "npx lerna run --stream --concurrency 1 test:e2e" + "test": "npm run lerna:run test", + "test:e2e": "npm run lerna:run test:e2e" }, "devDependencies": { "@types/mocha": "^9.0.0", From 5160c2f363dd6cfb24b117c007da794f1dbb18bd Mon Sep 17 00:00:00 2001 From: Gabriel Montes Date: Thu, 28 Mar 2024 15:52:01 -0400 Subject: [PATCH 5/5] Add GitHub Action workflows to test and lint --- .github/workflows/lint.yml | 17 +++++++++++++++++ .github/workflows/test.yml | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..89aa529 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,17 @@ +name: Lint + +on: + push: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + - run: npm ci + - run: npm run lint + - run: npm run format:check + - run: npm run deps:check diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c80e775 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: Test + +on: + pull_request: + branches: [ $default-branch ] + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + - run: npm ci + - run: npm run test + - run: npm run test:e2e + env: + BASE_NODE_URL: ${{ vars.BASE_NODE_URL }} + MNEMONIC: ${{ vars.MNEMONIC }} + - run: npm run build