Skip to content

Instantly share code, notes, and snippets.

@pi0neerpat
Last active July 8, 2021 19:14
Show Gist options
  • Save pi0neerpat/d18c9241c2d4da9fa7480a173dbfc6f1 to your computer and use it in GitHub Desktop.
Save pi0neerpat/d18c9241c2d4da9fa7480a173dbfc6f1 to your computer and use it in GitHub Desktop.
Pi0neerpat's RedwoodJS Devops
name: Chromatic
on:
push:
jobs:
chromatic-deployment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Cache "node_modules"
uses: actions/cache@v2
with:
path: '**/node_modules'
key: node_modules_${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build Storybook
run: yarn rw storybook --build
- name: Move MSW to public/storybook
run: mv web/public/mockServiceWorker.js web/public/storybook
- name: Publish to Chromatic
uses: chromaui/action@v1
# Chromatic GitHub Action options
with:
token: ${{ secrets.GITHUB_TOKEN }}
# 👇 Chromatic projectToken, refer to the manage page to obtain it.
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
storybookBuildDir: web/public/storybook
name: CI
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize]
jobs:
runCI:
name: Run CI
runs-on: ubuntu-latest
steps:
# check out this repo (so that this workflow can use it)
# https://github.com/actions/checkout
- uses: actions/checkout@v2
# set up a node environment
# https://github.com/actions/setup-node
- name: Setup Node.js v14
uses: actions/setup-node@v2
with:
node-version: '14'
# cache dependencies and build outputs to improve workflow execution time
# https://github.com/actions/cache
- name: Cache "node_modules"
uses: actions/cache@v2
with:
path: '**/node_modules'
key: node_modules_${{ hashFiles('**/yarn.lock') }}
# install dependencies
- name: Install dependencies
run: yarn install --frozen-lockfile
# lint, check, run tests, and build
# - name: Run CI
# uses: jtoar/redwoodjs-ci@v0.2.0
- name: Lint
run: yarn rw lint
shell: bash
- name: Check
run: yarn rw check
shell: bash
# TODO: Inject DATABASE_URL for testing
# - name: Run tests
# run: yarn rw test
# shell: bash
- name: Build
run: yarn rw build
shell: bash
# Adapted from https://github.com/users/jeliasson/packages/container/package/redwoodjs-app-api-main
# Force redeploy
name: "redwoodjs-app-main"
on:
push:
branches:
- main
env:
# Build
# TODO: change to "production"?
NODE_ENV: "development"
RUNTIME_ENV: "main"
# Container Registry
CONTAINER_REGISTRY_HOSTNAME: ghcr.io
CONTAINER_REGISTRY_USERNAME: pi0neerpat
CONTAINER_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
CONTAINER_REGISTRY_REPOSITORY: pi0neerpat
CONTAINER_REGISTRY_IMAGE_PREFIX: XXXX
# Repository
GIT_DEPLOY_REPOSITORY_NAME: pi0neerpat/XXXX
GIT_DEPLOY_REPOSITORY_BRANCH: main
GIT_DEPLOY_REPOSITORY_AUTHOR_NAME: pi0neerpat
GIT_DEPLOY_REPOSITORY_AUTHOR_EMAIL: pi0neerpat@users.noreply.github.com
GIT_DEPLOY_REPOSITORY_AUTHOR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
#
# Build
#
build:
name: Build
runs-on: ubuntu-20.04
timeout-minutes: 10
strategy:
fail-fast: true
matrix:
platform: [api, web]
include:
- platform: api
# TODO: Change this to the production database
# Name of Github secret
DATABASE_URL: __DEVELOPMENT_DATABASE_URL
- platform: web
steps:
# Checkout source code
- name: Checkout source code
uses: actions/checkout@v2
# Setup Docker using buildx-action
- name: Setup Docker
uses: docker/setup-buildx-action@v1
# Login to Docker Container Registry
- name: Docker login
uses: docker/login-action@v1
with:
registry: ${{ env.CONTAINER_REGISTRY_HOSTNAME }}
username: ${{ env.CONTAINER_REGISTRY_USERNAME }}
password: ${{ env.CONTAINER_REGISTRY_PASSWORD }}
# Build Docker image with a :latest and :<git sha> tag
- name: Docker build
uses: docker/build-push-action@v2
with:
push: true
context: .
file: ./${{ matrix.platform }}/Dockerfile
build-args: |
NODE_ENV=${{ env.NODE_ENV }}
RUNTIME_ENV=${{ env.RUNTIME_ENV }}
DATABASE_URL=${{ secrets[matrix.DATABASE_URL] }}
tags: |
${{ env.CONTAINER_REGISTRY_HOSTNAME }}/${{ env.CONTAINER_REGISTRY_REPOSITORY }}/${{ env.CONTAINER_REGISTRY_IMAGE_PREFIX }}-${{ matrix.platform }}-${{ env.RUNTIME_ENV }}:latest
${{ env.CONTAINER_REGISTRY_HOSTNAME }}/${{ env.CONTAINER_REGISTRY_REPOSITORY }}/${{ env.CONTAINER_REGISTRY_IMAGE_PREFIX }}-${{ matrix.platform }}-${{ env.RUNTIME_ENV }}:${{ github.sha }}
# TODO: Add CD tooling here. See https://github.com/users/jeliasson/packages/container/package/redwoodjs-app-api-main
{
"private": true,
"workspaces": {
"packages": [
"api",
"web",
"packages/*"
]
},
"scripts": {
"build-storybook": "yarn rw storybook --build && cp web/public/mockServiceWorker.js web/public/storybook",
"chromatic": "chromatic --project-token=XXXXXX --storybook-build-dir web/public/storybook"
},
"devDependencies": {
"@redwoodjs/core": "^0.34.1",
"chromatic": "^5.9.2"
},
"eslintConfig": {
"extends": "@redwoodjs/eslint-config",
"root": true
},
"engines": {
"node": "14.x",
"yarn": "1.x"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment