From d5776efaaeb7f838b49fc3881a81fabc1e644f68 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Sun, 6 Oct 2024 10:01:47 -0400 Subject: [PATCH 01/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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/28] 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 ea7be1f2262e9f825c4cfed8078d4f495b20a19f Mon Sep 17 00:00:00 2001 From: Izzy Aristide <44146685+IzzyDotExe@users.noreply.github.com> Date: Tue, 4 Mar 2025 09:01:07 -0500 Subject: [PATCH 19/28] fix deploy pipeline (#23) Co-authored-by: israel.aristide --- .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", From 8796eea88037f71dcbfbd321fd81a35e15d02fbf Mon Sep 17 00:00:00 2001 From: "israel.aristide" Date: Wed, 5 Mar 2025 22:04:47 -0500 Subject: [PATCH 20/28] do not wait for stability --- .github/workflows/aws-deploy-stg.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/aws-deploy-stg.yml b/.github/workflows/aws-deploy-stg.yml index c20d853..c01ad7f 100644 --- a/.github/workflows/aws-deploy-stg.yml +++ b/.github/workflows/aws-deploy-stg.yml @@ -46,11 +46,7 @@ jobs: id: build-image env: ECR_REGISTRY: "140023379914.dkr.ecr.us-east-2.amazonaws.com" -<<<<<<< HEAD - ECR_REPOSITORY: "arc_api_repo" -======= ECR_REPOSITORY: "arc-api-repo" ->>>>>>> 8e4455f9b40ceb4bf46c19df91586cdc8883c0b0 IMAGE_TAG: ${{ github.sha }} run: | # Generate the Environment file @@ -67,13 +63,9 @@ jobs: echo CLIENT_REDIRECT_URI=${{ secrets.CLIENT_REDIRECT_URI }} >> .env echo TOKEN=${{ secrets.TOKEN }} >> .env echo DIRECT_URL=${{ secrets.DIRECT_URL }} >> .env -<<<<<<< HEAD - ehco HOSTED_URL=${{ secrets.HOSTED_URL }} >> .env -======= echo HOSTED_URL=${{ secrets.HOSTED_URL }} >> .env cat .env ->>>>>>> 8e4455f9b40ceb4bf46c19df91586cdc8883c0b0 # Build a docker container and @@ -99,4 +91,4 @@ jobs: task-definition: ${{ steps.task-def.outputs.task-definition }} service: ${{ env.ECS_SERVICE }} cluster: ${{ env.ECS_CLUSTER }} - wait-for-service-stability: true + wait-for-service-stability: false From 5025a3cf3d08c45ee986a4e5570ad13804ddc65f Mon Sep 17 00:00:00 2001 From: "israel.aristide" Date: Wed, 5 Mar 2025 22:42:46 -0500 Subject: [PATCH 21/28] fix bin www --- .github/workflows/aws-deploy-stg.yml | 2 +- bin/www | 3 ++- bin/www-dev | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/aws-deploy-stg.yml b/.github/workflows/aws-deploy-stg.yml index c01ad7f..cae7f7c 100644 --- a/.github/workflows/aws-deploy-stg.yml +++ b/.github/workflows/aws-deploy-stg.yml @@ -91,4 +91,4 @@ jobs: task-definition: ${{ steps.task-def.outputs.task-definition }} service: ${{ env.ECS_SERVICE }} cluster: ${{ env.ECS_CLUSTER }} - wait-for-service-stability: false + wait-for-service-stability: true \ No newline at end of file diff --git a/bin/www b/bin/www index 008d9b9..aacee14 100644 --- a/bin/www +++ b/bin/www @@ -1,5 +1,4 @@ const app = require('../src/app.js'); -const port = process.env.PORT || 3000; const https = require('https'); const fs = require('fs'); @@ -14,6 +13,8 @@ const options = { dotenv.config(); +const port = process.env.PORT || 3000; + (async () => { mongoose.connect(process.env.MONGODB_URI) diff --git a/bin/www-dev b/bin/www-dev index 253f8e6..a67cc9e 100644 --- a/bin/www-dev +++ b/bin/www-dev @@ -1,11 +1,11 @@ const app = require('../src/app.js'); -const port = process.env.PORT || 3000; const mongoose = require('mongoose'); const dotenv = require('dotenv'); dotenv.config(); +const port = process.env.PORT || 3000; (async () => { mongoose.connect(process.env.MONGODB_URI) From 0ec76c58f2b64a32cd1382f07e841234a297a051 Mon Sep 17 00:00:00 2001 From: "israel.aristide" Date: Wed, 5 Mar 2025 22:52:32 -0500 Subject: [PATCH 22/28] add env --- .github/workflows/td.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/td.json b/.github/workflows/td.json index 31a7398..75da66f 100644 --- a/.github/workflows/td.json +++ b/.github/workflows/td.json @@ -14,7 +14,12 @@ } ], "essential": true, - "environment": [], + "environment": [ + { + "PORT": 80, + "MONGODB_URI": "mongodb+srv://izzy:TT7eE1E6UplAoKmC@space.euw888i.mongodb.net/?retryWrites=true&w=majority" + } + ], "mountPoints": [], "volumesFrom": [], "systemControls": [] From f6e10d54747fc3be37f1b2123b126b91f357cfab Mon Sep 17 00:00:00 2001 From: "israel.aristide" Date: Wed, 5 Mar 2025 22:58:01 -0500 Subject: [PATCH 23/28] remove invalid config --- .github/workflows/td.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/td.json b/.github/workflows/td.json index 75da66f..b98f340 100644 --- a/.github/workflows/td.json +++ b/.github/workflows/td.json @@ -15,10 +15,6 @@ ], "essential": true, "environment": [ - { - "PORT": 80, - "MONGODB_URI": "mongodb+srv://izzy:TT7eE1E6UplAoKmC@space.euw888i.mongodb.net/?retryWrites=true&w=majority" - } ], "mountPoints": [], "volumesFrom": [], From b087116a6b0f35c28bdc429ea069bae07451e200 Mon Sep 17 00:00:00 2001 From: "israel.aristide" Date: Wed, 5 Mar 2025 23:18:22 -0500 Subject: [PATCH 24/28] fix task def --- .github/workflows/td.json | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/td.json b/.github/workflows/td.json index 31a7398..19975d7 100644 --- a/.github/workflows/td.json +++ b/.github/workflows/td.json @@ -17,6 +17,14 @@ "environment": [], "mountPoints": [], "volumesFrom": [], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "arc-log-group", + "awslogs-region": "us-east-2", + "awslogs-stream-prefix": "arc-api-logs" + } + }, "systemControls": [] } ], @@ -27,9 +35,18 @@ "volumes": [], "status": "ACTIVE", "requiresAttributes": [ + { + "name": "com.amazonaws.ecs.capability.logging-driver.awslogs" + }, + { + "name": "ecs.capability.execution-role-awslogs" + }, { "name": "com.amazonaws.ecs.capability.ecr-auth" }, + { + "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19" + }, { "name": "com.amazonaws.ecs.capability.task-iam-role" }, @@ -53,7 +70,7 @@ ], "cpu": "256", "memory": "512", - "registeredAt": "2025-03-03T17:32:35.285Z", + "registeredAt": "2025-03-06T04:16:27.412Z", "registeredBy": "arn:aws:iam::140023379914:user/terraform", "tags": [] } \ No newline at end of file From 74b96adc836f556daebf762c8e4c1a20d3e08ab0 Mon Sep 17 00:00:00 2001 From: "israel.aristide" Date: Wed, 5 Mar 2025 23:27:28 -0500 Subject: [PATCH 25/28] fix user --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9a1cc70..7793446 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM node:18 -USER node - WORKDIR /app COPY --chown=node:node ./package*.json . @@ -23,6 +21,8 @@ COPY ./src ./src COPY ./bin ./bin COPY .env .env +EXPOSE 80 + ENTRYPOINT [ "node", "--max-old-space-size=1000", "bin/www" ] From e2759eff869dd369402e5e68ddd30f47eb9afc27 Mon Sep 17 00:00:00 2001 From: "israel.aristide" Date: Wed, 5 Mar 2025 23:48:43 -0500 Subject: [PATCH 26/28] debug log --- .github/workflows/aws-deploy-stg.yml | 1 + .github/workflows/td.json | 3 ++- bin/www | 2 +- bin/www-dev | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/aws-deploy-stg.yml b/.github/workflows/aws-deploy-stg.yml index cae7f7c..73b3c4e 100644 --- a/.github/workflows/aws-deploy-stg.yml +++ b/.github/workflows/aws-deploy-stg.yml @@ -48,6 +48,7 @@ jobs: ECR_REGISTRY: "140023379914.dkr.ecr.us-east-2.amazonaws.com" ECR_REPOSITORY: "arc-api-repo" IMAGE_TAG: ${{ github.sha }} + MONGODB_URI: ${{ secrets.MONGODB_URI }} run: | # Generate the Environment file touch .env diff --git a/.github/workflows/td.json b/.github/workflows/td.json index 19975d7..1430525 100644 --- a/.github/workflows/td.json +++ b/.github/workflows/td.json @@ -14,7 +14,8 @@ } ], "essential": true, - "environment": [], + "environment": [ + ], "mountPoints": [], "volumesFrom": [], "logConfiguration": { diff --git a/bin/www b/bin/www index aacee14..f9e610e 100644 --- a/bin/www +++ b/bin/www @@ -16,7 +16,7 @@ dotenv.config(); const port = process.env.PORT || 3000; (async () => { - + console.log(process.env.MONGODB_URI) mongoose.connect(process.env.MONGODB_URI) const server = https.createServer(options, app); diff --git a/bin/www-dev b/bin/www-dev index a67cc9e..1d28be1 100644 --- a/bin/www-dev +++ b/bin/www-dev @@ -7,7 +7,7 @@ dotenv.config(); const port = process.env.PORT || 3000; (async () => { - + console.log(process.env.MONGODB_URI) mongoose.connect(process.env.MONGODB_URI) app.listen(port, () => { From f73fcbd85c947aa4a7d42f29301dd94a71862e25 Mon Sep 17 00:00:00 2001 From: "israel.aristide" Date: Wed, 5 Mar 2025 23:50:03 -0500 Subject: [PATCH 27/28] kjflk --- .github/workflows/td.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/td.json b/.github/workflows/td.json index f4de8d6..19975d7 100644 --- a/.github/workflows/td.json +++ b/.github/workflows/td.json @@ -14,12 +14,7 @@ } ], "essential": true, -<<<<<<< HEAD - "environment": [ - ], -======= "environment": [], ->>>>>>> 849e36af0c9d37bf9c3902ea9e1609be9d32f1b5 "mountPoints": [], "volumesFrom": [], "logConfiguration": { From a7b209da14217fcf5eb8dfff10ed2be12a35338e Mon Sep 17 00:00:00 2001 From: "israel.aristide" Date: Thu, 6 Mar 2025 00:05:46 -0500 Subject: [PATCH 28/28] inject environment --- .github/workflows/aws-deploy-stg.yml | 28 +++++++++++++++- .github/workflows/td.json | 48 +++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/.github/workflows/aws-deploy-stg.yml b/.github/workflows/aws-deploy-stg.yml index 73b3c4e..650800a 100644 --- a/.github/workflows/aws-deploy-stg.yml +++ b/.github/workflows/aws-deploy-stg.yml @@ -30,6 +30,33 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + env: + PORT: ${{ secrets.PORT }} + MONGODB_URI: ${{ secrets.MONGODB_URI }} + FULLCHAIN: ${{ secrets.FULLCHAIN }} + PRIVKEY: ${{ secrets.PRIVKEY }} + DISCORD_CLIENT_ID: ${{ secrets.DISCORD_CLIENT_ID }} + DISCORD_CLIENT_SECRET: ${{ secrets.DISCORD_CLIENT_SECRET }} + DISCORD_REDIRECT_URI: ${{ secrets.DISCORD_REDIRECT_URI }} + JWT_SECRET: ${{ secrets.JWT_SECRET }} + CLIENT_REDIRECT_URI: ${{ secrets.CLIENT_REDIRECT_URI }} + TOKEN: ${{ secrets.TOKEN }} + DIRECT_URL: ${{ secrets.DIRECT_URL }} + HOSTED_URL: ${{ secrets.HOSTED_URL }} + + run: | + sed -i "s//$MONGODB_URI/g" .github/workflows/td.json + sed -i "s//$PORT/g" .github/workflows/td.json + sed -i "s//$FULLCHAIN/g" .github/workflows/td.json + sed -i "s//$PRIVKEY/g" .github/workflows/td.json + sed -i "s//$DISCORD_CLIENT_ID/g" .github/workflows/td.json + sed -i "s//$DISCORD_CLIENT_SECRET/g" .github/workflows/td.json + sed -i "s//$JWT_SECRET/g" .github/workflows/td.json + sed -i "s//$CLIENT_REDIRECT_URI/g" .github/workflows/td.json + sed -i "s/TOKEN>/$TOKENI/g" .github/workflows/td.json + sed -i "s//$DIRECT_URL/g" .github/workflows/td.json + sed -i "s//$HOSTED_UR/g".github/workflows/td.json + sed -i "s//$DISCORD_REDIRECT_URI/g" .github/workflows/td.json - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83 @@ -48,7 +75,6 @@ jobs: ECR_REGISTRY: "140023379914.dkr.ecr.us-east-2.amazonaws.com" ECR_REPOSITORY: "arc-api-repo" IMAGE_TAG: ${{ github.sha }} - MONGODB_URI: ${{ secrets.MONGODB_URI }} run: | # Generate the Environment file touch .env diff --git a/.github/workflows/td.json b/.github/workflows/td.json index 19975d7..b99484e 100644 --- a/.github/workflows/td.json +++ b/.github/workflows/td.json @@ -14,7 +14,53 @@ } ], "essential": true, - "environment": [], + "environment": [ + + { + "name": "PORT", + "value": "" + }, + { + "name": "FULLCHAIN", + "value": "" + }, + { + "name": "PRIVKEY", + "value": "" + }, + { + "name": "DISCORD_CLIENT_ID", + "value": "" + }, + { + "name": "DISCORD_CLIENT_SECRET", + "value": "" + }, + { + "name": "DISCORD_REDIRECT_URI", + "value": "" + }, + { + "name": "JWT_SECRET", + "value": "" + }, + { + "name": "CLIENT_REDIRECT_URI", + "value": "" + }, + { + "name": "TOKEN", + "value": "" + }, + { + "name": "DIRECT_URL", + "value": "" + }, + { + "name": "HOSTED_URL", + "value": "" + } + ], "mountPoints": [], "volumesFrom": [], "logConfiguration": {