Skip to content

Commit

Permalink
Merge pull request #7 from Selleo/chore/lc-73-github-actions
Browse files Browse the repository at this point in the history
lc 73 GitHub actions
  • Loading branch information
typeWolffo authored Aug 12, 2024
2 parents be9395e + 8dec23f commit 6e8e0b0
Show file tree
Hide file tree
Showing 28 changed files with 479 additions and 315 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
**/node_modules
**/build
**/dist
**/terraform
**/tf
73 changes: 73 additions & 0 deletions .github/workflows/deploy-api-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: STAGING - Deploy API

env:
HUSKY: 0

on:
push:
branches:
- main
- "deploy-staging/**"
paths:
- apps/api/**
- .github/workflows/deploy-api-staging.yml

jobs:
build-api:
runs-on: ubuntu-latest
environment:
name: staging

steps:
- uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.STAGING_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.STAGING_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.STAGING_AWS_REGION }}

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

- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ secrets.STAGING_AWS_ECR_REGISTRY }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -f ./Dockerfile --build-arg VERSION=$IMAGE_TAG -t $ECR_REGISTRY:$IMAGE_TAG .
docker tag $ECR_REGISTRY:$IMAGE_TAG $ECR_REGISTRY:latest
docker push $ECR_REGISTRY:$IMAGE_TAG
docker push $ECR_REGISTRY:latest
- name: Install Selleo CLI
uses: jaxxstorm/[email protected]
with:
repo: selleo/cli
tag: v0.26.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: ECS Deployment
env:
AWS_REGION: ${{ secrets.STAGING_AWS_REGION }}
ECS_CLUSTER: ${{ vars.STAGING_ECS_CLUSTER }}
ECS_SERVICE: ${{ vars.STAGING_ECS_SERVICE }}
DOCKER_IMAGE: ${{ secrets.STAGING_AWS_ECR_REGISTRY }}:${{ github.sha }}
run: selleo aws ecs deploy --region $AWS_REGION --cluster $ECS_CLUSTER --service $ECS_SERVICE --docker-image $DOCKER_IMAGE --one-off migrate

- name: ECS Run migrations
env:
AWS_REGION: ${{ secrets.STAGING_AWS_REGION }}
ECS_CLUSTER: ${{ vars.STAGING_ECS_CLUSTER }}
ECS_SERVICE: ${{ vars.STAGING_ECS_SERVICE }}
run: selleo aws ecs run --region $AWS_REGION --cluster $ECS_CLUSTER --service $ECS_SERVICE --one-off migrate

- name: ECS Run seeds
env:
AWS_REGION: ${{ secrets.STAGING_AWS_REGION }}
ECS_CLUSTER: ${{ vars.STAGING_ECS_CLUSTER }}
ECS_SERVICE: ${{ vars.STAGING_ECS_SERVICE }}
run: selleo aws ecs run --region $AWS_REGION --cluster $ECS_CLUSTER --service $ECS_SERVICE --one-off seed
54 changes: 54 additions & 0 deletions .github/workflows/deploy-webapp-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: STAGING - Deploy Webapp

env:
HUSKY: 0

on:
push:
branches:
- main
- "deploy-staging/**"
paths:
- apps/web/**
- .github/workflows/deploy-webapp-staging.yml

jobs:
build:
runs-on: ubuntu-latest
environment:
name: staging
defaults:
run:
working-directory: ./apps/web/
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20.15.0
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Build app
run: pnpm run build
env:
VITE_API_URL: ${{ vars.STAGING_API_URL }}
- name: Synchronize S3 Bucket
uses: jakejarvis/s3-sync-action@master
with:
args: --delete
env:
AWS_S3_BUCKET: ${{ secrets.STAGING_AWS_APPS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.STAGING_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.STAGING_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.STAGING_AWS_REGION }}
SOURCE_DIR: ./apps/web/dist
DEST_DIR: apps/webapp
- name: Invalidate CloudFront
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: ${{ secrets.STAGING_AWS_CDN_WEBAPP_ID }}
PATHS: "/*"
AWS_REGION: "us-east-1"
AWS_ACCESS_KEY_ID: ${{ secrets.STAGING_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.STAGING_AWS_SECRET_ACCESS_KEY }}
33 changes: 33 additions & 0 deletions .github/workflows/nighty-playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# uncomment when staging will be ready

# name: Nightly Playwright Tests

# env:
# HUSKY: 0

# on:
# schedule:
# - cron: "0 1 * * *"
# workflow_dispatch:

# jobs:
# playwright:
# name: Playwright Tests
# runs-on: ubuntu-latest
# container:
# image: mcr.microsoft.com/playwright:v1.45.3-jammy
# defaults:
# run:
# working-directory: ./apps/web/
# steps:
# - uses: actions/checkout@v4
# - uses: pnpm/action-setup@v4
# - uses: actions/setup-node@v4
# with:
# node-version: 20.15.0
# - name: Install dependencies
# run: pnpm install
# - name: Run your tests
# run: pnpm playwright test
# env:
# HOME: /root
92 changes: 92 additions & 0 deletions .github/workflows/pr-backend-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Backend Pull Request Check

env:
HUSKY: 0
JWT_SECRET: "test_secret"
JWT_REFRESH_SECRET: "test_refresh"
JWT_EXPIRATION_TIME: "15min"
CORS_ORIGIN: ""
EMAIL_ADAPTER: "mailhog"
DATABASE_URL: ""
SMTP_HOST: ""
SMTP_PORT: ""
SMTP_USER: ""
SMTP_PASSWORD: ""
AWS_REGION: ""
AWS_ACCESS_KEY_ID: ""
AWS_SECRET_ACCESS_KEY: ""

on:
pull_request:
branches:
- "*"
paths:
- apps/api/**

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 20.15.0
cache: pnpm

- name: Install dependencies
run: pnpm install

- name: Run ESLint
run: pnpm --filter=api lint-tsc

build:
name: Build app
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./apps/api/
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 20.15.0
cache: pnpm

- run: pnpm install
- name: Build the app
run: pnpm run build

test:
name: Jest tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4

- name: Start containers
run: docker compose -f "docker-compose.yml" up -d --build

- uses: actions/setup-node@v4
with:
node-version: 20.9.0
cache: pnpm

- name: Install dependencies
run: pnpm install

- name: Run unit tests
run: pnpm --filter=api test:ci

- name: Run e2e tests
run: pnpm --filter=api test:e2e
76 changes: 76 additions & 0 deletions .github/workflows/pr-frontend-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Frontend Pull Request Check

env:
HUSKY: 0

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
branches:
- "*"
paths:
- apps/web/**
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./apps/web/
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 20.15.0
cache: pnpm

- name: Install dependencies
run: pnpm install

- name: Run ESLint & Compile Typescript
run: pnpm lint-tsc

build:
name: Build app
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./apps/web/
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 20.15.0
cache: pnpm

- run: pnpm install
- name: Build the app
run: pnpm run build

test:
name: Vitest tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./apps/web/
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 20.15.0
cache: pnpm

- name: Install dependencies
run: pnpm install

- name: Run Vite tests
run: pnpm test
27 changes: 27 additions & 0 deletions .github/workflows/pr-open-notification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Add SLACK_WEBHOOK for a channel notification

# name: Pull Request Open Notification

# on:
# pull_request:
# types: [ready_for_review, reopened]

# jobs:
# slack_notification_pr:
# runs-on: ubuntu-latest
# name: Slack Notification
# if: ${{ always() }}
# steps:
# - uses: actions/checkout@v3
# - name: Slack Notification
# uses: rtCamp/action-slack-notify@master
# env:
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
# SLACK_COLOR: '#005994'
# SLACK_USERNAME: 'Github Project Notifier'
# SLACK_ICON_EMOJI: ':node:'
# SLACK_LINK_NAMES: true
# SLACK_TITLE: 'New Pull Request! :nerd_face:'
# MSG_MINIMAL: true
# SLACK_MESSAGE: ' ${{ github.event.pull_request.title }} - ${{ github.event.pull_request.html_url }}'
# SLACK_FOOTER: 'Please review in your :coffee: time'
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pnpm lint

pnpm run test:web
pnpm run test:api
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:20.15.0-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

WORKDIR /app

COPY . .

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install
RUN pnpm build --filter=api
# TODO: Move pnpm deploy to turbo prune workflow
RUN pnpm deploy --filter=api pnpm-deploy-output --prod

FROM node:20.15.0-alpine
WORKDIR /app
COPY --from=base /app/pnpm-deploy-output /app

RUN chmod +x /app/entrypoint.sh

ENTRYPOINT [ "/app/entrypoint.sh" ]
Loading

0 comments on commit 6e8e0b0

Please sign in to comment.