Skip to content

Commit

Permalink
Merge branch 'beta' into prod
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Nov 6, 2024
2 parents 1d099e4 + 4587e20 commit d1c3187
Show file tree
Hide file tree
Showing 12 changed files with 3,595 additions and 3,413 deletions.
1 change: 0 additions & 1 deletion .depcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ ignores: [
"jest-mock-extended",
"jest-sorted",
"ts-jest",
"ts-node",
"typescript"
]
86 changes: 56 additions & 30 deletions .github/workflows/deploy-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ on:
branches:
- beta

env:
AWS_REGION: us-east-1
CONTAINER_NAME: api-xyo-automation-witness

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: beta
environment:
name: beta
url: ${{ vars.URL }}

steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Set up Docker Buildx
id: buildx
Expand All @@ -28,45 +28,71 @@ jobs:
[worker.oci]
max-parallelism = 4
- uses: actions/setup-node@v3
with:
node-version: "18"
cache: "yarn"

- name: install
run: yarn install

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@13d241b293754004c80624b5567555c4a39ffbe3
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ECS_DEPLOY_ACCESS_KEY_SELECT }}
aws-secret-access-key: ${{ secrets.AWS_ECS_DEPLOY_SECRET_KEY_SELECT }}
aws-region: ${{ env.AWS_REGION }}
aws-region: ${{ vars.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@aaf69d68aa3fb14c1d5a6be9ac61fe15b48453a2
env:
AWS_REGION: ${{ vars.AWS_REGION }}

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
DOCKER_BUILDKIT: 1
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG .
docker push $ECR_REGISTRY/${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG"
docker build -t ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG} .
docker push ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG}
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@374ee96751fffe528c09b5f427848da60469bb55
- name: Install kubectl
uses: azure/setup-kubectl@3e0aec4d80787158d308d7b364cb1b702e7feb7f # v4.0.0
with:
task-definition: .aws/task-definition-beta.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
environment-variables: |
AWS_ENV_SECRET_ARN=${{ secrets.AWS_ENV_SECRET_ARN }}
version: latest

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@3cc43061dd30ad47511af35bca46e2c1435b9035
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ secrets.ECS_SERVICE }}
cluster: ${{ secrets.ECS_CLUSTER }}
wait-for-service-stability: true
- name: Set up EKS kubeconfig
run: aws eks update-kubeconfig --name ${{ secrets.EKS_CLUSTER_NAME }}
env:
AWS_REGION: ${{ vars.AWS_REGION }}

- name: Update Deployment in Kubernetes
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
run: |
kubectl --namespace ${{ vars.NAMESPACE }} set image deployment/deployment app=$ECR_REGISTRY/${ECR_REPOSITORY}:${IMAGE_TAG}
kubectl rollout status deployment
- name: invalidate cloudfront distribution and wait for completion
run: |
PATHS=('/' '/*')
INVALIDATION_ID=$(aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --query 'Invalidation.Id' --output text --paths "${PATHS[@]}")
aws cloudfront wait invalidation-completed --distribution-id $DISTRIBUTION_ID --id $INVALIDATION_ID
env:
DISTRIBUTION_ID: ${{ secrets.DISTRIBUTION_ID }}

# - name: Notify deploy to Rollbar
# uses: rollbar/[email protected]
# id: rollbar_deploy
# with:
# environment: "beta"
# version: ${{ github.sha }}
# env:
# ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_ACCESS_TOKEN }}
# ROLLBAR_USERNAME: ${{ github.actor }}
84 changes: 54 additions & 30 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ on:
branches:
- prod

env:
AWS_REGION: us-east-1
CONTAINER_NAME: api-xyo-automation-witness

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment:
name: prod
url: https://api.automation-witness.xyo.network/
url: ${{ vars.URL }}

steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Set up Docker Buildx
id: buildx
Expand All @@ -29,45 +27,71 @@ jobs:
[worker.oci]
max-parallelism = 4
- uses: actions/setup-node@v3
with:
node-version: "18"
cache: "yarn"

- name: install
run: yarn install

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@13d241b293754004c80624b5567555c4a39ffbe3
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ECS_DEPLOY_ACCESS_KEY_SELECT }}
aws-secret-access-key: ${{ secrets.AWS_ECS_DEPLOY_SECRET_KEY_SELECT }}
aws-region: ${{ env.AWS_REGION }}
aws-region: ${{ vars.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@aaf69d68aa3fb14c1d5a6be9ac61fe15b48453a2
env:
AWS_REGION: ${{ vars.AWS_REGION }}

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
DOCKER_BUILDKIT: 1
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG .
docker push $ECR_REGISTRY/${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG"
docker build -t ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG} .
docker push ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG}
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@374ee96751fffe528c09b5f427848da60469bb55
- name: Install kubectl
uses: azure/setup-kubectl@3e0aec4d80787158d308d7b364cb1b702e7feb7f # v4.0.0
with:
task-definition: .aws/task-definition-prod.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
environment-variables: |
AWS_ENV_SECRET_ARN=${{ secrets.AWS_ENV_SECRET_ARN }}
version: latest

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@3cc43061dd30ad47511af35bca46e2c1435b9035
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ secrets.ECS_SERVICE }}
cluster: ${{ secrets.ECS_CLUSTER }}
wait-for-service-stability: true
- name: Set up EKS kubeconfig
run: aws eks update-kubeconfig --name ${{ secrets.EKS_CLUSTER_NAME }}
env:
AWS_REGION: ${{ vars.AWS_REGION }}

- name: Update Deployment in Kubernetes
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
run: |
kubectl --namespace ${{ vars.NAMESPACE }} set image deployment/deployment app=$ECR_REGISTRY/${ECR_REPOSITORY}:${IMAGE_TAG}
kubectl rollout status deployment
- name: invalidate cloudfront distribution and wait for completion
run: |
PATHS=('/' '/*')
INVALIDATION_ID=$(aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --query 'Invalidation.Id' --output text --paths "${PATHS[@]}")
aws cloudfront wait invalidation-completed --distribution-id $DISTRIBUTION_ID --id $INVALIDATION_ID
env:
DISTRIBUTION_ID: ${{ secrets.DISTRIBUTION_ID }}

# - name: Notify deploy to Rollbar
# uses: rollbar/[email protected]
# id: rollbar_deploy
# with:
# environment: "prod"
# version: ${{ github.sha }}
# env:
# ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_ACCESS_TOKEN }}
# ROLLBAR_USERNAME: ${{ github.actor }}
4 changes: 0 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"runtimeArgs": [
"--max-old-space-size=8192",
"--experimental-specifier-resolution=node",
"--loader=ts-node/esm"
],
"envFile": "${workspaceFolder}/.env",
"sourceMaps": true,
Expand All @@ -28,8 +26,6 @@
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"runtimeArgs": [
"--max-old-space-size=8192",
"--experimental-specifier-resolution=node",
"--loader=ts-node/esm"
],
"envFile": "${workspaceFolder}/.env",
"sourceMaps": true,
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
".DS_Store": true,
"node_modules": true,
"build": true,
"dist": true,
"dist": false,
".webpack": true,
".serverless": true,
".rollup.cache": true
Expand Down
34 changes: 26 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
# syntax=docker/dockerfile:1

# Define build-time arguments
ARG NODE_VERSION=22

# Build here and pull down all the devDependencies
FROM node:20 AS builder
FROM node:${NODE_VERSION} AS builder
WORKDIR /app
COPY . .
RUN corepack enable
RUN corepack prepare
RUN yarn install
RUN yarn xy compile
RUN yarn xy build

# Just install the production dependencies here
FROM node:20 AS dependencies
FROM node:${NODE_VERSION} AS dependencies
WORKDIR /app
COPY . .
RUN corepack enable
RUN corepack prepare
RUN yarn workspaces focus --production

# Copy over the compiled output and production dependencies
# into a slimmer container
FROM node:20-alpine
# FROM node:${NODE_VERSION}-alpine
FROM node:${NODE_VERSION}
EXPOSE 80
WORKDIR /app
CMD ["yarn", "launch"]
CMD ["node", "./dist/node/index.js"]

# Install required packages
# RUN apk add --no-cache file imagemagick ffmpeg
RUN apt-get update && apt-get install -y file imagemagick ffmpeg

COPY --from=dependencies /app/package.json ./package.json
RUN corepack enable
RUN corepack prepare
COPY --from=dependencies /app/.yarn ./.yarn
COPY --from=dependencies /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/yarn.lock ./yarn.lock
COPY --from=builder /app/dist/node ./dist/node
COPY --from=dependencies /app/yarn.lock ./yarn.lock
COPY --from=dependencies /root/.yarn /root/.yarn
COPY --from=builder /app/dist/node ./dist/node

1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"ethersproject",
"Ethgasstation",
"hdnode",
"nodenext",
"pako",
"satoshi",
"Trouw",
Expand Down
17 changes: 5 additions & 12 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
const generateJestConfig = ({ esModules }) => {
const esModulesList = Array.isArray(esModules) ? esModules.join('|') : esModules
return {
coveragePathIgnorePatterns: ['<rootDir>/src/Server'],
coverageThreshold: {
global: {
branches: 50,
functions: 70,
lines: 70,
statements: 70,
},
},
coveragePathIgnorePatterns: ['<rootDir>/(.*)/dist'],
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
preset: 'ts-jest/presets/default-esm',
preset: 'ts-jest',
setupFiles: ['dotenv/config'],
setupFilesAfterEnv: [],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
testTimeout: 15000,
testRegex: String.raw`(/__tests__/.*|(\.|/)(test|spec))\.tsx?$`,
testTimeout: 15_000,
transform: {
[`(${esModulesList}).+\\.js$`]: [
'babel-jest',
Expand Down
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"env": {
"NODE_ENV": "development"
},
"exec": "node -r ts-node/register ./src/index.ts",
"exec": "node ./dist/node/index.js",
"ext": ".ts",
"ignore": ["**/*.spec.ts"],
"watch": ["./src"]
Expand Down
Loading

0 comments on commit d1c3187

Please sign in to comment.