Skip to content

Commit

Permalink
chore: set up deployment gf-18 (#111)
Browse files Browse the repository at this point in the history
* chore: set up deployment gf-18

* chore: remove nodejs step in cd workflow gf-18
  • Loading branch information
liza-veis authored Aug 29, 2024
1 parent 438f4b2 commit 2df09c0
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 13 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Continuous Delivery

env:
EBS_ENVIRONMENT_NAME: development

on:
push:
branches:
- main
workflow_dispatch:

concurrency:
group: ${{ github.ref_name }}
cancel-in-progress: false

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
release_created: ${{ steps.release.outputs.release_created }}
steps:
- name: Code Checkout
uses: actions/checkout@v4

- name: Release
id: release
uses: googleapis/release-please-action@v4
with:
manifest-file: .release-please-manifest.json
config-file: release-please-config.json

deploy:
name: Deploy
needs: release
if: ${{ needs.release.outputs.release_created }}
runs-on: ubuntu-latest
environment:
name: development
url: http://git-fit-development.eu-central-1.elasticbeanstalk.com/

steps:
- name: Code Checkout
uses: actions/checkout@v4

- name: Prepare deployment package
run: |
zip -r build.zip . -x .github
- name: Deploy to Beanstalk
uses: einaregilsson/beanstalk-deploy@v22
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
region: ${{ secrets.AWS_REGION }}
application_name: ${{ secrets.EBS_APPLICATION_NAME }}
environment_name: ${{ env.EBS_ENVIRONMENT_NAME }}
version_label: ${{ github.sha }}
deployment_package: ./build.zip
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Constructor = {
};
title: string;
token: Token;
whiteRoutes: readonly RegExp[];
whiteRoutes: string[];
};

class BaseServerApplication implements ServerApplication {
Expand All @@ -58,7 +58,7 @@ class BaseServerApplication implements ServerApplication {

private token: Token;

private whiteRoutes: readonly RegExp[];
private whiteRoutes: string[];

public constructor({
apis,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { APIPath, AuthApiPath } from "@git-fit/shared";

const WHITE_ROUTES = [
/^\/api\/v1\/[^/]+\/sign-up\/?$/,
/^\/api\/v1\/[^/]+\/sign-in\/?$/,
] as const;
`${APIPath.AUTH}${AuthApiPath.SIGN_UP}`,
`${APIPath.AUTH}${AuthApiPath.SIGN_IN}`,
];

export { WHITE_ROUTES };
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ import { type Token } from "~/libs/modules/token/token.js";
import { AuthError } from "~/modules/auth/auth.js";
import { type UserService } from "~/modules/users/user.service.js";

import { checkIsWhiteRoute } from "./helpers/helpers.js";

type Options = {
token: Token;
userService: UserService;
whiteRoutes: readonly RegExp[];
whiteRoutes: string[];
};

const authorization = fp<Options>((fastify, options, done) => {
const { token, userService, whiteRoutes } = options;

fastify.decorateRequest("user", null);

fastify.addHook("preHandler", async (request: FastifyRequest) => {
const { url } = request.raw;

for (const whiteRoute of whiteRoutes) {
if (whiteRoute.test(url as string)) {
return;
}
fastify.addHook("onRequest", async (request: FastifyRequest) => {
if (checkIsWhiteRoute(request.url, whiteRoutes)) {
return;
}

const BEARER_PREFIX = "Bearer ";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const checkIsWhiteRoute = (url: string, whiteRoutes: string[]): boolean => {
const apiUrlRegex = /^\/api\/v\d+(\/.+)$/;
const match = url.match(apiUrlRegex);
const [, route] = match ?? [];

if (!route) {
return true;
}

return whiteRoutes.includes(route);
};

export { checkIsWhiteRoute };
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { checkIsWhiteRoute } from "./check-is-white-route.helper.js";

0 comments on commit 2df09c0

Please sign in to comment.