From d5776efaaeb7f838b49fc3881a81fabc1e644f68 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Sun, 6 Oct 2024 10:01:47 -0400 Subject: [PATCH 01/19] add application db schema --- src/v1/db/Application.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/v1/db/Application.js diff --git a/src/v1/db/Application.js b/src/v1/db/Application.js new file mode 100644 index 0000000..b147241 --- /dev/null +++ b/src/v1/db/Application.js @@ -0,0 +1,20 @@ +const mongoose = require('mongoose'); + +const ApplicationSchema = new mongoose.Schema({ + _id: String, + guildSnowflake: String, + userSnowflake: String, + experience: String, + position: String, + server: String, + botexp: String, + avail: String, + message: String, + about: String, + age: String, + joindate: String +}) + +const Application = mongoose.model('Application', ApplicationSchema); + +module.exports = Application; \ No newline at end of file From c2fa3e346adc4125b83890e6437bf27a95fbe9c0 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Sun, 6 Oct 2024 10:02:16 -0400 Subject: [PATCH 02/19] add post application controller --- src/v1/controllers/ApplicationControllers.js | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/v1/controllers/ApplicationControllers.js diff --git a/src/v1/controllers/ApplicationControllers.js b/src/v1/controllers/ApplicationControllers.js new file mode 100644 index 0000000..5f75dea --- /dev/null +++ b/src/v1/controllers/ApplicationControllers.js @@ -0,0 +1,25 @@ +const Application = require('../db/Application'); +const clean = str => str.replace(/[^\x00-\x7F]/g, ""); +const escape = require('escape-html'); + +async function PostApplication(req, res) { + + const { + experience, + position, + server, + botexp, + avail, + message, + about, + age, + joindate + } = req.body; + + // Get the current user + const self = await req.state.self(); + + + + +} \ No newline at end of file From fa2bc5512f608acd6ee557d02d656711d6b3675a Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Sun, 6 Oct 2024 10:38:31 -0400 Subject: [PATCH 03/19] edit schema and finish controllers --- src/v1/controllers/ApplicationControllers.js | 102 ++++++++++++++++++- src/v1/db/Application.js | 2 +- 2 files changed, 100 insertions(+), 4 deletions(-) diff --git a/src/v1/controllers/ApplicationControllers.js b/src/v1/controllers/ApplicationControllers.js index 5f75dea..5f63bc4 100644 --- a/src/v1/controllers/ApplicationControllers.js +++ b/src/v1/controllers/ApplicationControllers.js @@ -4,7 +4,7 @@ const escape = require('escape-html'); async function PostApplication(req, res) { - const { + let { experience, position, server, @@ -13,13 +13,109 @@ async function PostApplication(req, res) { message, about, age, - joindate + joindate, + guildSnowflake } = req.body; + if (experience == undefined || + position == undefined || + server == undefined || + botexp == undefined || + avail == undefined || + message == undefined || + about == undefined || + age == undefined || + joindate == undefined || + guildSnowflake == undefined + ) { + + res.status(400); + res.json({ + status: 400, + error: "failed to submit, fill in all the fields." + }) + + } + // Get the current user const self = await req.state.self(); + const date = new Date(); + experience = clean(escape(experience)) + position = clean(escape(position)) + server = clean(escape(server)) + botexp = clean(escape(botexp)) + avail = clean(escape(avail)) + message = clean(escape(message)) + about = clean(escape(about)) + age = clean(escape(age)) + joindate = clean(escape(joindate)) + + try { + + const application = new Application({ + guildSnowflake: guildSnowflake, + userSnowflake: self.id, + submitDate: date.getTime(), + experience: experience, + position: position, + server: server, + botexp: botexp, + avail: avail, + message: message, + about: about, + age: age, + joindate: joindate + }) + + application.save(); + + res.status(200); + + } catch (e) { + + console.error(e.message); + + res.status(500); + res.json({ + 'status': 500, + 'error': 'An Error occured please try again.' + }) + + } + +} + +async function GetApplicatons(req, res) { + + const guildid = req.body.guildid; + + if (guildid === undefined) { + + res.status(400).json({ + status: 400, + message: 'Invalid id' + }); + + return; + } + + try { + + const applications = await Application.find({guildSnowflake: guildid}); + res.status(200).json(applications); + + } catch (e) { + + console.error(e.message); + res.status(500); + res.json({ + 'status': 500, + 'error': 'An Error occured. Please try again later.' + }); + } +} -} \ No newline at end of file +module.exports = {PostApplication, GetApplicatons} \ No newline at end of file diff --git a/src/v1/db/Application.js b/src/v1/db/Application.js index b147241..03caca4 100644 --- a/src/v1/db/Application.js +++ b/src/v1/db/Application.js @@ -1,9 +1,9 @@ const mongoose = require('mongoose'); const ApplicationSchema = new mongoose.Schema({ - _id: String, guildSnowflake: String, userSnowflake: String, + submitDate: String, experience: String, position: String, server: String, From 5f00bd11acb8af0d3fd024c09ea1475ff4e418b4 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Sun, 6 Oct 2024 10:48:36 -0400 Subject: [PATCH 04/19] add applications routes --- src/v1/controllers/ApplicationControllers.js | 6 +++--- src/v1/routers/ApplicationRoutes.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/v1/routers/ApplicationRoutes.js diff --git a/src/v1/controllers/ApplicationControllers.js b/src/v1/controllers/ApplicationControllers.js index 5f63bc4..b35f6e5 100644 --- a/src/v1/controllers/ApplicationControllers.js +++ b/src/v1/controllers/ApplicationControllers.js @@ -85,9 +85,9 @@ async function PostApplication(req, res) { } -async function GetApplicatons(req, res) { +async function GetApplications(req, res) { - const guildid = req.body.guildid; + const guildid = req.params.guildid; if (guildid === undefined) { @@ -118,4 +118,4 @@ async function GetApplicatons(req, res) { } -module.exports = {PostApplication, GetApplicatons} \ No newline at end of file +module.exports = {PostApplication, GetApplications} \ No newline at end of file diff --git a/src/v1/routers/ApplicationRoutes.js b/src/v1/routers/ApplicationRoutes.js new file mode 100644 index 0000000..6c075cc --- /dev/null +++ b/src/v1/routers/ApplicationRoutes.js @@ -0,0 +1,13 @@ +const express = require("express"); +const router = express.Router(); + +const { PostApplication, GetApplications} = require("../controllers/AppealsControllers.js"); + +const authenticated = require('../../auth/middlewares/authenticated.js'); +const whitelist = require('../../auth/middlewares/whitelist.js'); + +router.get('/:guildid', authenticated, whitelist, GetApplications); + +router.post('/', authenticated, PostApplication) + +module.exports = router; \ No newline at end of file From cacc0892422444a2605511049dc90335c759bc04 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Sun, 6 Oct 2024 10:52:37 -0400 Subject: [PATCH 05/19] add router to api --- src/v1/v1.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/v1/v1.js b/src/v1/v1.js index ec50aa6..1a7cc32 100644 --- a/src/v1/v1.js +++ b/src/v1/v1.js @@ -5,6 +5,7 @@ const Appeals = require('./routers/AppealsRoutes.js'); const Notes = require('./routers/UsernoteRoutes.js'); const Insights = require('./routers/InsightRoutes.js'); const Stats = require('./routers/StatRoutes.js'); +const Applications = require('./routers/ApplicationRoutes.js'); const router = express.Router(); @@ -17,7 +18,7 @@ router.use('/appeals', Appeals); router.use('/notes', Notes); router.use('/insights', Insights); router.use('/stats', Stats); - +router.use('/applications', Applications) router.use((req, res) => { const errObj = {'status': 404, 'error': 'Page not found'}; From 6fded0fd4549b068bf658f3ee6d05657f3c85b26 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Sun, 6 Oct 2024 11:04:49 -0400 Subject: [PATCH 06/19] add check for exisiting application --- src/v1/controllers/ApplicationControllers.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/v1/controllers/ApplicationControllers.js b/src/v1/controllers/ApplicationControllers.js index b35f6e5..d482c05 100644 --- a/src/v1/controllers/ApplicationControllers.js +++ b/src/v1/controllers/ApplicationControllers.js @@ -40,6 +40,20 @@ async function PostApplication(req, res) { // Get the current user const self = await req.state.self(); const date = new Date(); + + const existing = await Application.find({'userSnowflake': self.id}); + + if (existing.length > 0) { + + res.status(403); + res.json({ + status: 403, + error: "Unauthorized you already have applied." + }) + + return; + } + experience = clean(escape(experience)) position = clean(escape(position)) server = clean(escape(server)) From 66477418afb13bde896967912c4f45d5c9918285 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Sun, 6 Oct 2024 11:16:08 -0400 Subject: [PATCH 07/19] fix application routes --- src/v1/routers/ApplicationRoutes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v1/routers/ApplicationRoutes.js b/src/v1/routers/ApplicationRoutes.js index 6c075cc..a7df3c2 100644 --- a/src/v1/routers/ApplicationRoutes.js +++ b/src/v1/routers/ApplicationRoutes.js @@ -1,7 +1,7 @@ const express = require("express"); const router = express.Router(); -const { PostApplication, GetApplications} = require("../controllers/AppealsControllers.js"); +const { PostApplication, GetApplications} = require("../controllers/ApplicationControllers.js"); const authenticated = require('../../auth/middlewares/authenticated.js'); const whitelist = require('../../auth/middlewares/whitelist.js'); From ae9c9e1251b69ab328524616eef2d9bdd8c3d9e2 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Sun, 6 Oct 2024 11:31:47 -0400 Subject: [PATCH 08/19] send reply apon application --- src/v1/controllers/ApplicationControllers.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/v1/controllers/ApplicationControllers.js b/src/v1/controllers/ApplicationControllers.js index d482c05..b3438e1 100644 --- a/src/v1/controllers/ApplicationControllers.js +++ b/src/v1/controllers/ApplicationControllers.js @@ -84,6 +84,10 @@ async function PostApplication(req, res) { application.save(); res.status(200); + res.json({ + 'status': 200, + 'message': "application submitted." + }) } catch (e) { From 64ef220e27e9bf43a713c0ff6646f1781a8d5f4c Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Sun, 6 Oct 2024 12:49:53 -0400 Subject: [PATCH 09/19] add missing return after failure to prevent crash --- src/v1/controllers/ApplicationControllers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/v1/controllers/ApplicationControllers.js b/src/v1/controllers/ApplicationControllers.js index b3438e1..77fb5cc 100644 --- a/src/v1/controllers/ApplicationControllers.js +++ b/src/v1/controllers/ApplicationControllers.js @@ -35,6 +35,7 @@ async function PostApplication(req, res) { error: "failed to submit, fill in all the fields." }) + return; } // Get the current user From 73e05c7bfacea6bd6f471350189d13e01e125b05 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Fri, 13 Dec 2024 02:47:53 -0500 Subject: [PATCH 10/19] add deploy workflow --- .github/workflows/aws-deploy-stg.yml | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/aws-deploy-stg.yml diff --git a/.github/workflows/aws-deploy-stg.yml b/.github/workflows/aws-deploy-stg.yml new file mode 100644 index 0000000..e17d429 --- /dev/null +++ b/.github/workflows/aws-deploy-stg.yml @@ -0,0 +1,75 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# GitHub recommends pinning actions to a commit SHA. +# To get a newer version, you will need to update the SHA. +# You can also reference a tag or branch, but the action may change without warning. + +name: Deploy to Amazon ECS + +on: + push: + branches: + - main + +env: + AWS_REGION: us-east-1 # set this to your preferred AWS region, e.g. us-west-1 + ECR_REPOSITORY: 140023379914.dkr.ecr.us-east-1.amazonaws.com/billiecord_ecr # set this to your Amazon ECR repository name + ECS_SERVICE: ARC_API # set this to your Amazon ECS service name + ECS_CLUSTER: BilleCluster # set this to your Amazon ECS cluster name + ECS_TASK_DEFINITION: ARC_API # set this to the path to your Amazon ECS task definition + # file, e.g. .aws/task-definition.json + CONTAINER_NAME: ARC_API # set this to the name of the container in the + # containerDefinitions section of your task definition + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + environment: STG + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a + + - name: Build, tag, and push image to Amazon ECR + id: build-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + 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/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT + + - name: Fill in the new image ID in the Amazon ECS task definition + id: task-def + uses: aws-actions/amazon-ecs-render-task-definition@c804dfbdd57f713b6c079302a4c01db7017a36fc + with: + task-definition: ${{ env.ECS_TASK_DEFINITION }} + container-name: ${{ env.CONTAINER_NAME }} + image: ${{ steps.build-image.outputs.image }} + + - name: Deploy Amazon ECS task definition + uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a + with: + task-definition: ${{ steps.task-def.outputs.task-definition }} + service: ${{ env.ECS_SERVICE }} + cluster: ${{ env.ECS_CLUSTER }} + wait-for-service-stability: true From 78406908fba5cc48cfc1b9dd824bbc55a7dd945f Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Fri, 13 Dec 2024 02:51:19 -0500 Subject: [PATCH 11/19] add dockerfile --- Dockerfile | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7f2e4ed --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM node AS build-step + +WORKDIR /app + +COPY ./ARC3-DASH/package*.json . +RUN node --max-old-space-size=1000 $(which npm) ci + +COPY ./ARC3-DASH/ . + +RUN node --max-old-space-size=1000 $(which npm) run build + +FROM node +WORKDIR /app + +COPY ./ARC3-API/package*.json /app/ +RUN node --max-old-space-size=1000 $(which npm) ci + +COPY --from=build-step /app/build /app/build +COPY ./keys /keys +COPY ./ARC3-API/src /app/src +COPY ./ARC3-API/bin /app/bin + +ENTRYPOINT [ "node", "--max-old-space-size=1000", "bin/www" ] + + From b6159fb1d199b53c69d93654d287d299a042fd61 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Fri, 13 Dec 2024 03:14:57 -0500 Subject: [PATCH 12/19] fix keyfile and dockerfile --- Dockerfile | 22 +++++++--------------- gen_keyfile.sh | 5 +++++ 2 files changed, 12 insertions(+), 15 deletions(-) create mode 100644 gen_keyfile.sh diff --git a/Dockerfile b/Dockerfile index 7f2e4ed..16abeb9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,16 @@ -FROM node AS build-step - +FROM node:18 WORKDIR /app -COPY ./ARC3-DASH/package*.json . +COPY ./package*.json . RUN node --max-old-space-size=1000 $(which npm) ci -COPY ./ARC3-DASH/ . - -RUN node --max-old-space-size=1000 $(which npm) run build +COPY ./gen_keyfile.sh . -FROM node -WORKDIR /app - -COPY ./ARC3-API/package*.json /app/ -RUN node --max-old-space-size=1000 $(which npm) ci +RUN chmod u+x gen_keyfile.sh +RUN ./gen_keyfile.sh -COPY --from=build-step /app/build /app/build -COPY ./keys /keys -COPY ./ARC3-API/src /app/src -COPY ./ARC3-API/bin /app/bin +COPY ./src ./src +COPY ./bin ./bin ENTRYPOINT [ "node", "--max-old-space-size=1000", "bin/www" ] diff --git a/gen_keyfile.sh b/gen_keyfile.sh new file mode 100644 index 0000000..8d812e3 --- /dev/null +++ b/gen_keyfile.sh @@ -0,0 +1,5 @@ +mkdir keys +openssl rand -base64 756 > ./keys/mongo.keyfile +chmod 400 ./keys/mongo.keyfile +openssl genrsa > ./keys/privkey.pem +openssl req -new -x509 -key ./keys/privkey.pem -out ./keys/fullchain.pem -sha256 -days 3650 -nodes -subj "/C=CA/ST=QC/L=Montreal/O=Billiecord/OU=Engineering/CN=stg.billiecord.com" \ No newline at end of file From 2a11634296603b6210302da232c43a616e899ff8 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Fri, 13 Dec 2024 03:17:17 -0500 Subject: [PATCH 13/19] add user to dockerfile --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 16abeb9..9243e6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,7 @@ FROM node:18 + +USER node + WORKDIR /app COPY ./package*.json . From 876e242f6a39c77db9da64182d3c2e8a4dfff4c7 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Fri, 13 Dec 2024 03:19:12 -0500 Subject: [PATCH 14/19] fix dockerfile run --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9243e6f..9242369 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,8 +9,7 @@ RUN node --max-old-space-size=1000 $(which npm) ci COPY ./gen_keyfile.sh . -RUN chmod u+x gen_keyfile.sh -RUN ./gen_keyfile.sh +RUN chmod u+x gen_keyfile.sh && ./gen_keyfile.sh COPY ./src ./src COPY ./bin ./bin From 13278ac13a7ffe3cd5ee1ed207161e606c61d03a Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Fri, 13 Dec 2024 03:25:01 -0500 Subject: [PATCH 15/19] fix docker build --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9242369..9243e6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,8 @@ RUN node --max-old-space-size=1000 $(which npm) ci COPY ./gen_keyfile.sh . -RUN chmod u+x gen_keyfile.sh && ./gen_keyfile.sh +RUN chmod u+x gen_keyfile.sh +RUN ./gen_keyfile.sh COPY ./src ./src COPY ./bin ./bin From b0e81a6e51c7d7622c72e1f74db8b8ee754b83f4 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Fri, 13 Dec 2024 03:27:42 -0500 Subject: [PATCH 16/19] add --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9243e6f..1979244 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,6 @@ RUN node --max-old-space-size=1000 $(which npm) ci COPY ./gen_keyfile.sh . -RUN chmod u+x gen_keyfile.sh RUN ./gen_keyfile.sh COPY ./src ./src From 4330a125246eabc635f45b2184ee849706c4baf9 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Fri, 13 Dec 2024 03:32:32 -0500 Subject: [PATCH 17/19] fix dockerfile permissions --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1979244..5eb1156 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,11 +4,12 @@ USER node WORKDIR /app -COPY ./package*.json . +COPY --chown=node:node ./package*.json . RUN node --max-old-space-size=1000 $(which npm) ci -COPY ./gen_keyfile.sh . +COPY --chown=node:node ./gen_keyfile.sh . +RUN chmod u+x ./gen_keyfile.sh RUN ./gen_keyfile.sh COPY ./src ./src From 884182470048dff0857f872122e501d1430b6ac3 Mon Sep 17 00:00:00 2001 From: "israel.aristide" Date: Mon, 3 Mar 2025 12:52:18 -0500 Subject: [PATCH 18/19] fix aws workflow --- .github/workflows/aws-deploy-stg.yml | 35 ++++++++++++----- .github/workflows/td.json | 59 ++++++++++++++++++++++++++++ Dockerfile | 13 +++++- src/app.js | 8 +++- 4 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/td.json diff --git a/.github/workflows/aws-deploy-stg.yml b/.github/workflows/aws-deploy-stg.yml index e17d429..d4dc797 100644 --- a/.github/workflows/aws-deploy-stg.yml +++ b/.github/workflows/aws-deploy-stg.yml @@ -15,14 +15,11 @@ on: - main env: - AWS_REGION: us-east-1 # set this to your preferred AWS region, e.g. us-west-1 - ECR_REPOSITORY: 140023379914.dkr.ecr.us-east-1.amazonaws.com/billiecord_ecr # set this to your Amazon ECR repository name - ECS_SERVICE: ARC_API # set this to your Amazon ECS service name - ECS_CLUSTER: BilleCluster # set this to your Amazon ECS cluster name - ECS_TASK_DEFINITION: ARC_API # set this to the path to your Amazon ECS task definition - # file, e.g. .aws/task-definition.json - CONTAINER_NAME: ARC_API # set this to the name of the container in the - # containerDefinitions section of your task definition + AWS_REGION: us-east-2 # set this to your preferred AWS region, e.g. us-west-1 + ECS_CLUSTER: arc-api-cluster # set this to your Amazon ECS cluster name + CONTAINER_NAME: arc-api + ECS_SERVICE: arc-api-service + ECS_TD: .github/workflows/td.json jobs: deploy: @@ -48,9 +45,27 @@ jobs: - name: Build, tag, and push image to Amazon ECR id: build-image env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REGISTRY: "140023379914.dkr.ecr.us-east-2.amazonaws.com" + ECR_REPOSITORY: "arc_api_repo" IMAGE_TAG: ${{ github.sha }} run: | + # Generate the Environment file + touch .env + + echo PORT=${{ secrets.PORT }} >> .env + echo MONGODB_URI=${{ secrets.MONGODB_URI }} >> .env + echo FULLCHAIN=${{ secrets.FULLCHAIN }} >> .env + echo PRIVKEY=${{ secrets.PRIVKEY }} >> .env + echo DISCORD_CLIENT_ID=${{ secrets.DISCORD_CLIENT_ID }} >> .env + echo DISCORD_CLIENT_SECRET=${{ secrets.DISCORD_CLIENT_SECRET }} >> .env + echo DISCORD_REDIRECT_URI=${{ secrets.DISCORD_REDIRECT_URI }} >> .env + echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env + echo CLIENT_REDIRECT_URT=${{ secrets.CLIENT_REDIRECT_UR }} >> .env + echo TOKEN=${{ secrets.TOKEN }} >> .env + echo DIRECT_URL=${{ secrets.DIRECT_URL }} >> .env + ehco HOSTED_URL=${{ secrets.HOSTED_URL }} >> .env + + # Build a docker container and # push it to ECR so that it can # be deployed to ECS. @@ -62,7 +77,7 @@ jobs: id: task-def uses: aws-actions/amazon-ecs-render-task-definition@c804dfbdd57f713b6c079302a4c01db7017a36fc with: - task-definition: ${{ env.ECS_TASK_DEFINITION }} + task-definition: ${{ env.ECS_TD }} container-name: ${{ env.CONTAINER_NAME }} image: ${{ steps.build-image.outputs.image }} diff --git a/.github/workflows/td.json b/.github/workflows/td.json new file mode 100644 index 0000000..31a7398 --- /dev/null +++ b/.github/workflows/td.json @@ -0,0 +1,59 @@ +{ + "taskDefinitionArn": "arn:aws:ecs:us-east-2:140023379914:task-definition/arc-api", + "containerDefinitions": [ + { + "name": "arc-api", + "image": "140023379914.dkr.ecr.us-east-2.amazonaws.com/arc-api-repo", + "cpu": 256, + "memory": 512, + "portMappings": [ + { + "containerPort": 80, + "hostPort": 80, + "protocol": "tcp" + } + ], + "essential": true, + "environment": [], + "mountPoints": [], + "volumesFrom": [], + "systemControls": [] + } + ], + "family": "arc-api", + "taskRoleArn": "arn:aws:iam::140023379914:role/ecsTaskExecutionRole", + "executionRoleArn": "arn:aws:iam::140023379914:role/ecsTaskExecutionRole", + "networkMode": "awsvpc", + "volumes": [], + "status": "ACTIVE", + "requiresAttributes": [ + { + "name": "com.amazonaws.ecs.capability.ecr-auth" + }, + { + "name": "com.amazonaws.ecs.capability.task-iam-role" + }, + { + "name": "ecs.capability.execution-role-ecr-pull" + }, + { + "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18" + }, + { + "name": "ecs.capability.task-eni" + } + ], + "placementConstraints": [], + "compatibilities": [ + "EC2", + "FARGATE" + ], + "requiresCompatibilities": [ + "FARGATE" + ], + "cpu": "256", + "memory": "512", + "registeredAt": "2025-03-03T17:32:35.285Z", + "registeredBy": "arn:aws:iam::140023379914:user/terraform", + "tags": [] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5eb1156..9a1cc70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,10 +10,19 @@ RUN node --max-old-space-size=1000 $(which npm) ci COPY --chown=node:node ./gen_keyfile.sh . RUN chmod u+x ./gen_keyfile.sh -RUN ./gen_keyfile.sh + +WORKDIR /keys +RUN openssl rand -base64 756 > ./mongo.keyfile +RUN chmod 400 ./mongo.keyfile +RUN openssl genrsa > ./privkey.pem +RUN openssl req -new -x509 -key ./privkey.pem -out ./fullchain.pem -sha256 -days 3650 -nodes -subj "/C=CA/ST=QC/L=Montreal/O=Billiecord/OU=Engineering/CN=stg.billiecord.com" + +WORKDIR /app COPY ./src ./src -COPY ./bin ./bin +COPY ./bin ./bin +COPY .env .env + ENTRYPOINT [ "node", "--max-old-space-size=1000", "bin/www" ] diff --git a/src/app.js b/src/app.js index 80cbc98..e8c28a6 100644 --- a/src/app.js +++ b/src/app.js @@ -8,8 +8,14 @@ const whitelist = require('./auth/middlewares/whitelist.js'); const v1 = require('./v1/v1.js'); const auth = require('./auth/auth.js'); +let STATIC_FILES; + +try { + STATIC_FILES = fs.readdirSync(process.env.BUILD_PATH); +} catch { + STATIC_FILES = [] +} -const STATIC_FILES = fs.readdirSync(process.env.BUILD_PATH); app.use( helmet({ From ddd4efb264f0516e7af7aae82fb7bab7951d11f2 Mon Sep 17 00:00:00 2001 From: "israel.aristide" Date: Tue, 4 Mar 2025 08:57:48 -0500 Subject: [PATCH 19/19] fix deploy pipeline --- .github/workflows/aws-deploy-stg.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/aws-deploy-stg.yml b/.github/workflows/aws-deploy-stg.yml index d4dc797..957add2 100644 --- a/.github/workflows/aws-deploy-stg.yml +++ b/.github/workflows/aws-deploy-stg.yml @@ -60,7 +60,7 @@ jobs: echo DISCORD_CLIENT_SECRET=${{ secrets.DISCORD_CLIENT_SECRET }} >> .env echo DISCORD_REDIRECT_URI=${{ secrets.DISCORD_REDIRECT_URI }} >> .env echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env - echo CLIENT_REDIRECT_URT=${{ secrets.CLIENT_REDIRECT_UR }} >> .env + echo CLIENT_REDIRECT_URI=${{ secrets.CLIENT_REDIRECT_URI }} >> .env echo TOKEN=${{ secrets.TOKEN }} >> .env echo DIRECT_URL=${{ secrets.DIRECT_URL }} >> .env ehco HOSTED_URL=${{ secrets.HOSTED_URL }} >> .env diff --git a/package.json b/package.json index 7870a0f..b9d9acd 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "arc3 api and dashboard", "main": "bin/www", "scripts": { - "dev": "nodemon bin/www" + "dev": "nodemon bin/www-dev" }, "author": "izzydotexe", "license": "ISC",