Skip to content

Commit

Permalink
Merge branch 'dev' into log_transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
wjuniorbh92 committed Aug 21, 2023
2 parents 4bc42a5 + 70b8e18 commit ac20201
Show file tree
Hide file tree
Showing 167 changed files with 10,502 additions and 462 deletions.
159 changes: 159 additions & 0 deletions .github/workflows/backend-cicd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: Backend - CI/CD

on:
workflow_dispatch:
inputs:
run-type:
description: 'Run type'
required: true
default: 'Deploy'
type: choice
options:
- Code-Quality
- Deploy
pull_request:
types:
- opened
- reopened
- synchronize
paths:
- 'backend/**.go'
- 'backend/**.mod'
- 'backend/**.sum'
- 'backend/Dockerfile'

defaults:
run:
working-directory: ./backend

jobs:
code-quality:
name: Code Quality
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.20"]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
check-latest: true
cache-dependency-path: ./backend/go.sum

# TODO: fix lint errors to remove `args: --issues-exit-code=0` to break the pipeline when lint errors are found
- name: Run linter
uses: golangci/golangci-lint-action@v3
with:
working-directory: ./backend
args: --issues-exit-code=0

# TODO: adjust project Docker Compose to tests work properly
# TODO: add make file commands to Backend
# - name: Run tests
# run: |
# go test ./...

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: backend/
platforms: linux/amd64
target: remote
push: false
tags: build:1.0.0
outputs: type=docker,dest=/tmp/docker_image.tar

- name: Upload artifact
uses: actions/upload-artifact@v3
if: inputs.run-type == 'Deploy'
with:
retention-days: 1
name: docker_image
path: /tmp/docker_image.tar

deploy:
name: Deploy
runs-on: ubuntu-latest
needs: ['code-quality', 'build']
if: needs.code-quality.result == 'success' && needs.build.result == 'success' && inputs.run-type == 'Deploy'
environment: Production
env:
ECR_REPOSITORY: ${{ vars.resource_base_name }}-tfv2-backend
ECS_CLUSTER_NAME: ${{ vars.resource_base_name }}
ECS_SERVICE_NAME: ${{ vars.resource_base_name }}-tfv2-backend
ECS_CONTAINER_NAME: ${{ vars.resource_base_name }}-tfv2-backend
ECS_TASK_NAME: ${{ vars.resource_base_name }}-tfv2-backend
IMAGE_TAG: ${{ github.sha }}
permissions:
contents: 'read'

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Set image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: echo "IMAGE=$(echo $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG )" >> $GITHUB_ENV

- name: Download artifact
uses: actions/download-artifact@v3
with:
name: docker_image
path: /tmp

- name: Load, tag and push Docker image
run: |
docker load --input /tmp/docker_image.tar
docker tag build:1.0.0 ${{ env.IMAGE }}
docker image ls -a
docker push ${{ env.IMAGE }}
- name: Download ECS task definition
run: |
aws ecs describe-task-definition --task-definition $ECS_TASK_NAME --query taskDefinition > task-definition.json
cat task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: backend/task-definition.json
container-name: ${{ env.ECS_CONTAINER_NAME }}
image: ${{ env.IMAGE }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE_NAME }}
cluster: ${{ env.ECS_CLUSTER_NAME }}
wait-for-service-stability: true
173 changes: 173 additions & 0 deletions .github/workflows/frontend-cicd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
name: Frontend - CI/CD

on:
workflow_dispatch:
inputs:
run-type:
description: 'Run type'
required: true
default: 'Deploy'
type: choice
options:
- Code-Quality
- Deploy
pull_request:
types:
- opened
- reopened
- synchronize
paths:
- 'frontend/**.js'
- 'frontend/**.ts'
- 'frontend/**.tsx'
- 'frontend/**.json'
- 'frontend/**.lock'
- 'frontend/src/**'
- 'frontend/Dockerfile'

defaults:
run:
working-directory: ./frontend

jobs:
code-quality:
name: Code Quality
runs-on: ubuntu-latest
strategy:
matrix:
node: ["16"]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: "./frontend/package-lock.json"

- name: Install dependencies
run: make clean_install_dev

# TODO: fix lint errors
# - name: Run Review Dog - Linter
# uses: reviewdog/action-eslint@v1
# with:
# level: "info"
# workdir: "./frontend/"
# fail_on_error: "true"

# TODO: fix lint errors
# - name: Run linter
# if: github.event_name != 'pull_request'
# run: make lint

# TODO: add tests and fix cogerage tests errors
# - name: Run coverage test
# run: make coverage-test

build:
name: Build
runs-on: ubuntu-latest
environment: Production
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: frontend/
platforms: linux/amd64
target: remote
push: false
tags: build:1.0.0
build-args: |
REACT_APP_API_URL=${{ vars.REACT_APP_API_URL }}
REACT_APP_SENTRY_DSN=${{ secrets.REACT_APP_SENTRY_DSN }}
outputs: type=docker,dest=/tmp/docker_image.tar

- name: Upload artifact
uses: actions/upload-artifact@v3
if: inputs.run-type == 'Deploy'
with:
retention-days: 1
name: docker_image
path: /tmp/docker_image.tar

deploy:
name: Deploy
runs-on: ubuntu-latest
needs: ['code-quality', 'build']
if: needs.code-quality.result == 'success' && needs.build.result == 'success' && inputs.run-type == 'Deploy'
environment: Production
env:
ECR_REPOSITORY: ${{ vars.resource_base_name }}-tfv2-frontend
ECS_CLUSTER_NAME: ${{ vars.resource_base_name }}
ECS_SERVICE_NAME: ${{ vars.resource_base_name }}-tfv2-frontend
ECS_CONTAINER_NAME: ${{ vars.resource_base_name }}-tfv2-frontend
ECS_TASK_NAME: ${{ vars.resource_base_name }}-tfv2-frontend
IMAGE_TAG: ${{ github.sha }}
permissions:
contents: 'read'

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Set image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: echo "IMAGE=$(echo $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG )" >> $GITHUB_ENV

- name: Download artifact
uses: actions/download-artifact@v3
with:
name: docker_image
path: /tmp

- name: Load, tag and push Docker image
run: |
docker load --input /tmp/docker_image.tar
docker tag build:1.0.0 ${{ env.IMAGE }}
docker image ls -a
docker push ${{ env.IMAGE }}
- name: Download ECS task definition
run: |
aws ecs describe-task-definition --task-definition $ECS_TASK_NAME --query taskDefinition > task-definition.json
cat task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: frontend/task-definition.json
container-name: ${{ env.ECS_CONTAINER_NAME }}
image: ${{ env.IMAGE }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE_NAME }}
cluster: ${{ env.ECS_CLUSTER_NAME }}
wait-for-service-stability: true
Loading

0 comments on commit ac20201

Please sign in to comment.