diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 000000000..0168faf58 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,42 @@ +name: Continuous Delivery + +env: + AWS_REGION: eu-north-1 + EBS_APP_NAME: bsa-2024-outreachvids + ENVIRONMENT: next + +on: + push: + branches: + - next + workflow_dispatch: + +jobs: + cd: + runs-on: ubuntu-latest + + steps: + - name: Checkout Source Code + uses: actions/checkout@v4 + + - name: Install NodeJS + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + + - name: Zipping Deployment Package + run: | + zip -r build.zip . -x .github + + - name: Deploy to EB + uses: einaregilsson/beanstalk-deploy@v21 + with: + use_existing_version_if_available: true + aws_access_key: ${{ secrets.AWS_ACCESS_KEY }} + aws_secret_key: ${{ secrets.AWS_SECRET_KEY }} + region: ${{ env.AWS_REGION }} + application_name: ${{ env.EBS_APP_NAME }} + environment_name: ${{ env.ENVIRONMENT }} + version_label: ${{ github.sha }} + deployment_package: ./build.zip + wait_for_environment_recovery: 300 diff --git a/backend/src/common/database/base-database.package.ts b/backend/src/common/database/base-database.package.ts index dabeafca9..ab87d8d9d 100644 --- a/backend/src/common/database/base-database.package.ts +++ b/backend/src/common/database/base-database.package.ts @@ -32,9 +32,17 @@ class BaseDatabase implements Database { } private get initialConfig(): TKnex.Config { + const sslConfig = + this.appConfig.ENV.APP.ENVIRONMENT === AppEnvironment.DEVELOPMENT + ? null + : { ssl: { rejectUnauthorized: false } }; + return { client: this.appConfig.ENV.DB.DIALECT, - connection: this.appConfig.ENV.DB.CONNECTION_STRING, + connection: { + connectionString: this.appConfig.ENV.DB.CONNECTION_STRING, + ...(!!sslConfig && sslConfig), + }, pool: { min: this.appConfig.ENV.DB.POOL_MIN, max: this.appConfig.ENV.DB.POOL_MAX, diff --git a/backend/tsconfig.json b/backend/tsconfig.json index 10167079e..414e46c76 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -6,6 +6,7 @@ "baseUrl": ".", "paths": { "~/*": ["./src/*"] - } + }, + "outDir": "build" } } diff --git a/package-lock.json b/package-lock.json index 4b51f6ece..1a4340a92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,6 @@ "packages": { "": { "name": "project", - "hasInstallScript": true, "workspaces": [ "shared", "backend", diff --git a/package.json b/package.json index 07b2f7e62..bffdc2a17 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,10 @@ "frontend" ], "scripts": { - "postinstall": "npm run build:shared", "build:shared": "npm run build -w shared", "build:frontend": "npm run build -w frontend", "build:backend": "npm run build -w backend", + "build": "npm run build:shared && npm run build:backend && npm run build:frontend && sh ./prepare-build.sh", "lint:editor": "editorconfig-checker", "lint:fs": "ls-lint", "lint:type": "npm run lint:type --workspaces --if-present", @@ -25,7 +25,10 @@ "lint:format": "prettier --check \"**/*.{ts,tsx,json,md,scss,html,yml}\"", "lint": "npm run lint:editor && npm run lint:fs && npm run lint:format && npm run lint:type && npm run lint:js && npm run lint:css", "lint:fix": "npm run lint:fix -w frontend && npm run lint:fix -w backend", - "format": "prettier --write \"**/*.{ts,tsx,json,md,css,html,yml}\"" + "format": "prettier --write \"**/*.{ts,tsx,json,md,css,html,yml}\"", + "migrate": "npm run migrate:dev -w backend", + "prestart": "npm install --include=dev && npm run build && npm run migrate", + "start": "cd ./build/backend && npm run start" }, "devDependencies": { "@commitlint/cli": "19.4.0", diff --git a/prepare-build.sh b/prepare-build.sh new file mode 100644 index 000000000..384432fa0 --- /dev/null +++ b/prepare-build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +mkdir -p ./build/backend; mv ./backend/build/* ./build/backend +mkdir ./build/backend/public; mv ./frontend/build/* ./build/backend/public +cp ./backend/package.json ./build/backend +cp package.json package-lock.json ./build