Skip to content

Commit

Permalink
adjust deploy to sl
Browse files Browse the repository at this point in the history
  • Loading branch information
Janderson Souza Matias authored and Janderson Souza Matias committed Nov 21, 2023
1 parent 289fa24 commit 98c556d
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 100 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/main.yml

This file was deleted.

55 changes: 55 additions & 0 deletions .github/workflows/sierra-leone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy Sierra Leone

on:
push:
branches:
- main

jobs:
build:
name: Deploy to Sierra Leone server
runs-on: ubuntu-latest
env:
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_DATABASE: ${{ secrets.DB_DATABASE_SL }}

steps:
- name: Checkout 🛎️
uses: actions/checkout@v1

- name: Use Node.js 18.x
uses: actions/setup-node@v1
with:
node-version: 18.x

- name: Install dependencies
run: npm install

- name: Run Migrations
run: npm run build

- name: Run Migrations
run: npm run migration:run

- name: Copy public folder
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
source: "src,node_modules,build,package.json,Dockerfile,docker-compose-sl.yml"
target: "/home/ubuntu/apps/coach-backend-sl"

- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@v0.1.8
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
cd /home/ubuntu/apps/coach-backend-sl
sudo docker build -t coach-backend-sl .
sudo docker-compose -f docker-compose-sl.yml up -d
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coach-backend-sl",
"version": "1.2.0",
"version": "1.2.1",
"description": "Coach SL API",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const port = process.env.PORT || 3000;
const config = {
port,

country: process.env.COUNTRY,

env: process.env.NODE_ENV || "production",

allowedOrigins: process.env.ALLOWED_ORIGINS
Expand Down
11 changes: 7 additions & 4 deletions src/modules/auth/routes.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Application } from "express";
import Authentication from "./service";
import AuthenticationController from "./controller";
import config from "../../config";

const AuthRouter = (app: Application): void => {
app.post("/sl/api/auth", AuthenticationController.login);
app.get("/sl/api/auth", Authentication.authenticate, (_req, res) =>
res.status(200).send(res.locals?.authUser)
app.post(`/${config.country}/api/auth`, AuthenticationController.login);
app.get(
`/${config.country}/api/auth`,
Authentication.authenticate,
(_req, res) => res.status(200).send(res.locals?.authUser)
);
app.get(
"/sl/api/auth/superset",
`/${config.country}/api/auth/superset`,
Authentication.authenticate,
AuthenticationController.supertsetLogin
);
Expand Down
31 changes: 26 additions & 5 deletions src/modules/coach/routes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
import { Application } from "express";
import Authentication from "../auth/service";
import CoachController from "./controller";
import config from "../../config";

const coachRouter = (app: Application): void => {
app.post("/sl/api/coach", Authentication.authenticate, CoachController.create);
app.put("/sl/api/coach", Authentication.authenticate, CoachController.update);
app.delete("/sl/api/coach/:id", Authentication.authenticate, CoachController.delete);
app.get("/sl/api/coach/:id", Authentication.authenticate, CoachController.findById);
app.get("/sl/api/coach", Authentication.authenticate, CoachController.findAll);
app.post(
`/${config.country}/api/coach`,
Authentication.authenticate,
CoachController.create
);
app.put(
`/${config.country}/api/coach`,
Authentication.authenticate,
CoachController.update
);
app.delete(
`/${config.country}/api/coach/:id`,
Authentication.authenticate,
CoachController.delete
);
app.get(
`/${config.country}/api/coach/:id`,
Authentication.authenticate,
CoachController.findById
);
app.get(
`/${config.country}/api/coach`,
Authentication.authenticate,
CoachController.findAll
);
};

export default coachRouter;
11 changes: 6 additions & 5 deletions src/modules/competencies/routes.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import { Application } from "express";
import Authentication from "../auth/service";
import CompetenceController from "./controller";
import config from "../../config";

const competenceRouter = (app: Application): void => {
app.post(
"/sl/api/competence",
`/${config.country}/api/competence`,
Authentication.authenticate,
CompetenceController.create
);
app.put(
"/sl/api/competence",
`/${config.country}/api/competence`,
Authentication.authenticate,
CompetenceController.update
);
app.delete(
"/sl/api/competence/:id",
`/${config.country}/api/competence/:id`,
Authentication.authenticate,
CompetenceController.delete
);
app.get(
"/sl/api/competence/:id",
`/${config.country}/api/competence/:id`,
Authentication.authenticate,
CompetenceController.findById
);
app.get(
"/sl/api/competence",
`/${config.country}/api/competence`,
Authentication.authenticate,
CompetenceController.findAll
);
Expand Down
15 changes: 0 additions & 15 deletions src/modules/dashboard/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,4 @@ export default class DashboardController {
});
}
};

public static insertMock = async (
_req: Request,
res: Response
): Promise<any> => {
try {
const data = await DashboardService.getData();
return res.status(HTTP_STATUS_OK).send(data);
} catch (error) {
res.status(HTTP_STATUS_INTERNAL_SERVER_ERROR).send({
error: HTTP_STATUS_INTERNAL_SERVER_ERROR,
message: (error as any).message,
});
}
};
}
8 changes: 2 additions & 6 deletions src/modules/dashboard/routes.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { Application } from "express";
import Authentication from "../auth/service";
import DashboardController from "./controller";
import config from "../../config";

const dashboardRouter = (app: Application): void => {
app.get(
"/sl/api/dashboard",
`/${config.country}/api/dashboard`,
Authentication.authenticate,
DashboardController.getData
);
app.get(
"/sl/api/dashboard/insert-mock",
// Authentication.authenticate,
DashboardController.insertMock
);
};

export default dashboardRouter;
31 changes: 26 additions & 5 deletions src/modules/image/routes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
import { Application } from "express";
import Authentication from "../auth/service";
import ImageController from "./controller";
import config from "../../config";

const imageRouter = (app: Application): void => {
app.post("/sl/api/image", Authentication.authenticate, ImageController.create);
app.put("/sl/api/image", Authentication.authenticate, ImageController.update);
app.delete("/sl/api/image/:id", Authentication.authenticate, ImageController.delete);
app.get("/sl/api/image/:id", Authentication.authenticate, ImageController.findById);
app.get("/sl/api/image", Authentication.authenticate, ImageController.findAll);
app.post(
`/${config.country}/api/image`,
Authentication.authenticate,
ImageController.create
);
app.put(
`/${config.country}api/image`,
Authentication.authenticate,
ImageController.update
);
app.delete(
`/${config.country}/api/image/:id`,
Authentication.authenticate,
ImageController.delete
);
app.get(
`/${config.country}/api/image/:id`,
Authentication.authenticate,
ImageController.findById
);
app.get(
`/${config.country}/api/image`,
Authentication.authenticate,
ImageController.findAll
);
};

export default imageRouter;
7 changes: 6 additions & 1 deletion src/modules/logs/routes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Application } from "express";
import LogsController from "./controller";
import Authentication from "../auth/service";
import config from "../../config";

const LogRouter = (app: Application): void => {
app.get("/sl/api/logs", Authentication.authenticate, LogsController.findAll);
app.get(
`/${config.country}/api/logs`,
Authentication.authenticate,
LogsController.findAll
);
};

export default LogRouter;
11 changes: 6 additions & 5 deletions src/modules/question/routes.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import { Application } from "express";
import Authentication from "../auth/service";
import QuestionnaireController from "./controller";
import config from "../../config";

const questionnaireRouter = (app: Application): void => {
app.post(
"/sl/api/questionnaire",
`/${config.country}/api/questionnaire`,
Authentication.authenticate,
QuestionnaireController.create
);
app.put(
"/sl/api/questionnaire",
`/${config.country}/api/questionnaire`,
Authentication.authenticate,
QuestionnaireController.update
);
app.delete(
"/sl/api/questionnaire/:id",
`/${config.country}/api/questionnaire/:id`,
Authentication.authenticate,
QuestionnaireController.delete
);
app.get(
"/sl/api/questionnaire/:id",
`/${config.country}/api/questionnaire/:id`,
Authentication.authenticate,
QuestionnaireController.findById
);
app.get(
"/sl/api/questionnaire",
`/${config.country}/api/questionnaire`,
Authentication.authenticate,
QuestionnaireController.findAll
);
Expand Down
27 changes: 20 additions & 7 deletions src/modules/school/routes.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
import { Application } from "express";
import Authentication from "../auth/service";
import SchoolController from "./controller";
import config from "../../config";

const schoolRouter = (app: Application): void => {
app.post("/sl/api/school", Authentication.authenticate, SchoolController.create);
app.put("/sl/api/school", Authentication.authenticate, SchoolController.update);
app.post(
`/${config.country}/api/school`,
Authentication.authenticate,
SchoolController.create
);
app.put(
`/${config.country}/api/school`,
Authentication.authenticate,
SchoolController.update
);
app.delete(
"/sl/api/school/:id",
`/${config.country}/api/school/:id`,
Authentication.authenticate,
SchoolController.delete
);
app.get(
"/sl/api/school/:id",
`/${config.country}/api/school/:id`,
Authentication.authenticate,
SchoolController.findById
);
app.get(
"/sl/api/school/qrcode/:id",
`/${config.country}/api/school/qrcode/:id`,
Authentication.authenticate,
SchoolController.generateKey
);
app.get("/sl/api/school", Authentication.authenticate, SchoolController.findAll);
app.get(
"/sl/api/school/:region/districts",
`/${config.country}/api/school`,
Authentication.authenticate,
SchoolController.findAll
);
app.get(
`/${config.country}/api/school/:region/districts`,
Authentication.authenticate,
SchoolController.findAllDistrictsByRegion
);
Expand Down
Loading

0 comments on commit 98c556d

Please sign in to comment.