Skip to content

Commit

Permalink
Merge pull request #48 from andreciornavei/develop
Browse files Browse the repository at this point in the history
deploy frontend ci
  • Loading branch information
andreciornavei authored Mar 8, 2024
2 parents d36da7e + a4411e0 commit 126691b
Show file tree
Hide file tree
Showing 62 changed files with 1,334 additions and 187 deletions.
126 changes: 103 additions & 23 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,61 @@ on:
- production

jobs:
deploy-api:
# deploy-api:
# name: deploy-api
# runs-on: ubuntu-latest
# steps:
# # This step checks out a copy of your repository.
# - name: Checkout code
# uses: actions/checkout@v3

# - name: Get branch names
# id: branch-names
# uses: tj-actions/branch-names@v8

# # This step sets up Node.js environment.
# - name: Setup Node.js
# uses: actions/setup-node@v3
# if: success()

# # This step installs the Serverless Framework globally.
# - name: Install Serverless Framework
# run: |
# cd backend
# npm install -g serverless serverless-prune-plugin serverless-iam-roles-per-function
# if: success()

# # This step sets up PHP environment with the specified version.
# - name: Setup PHP
# uses: shivammathur/setup-php@v2
# with:
# php-version: "8.2"
# if: success()

# # This step installs Composer dependencies with the specified options.
# - name: Install Composer dependencies
# run: |
# cd backend
# composer install --prefer-dist --optimize-autoloader --no-dev
# if: success()

# # This step deploys your application to AWS Lambda using the Serverless Framework.
# - name: Deploy to AWS Lambda
# run: |
# cd backend
# echo "APP_KEY=${{ vars.APP_KEY }}" >> .env
# echo "APP_NAME=${{ vars.SUBDOMAIN }}" >> .env
# echo "SUBDOMAIN=${{ vars.SUBDOMAIN }}" >> .env
# echo "DOMAIN=${{ vars.DOMAIN }}" >> .env
# echo "DB_URI=${{ secrets.DB_URI }}" >> .env
# echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
# echo "AWS_HOSTED_ZONE_ID=${{ vars.AWS_HOSTED_ZONE_ID }}" >> .env
# echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> .env
# echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> .env
# serverless deploy --config serverless.yml --stage ${{ steps.branch-names.outputs.current_branch }} --region ${{ vars.AWS_DEFAULT_REGION }} --verbose
# if: success()

deploy-web:
name: deploy-api
runs-on: ubuntu-latest
steps:
Expand All @@ -27,36 +81,62 @@ jobs:
# This step installs the Serverless Framework globally.
- name: Install Serverless Framework
run: |
cd backend
npm install -g serverless serverless-prune-plugin serverless-iam-roles-per-function
cd frontend
npm install -g serverless serverless-dotenv-plugin serverless-export-outputs
if: success()

# This step sets up PHP environment with the specified version.
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
# This step install aws cli to execute commands on aws.
- name: Install AWS Cli
run: |
apt update && apt -y install zip curl jq
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./aws/install
if: success()

# This step installs Composer dependencies with the specified options.
- name: Install Composer dependencies
# This step expose variables to environment
- name: Build ReactJS Application
run: |
cd backend
composer install --prefer-dist --optimize-autoloader --no-dev
BRANCH=${{ steps.branch-names.outputs.current_branch }}
DOMAIN=${{ vars.DOMAIN }}
APP_NAME=${{ vars.SUBDOMAIN }}-web
SUBDOMAIN=${{ vars.SUBDOMAIN }}
AWS_DEFAULT_REGION=${{ vars.AWS_DEFAULT_REGION }}
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}
if: success()

# This step build reactjs application to be deployed.
- name: Build ReactJS Application
run: |
cd frontend
rm -rf .env
echo "REACT_APP_API_URL=https://$SUBDOMAIN-api.$([ "$BRANCH" != "production" ] && echo "$BRANCH.")$DOMAIN" >> .env
yarn --dev --production=false
yarn build
if: success()

# This step deploys your application to AWS Lambda using the Serverless Framework.
- name: Deploy to AWS Lambda
run: |
cd backend
echo "APP_KEY=${{ vars.APP_KEY }}" >> .env
echo "APP_NAME=${{ vars.SUBDOMAIN }}" >> .env
echo "SUBDOMAIN=${{ vars.SUBDOMAIN }}" >> .env
echo "DOMAIN=${{ vars.DOMAIN }}" >> .env
echo "DB_URI=${{ secrets.DB_URI }}" >> .env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
echo "AWS_HOSTED_ZONE_ID=${{ vars.AWS_HOSTED_ZONE_ID }}" >> .env
echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> .env
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> .env
serverless deploy --config serverless.yml --stage ${{ steps.branch-names.outputs.current_branch }} --region ${{ vars.AWS_DEFAULT_REGION }} --verbose
cd frontend
rm -rf .env
echo "DOMAIN=$DOMAIN" >> .env
echo "AWS_HOSTED_ZONE_ID=$AWS_HOSTED_ZONE_ID" >> .env
serverless deploy --config serverless-cert.yml --stage $BRANCH --region $AWS_DEFAULT_REGION --verbose
SLS_WEBCERT_OUTPUT=$(cat sls-webcert-output.json)
$(echo "$SLS_WEBCERT_OUTPUT" | jq -r 'keys[] as $k | "export \($k)=\(.[$k])"')
echo "AWS_ACM_ARN=${CertificateDomainArn}" >> .env
serverless deploy --config serverless.yml --stage $BRANCH --region $AWS_DEFAULT_REGION --verbose
if: success()

# This step deploys your application to AWS Lambda using the Serverless Framework.
- name: Release application aws s3 and invalidate cloud formation cache
run: |
cd frontend
S3_DOMAIN="$APP_NAME.$([ "$BRANCH" != "production" ] && echo "$BRANCH.")${{ vars.DOMAIN }}"
aws s3 sync build/ s3://$S3_DOMAIN
SLS_OUTPUT=$(cat sls-output.json)
$(echo "$SLS_OUTPUT" | jq -r 'keys[] as $k | "export \($k)=\(.[$k])"')
aws cloudfront create-invalidation --distribution-id $CDNDistributionId --paths "/*"
if: success()
40 changes: 40 additions & 0 deletions backend/app/Domain/Entities/BalanceSummaryEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Domain\Entities;


class BalanceSummaryEntity
{
private $incomes;
private $expenses;
private $net;

public function __construct(array | object $data)
{
foreach ($data as $key => $value) {
if (property_exists($this, $key)) {
$this->$key = $value;
}
}
}

public function toJson()
{
return get_object_vars($this);
}

public function getIncomes()
{
return $this->incomes;
}

public function getExpenses()
{
return $this->expenses;
}

public function getNet()
{
return $this->net;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Domain\Repositories\IBalanceSummaryRepository;


class IBalanceSummaryDto
{
private $user_id;
private $period_from;
private $period_to;

public function __construct(array $data)
{
foreach ($data as $key => $value) {
if (property_exists($this, $key)) {
$this->$key = $value;
}
}
}

public function getUserId()
{
return $this->user_id ?? null;
}

public function getPeriodFrom()
{
return $this->period_from ?? null;
}

public function getPeriodTo()
{
return $this->period_to ?? null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Domain\Repositories\IBalanceSummaryRepository;

use App\Domain\Entities\BalanceSummaryEntity;

interface IBalanceSummaryRepository
{
public function handler(IBalanceSummaryDto $dto): BalanceSummaryEntity;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Domain\Usecases\TransactionCheckUrl;

class TransactionCheckUrlDto
{

private $transaction_id;

public function __construct(array $data)
{
foreach ($data as $key => $value) {
if (property_exists($this, $key)) {
$this->$key = $value;
}
}
}

public function getTransactionId()
{
return $this->transaction_id ?? null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace App\Domain\Usecases\TransactionCheckUrl;

use App\Exceptions\JsonException;
use Illuminate\Support\Facades\Validator;
use App\Domain\Providers\IStorageProvider;
use App\Domain\Entities\TransactionEntity;
use App\Domain\Repositories\IFindTransactionRepository\IFindTransactionDto;
use App\Domain\Repositories\IFindTransactionRepository\IFindTransactionRepository;

class TransactionCheckUrlUseCase
{
public function __construct(
private readonly IFindTransactionRepository $findTransactionRepository,
private readonly IStorageProvider $storageProvider
) {
}

public function handler(TransactionCheckUrlDto $dto): string
{
// create validate schema
$validator = Validator::make(
['transaction_id' => $dto->getTransactionId()],
['transaction_id' => 'required|string']
);

// validate provided data
if ($validator->fails()) {
throw new JsonException([
"error" => [
"message" => "Validation failed",
"fields" => $validator->errors()
]
]);
}

// find transaction by provided transactionId
$transactions = $this->findTransactionRepository->handler(new IFindTransactionDto([
"filter_id" => $dto->getTransactionId()
]));

// throws an error if was not possible to find transaction
if (sizeof($transactions) === 0) {
throw new JsonException([
"error" => [
"message" => "Transaction not founded"
]
]);
}

// store transaction on entity variable
$transaction = new TransactionEntity($transactions[0]);

// retrieve document url
$url = $this->storageProvider->generateReadableUrl("deposits" . "/" . $transaction->getDocument());

// throw an error if was not possible to generate url
if (!$url) {
throw new JsonException([
"error" => [
"message" => "Was not possible top generate document url"
]
]);
}

// return generated url
return $url;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Domain\Usecases\UserBalanceSummary;


class UserBalanceSummaryDto
{
private $user_id;
private $period_from;
private $period_to;

public function __construct(array $data)
{
foreach ($data as $key => $value) {
if (property_exists($this, $key)) {
$this->$key = $value;
}
}
}

public function getUserId()
{
return $this->user_id ?? null;
}

public function getPeriodFrom()
{
return $this->period_from ?? null;
}

public function getPeriodTo()
{
return $this->period_to ?? null;
}
}
Loading

0 comments on commit 126691b

Please sign in to comment.