Skip to content

Commit

Permalink
Create actions CI pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
scopsy committed Mar 10, 2022
1 parent bd5a819 commit 6d240ed
Show file tree
Hide file tree
Showing 13 changed files with 635 additions and 12 deletions.
188 changes: 188 additions & 0 deletions .github/workflows/dev-deploy-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
name: Deploy DEV API

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- master
paths:
- 'package.json'
- 'yarn.lock'
- 'apps/api/**'
- 'libs/dal/**'
- 'libs/shared/**'

jobs:
test_api:
if: "!contains(github.event.head_commit.message, 'ci skip')"
# The type of runner that the job will run on
runs-on: ubuntu-latest
timeout-minutes: 80
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Setup kernel for react native, increase watchers
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
- uses: actions/setup-node@v2
with:
node-version: '16.13.0'
- name: Start Redis
uses: supercharge/[email protected]

- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 4.2.8
- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/[email protected]
with:
version: 6.0.2
run_install: true

- name: Start Local Stack
env:
AWS_DEFAULT_REGION: us-east-1
DEFAULT_REGION: us-east-1
AWS_ACCOUNT_ID: "000000000000"
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
AWS_EC2_METADATA_DISABLED: true
working-directory: environment/test
run: |
docker-compose up -d
sleep 10
max_retry=30
counter=0
until $command
do
sleep 1
[[ counter -eq $max_retry ]] && echo "Failed!" && exit 1
aws --endpoint-url=http://localhost:4566 s3 ls
echo "Trying again. Try #$counter"
((counter++))
done
docker-compose logs --tail="all"
aws --endpoint-url=http://localhost:4566 s3 mb s3://notifire-test
# Runs a single command using the runners shell
- name: Build API
run: CI='' pnpm build:api

# Runs a set of commands using the runners shell
- name: Run a test
run: |
cd apps/api && pnpm test:e2e
pnpm test
deploy_dev_api:
if: "!contains(github.event.head_commit.message, 'ci skip')"
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: test_api
timeout-minutes: 80
environment: development
permissions:
contents: read
packages: write
deployments: write
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Setup kernel for react native, increase watchers
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
- uses: actions/setup-node@v2
with:
node-version: '16.13.0'
- name: Start Redis
uses: supercharge/[email protected]

- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 4.2.8

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
REGISTERY_OWNER: notifirehq
DOCKER_NAME: notifire/api
IMAGE_TAG: ${{ github.sha }}
GH_ACTOR: ${{ github.actor }}
GH_PASSWORD: ${{ secrets.GH_PACKAGES }}
run: |
echo $GH_PASSWORD | docker login ghcr.io -u $GH_ACTOR --password-stdin
docker build -t ghcr.io/$REGISTERY_OWNER/$DOCKER_NAME:$IMAGE_TAG -f apps/api/Dockerfile .
docker run --network=host --name api -dit --env NODE_ENV=test ghcr.io/$REGISTERY_OWNER/$DOCKER_NAME:$IMAGE_TAG
docker run --network=host appropriate/curl --retry 10 --retry-delay 5 --retry-connrefused http://localhost:1337/v1/health-check | grep 'ok'
docker tag ghcr.io/$REGISTERY_OWNER/$DOCKER_NAME:$IMAGE_TAG ghcr.io/$REGISTERY_OWNER/$DOCKER_NAME:dev
docker push ghcr.io/$REGISTERY_OWNER/$DOCKER_NAME:dev
docker push ghcr.io/$REGISTERY_OWNER/$DOCKER_NAME:$IMAGE_TAG
echo "::set-output name=IMAGE::ghcr.io/$REGISTERY_OWNER/$DOCKER_NAME:$IMAGE_TAG"
- name: Checkout cloud infra
uses: actions/checkout@master
with:
repository: notifirehq/cloud-infra
token: ${{ secrets.GH_PACKAGES }}
path: cloud-infra

- 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: eu-central-1

- name: Terraform setup
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.1.7
terraform_wrapper: false

- name: Terraform Init
working-directory: cloud-infra/terraform
run: terraform init

- name: Terraform Change Workspace
working-directory: cloud-infra/terraform
run: terraform workspace select dev

- name: Terraform get output
working-directory: cloud-infra/terraform
id: terraform
run: |
echo "api_ecs_container_name=$(terraform output -json api_ecs_container_name | jq -r .)" >> $GITHUB_ENV
echo "api_ecs_service=$(terraform output -json api_ecs_service | jq -r .)" >> $GITHUB_ENV
echo "api_ecs_cluster=$(terraform output -json api_ecs_cluster | jq -r .)" >> $GITHUB_ENV
echo "api_task_name=$(terraform output -json api_task_name | jq -r .)" >> $GITHUB_ENV
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ env.api_task_name }} \
--query taskDefinition > task-definition.json
- name: Render Amazon ECS task definition
id: render-web-container
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.api_ecs_container_name }}
image: ${{ steps.build-image.outputs.IMAGE }}

- name: Deploy to Amazon ECS service
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.render-web-container.outputs.task-definition }}
service: ${{ env.api_ecs_service }}
cluster: ${{ env.api_ecs_cluster }}
wait-for-service-stability: true

64 changes: 64 additions & 0 deletions .github/workflows/dev-deploy-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# This is a basic workflow to help you get started with Actions

name: Deploy DEV SDK

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- master
paths:
- 'libs/sdk/**'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
deploy_sdk:
environment: development
# The type of runner that the job will run on
runs-on: ubuntu-latest
timeout-minutes: 80
if: "!contains(github.event.head_commit.message, 'ci skip')"
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Setup kernel for react native, increase watchers
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
- uses: actions/setup-node@v2
with:
node-version: '16.13.0'
- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/[email protected]
with:
version: 6.0.2
run_install: true

# Runs a single command using the runners shell
- name: Build
working-directory: libs/sdk
run: CI='' npm run build:dev

- name: Deploy SDK to DEV
uses: nwtgck/[email protected]
with:
publish-dir: libs/sdk/dist
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: dev
production-deploy: true
alias: dev
github-deployment-environment: development
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: 22682666-3a8d-40be-af26-017bfadf5ae9
timeout-minutes: 1


131 changes: 131 additions & 0 deletions .github/workflows/dev-deploy-web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# This is a basic workflow to help you get started with Actions

name: Deploy DEV WEB

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- master
paths:
- 'apps/web/**'
- 'libs/shared/**'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
test_web:
environment: development
if: "!contains(github.event.head_commit.message, 'ci skip')"
# The type of runner that the job will run on
runs-on: ubuntu-latest
timeout-minutes: 80

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Setup kernel for react native, increase watchers
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
- uses: actions/setup-node@v2
with:
node-version: '16.13.0'
- name: Start Redis
uses: supercharge/[email protected]

- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 4.2.8

- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/[email protected]
with:
version: 6.0.2
run_install: true

- name: Start Local Stack
env:
DEFAULT_REGION: us-east-1
AWS_DEFAULT_REGION: us-east-1
AWS_ACCOUNT_ID: "000000000000"
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
AWS_EC2_METADATA_DISABLED: true
working-directory: environment/test
run: |
docker-compose up -d
sleep 5
max_retry=30
counter=0
until $command
do
sleep 1
[[ counter -eq $max_retry ]] && echo "Failed!" && exit 1
aws --endpoint-url=http://localhost:4566 s3 ls
echo "Trying again. Try #$counter"
((counter++))
done
aws --endpoint-url=http://localhost:4566 s3 mb s3://notifire-test
# Runs a single command using the runners shell
- name: Build
run: CI='' pnpm build:web

# Runs a single command using the runners shell
- name: Start Client
run: pnpm start:web &

- name: Cypress run
uses: cypress-io/github-action@v2
env:
NODE_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
record: false
working-directory: apps/web
start: pnpm start:api
wait-on: http://localhost:1336/v1/health-check
browser: chrome
headless: true
install: false

- name: Build
env:
REACT_APP_API_URL: https://dev.api.novu.co
REACT_APP_WIDGET_SDK_PATH: https://dev.sdk.novu.co/sdk.umd.min.js
REACT_APP_NOTIFIRE_APP_ID: uaahXGRverKF
REACT_APP_SENTRY_DSN: https://[email protected]/6250907
REACT_APP_ENVIRONMENT: dev
working-directory: apps/web
run: npm run build

- name: Deploy WEB to DEV
uses: nwtgck/[email protected]
with:
publish-dir: apps/web/build
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: Dev deployment
production-deploy: true
alias: dev
github-deployment-environment: development
github-deployment-description: Web Deployment
netlify-config-path: apps/web/netlify.toml
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: 45396446-dc86-4ad6-81e4-86d3eb78d06f
timeout-minutes: 1

- uses: actions/upload-artifact@v1
if: failure()
with:
name: cypress-screenshots
path: apps/web/cypress/screenshots
Loading

0 comments on commit 6d240ed

Please sign in to comment.