Skip to content

Commit

Permalink
feat: add deploy action (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
PainterPuppets authored Feb 28, 2023
1 parent ee1a4f3 commit 95a7f3b
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 4 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Deploy
on:
push:
branches:
- 'deploy_action'
- 'develop'
paths:
- 'packages/samples/**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 18

- name: restore lerna
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}

- name: Install project dependencies and build
run: npx lerna bootstrap

- name: Build packages
run: npm run build

- name: Get GitHub organization or user
run: echo 'ORG='$(echo $(dirname ${GITHUB_REPOSITORY}) | awk '{print tolower($0)}') >> $GITHUB_ENV

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

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

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: docker/mvp-dapp/Dockerfile
pull: true
push: true
tags: ${{ env.ORG }}/kuai-mvp-dapp:latest
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

redeploy:
name: Redeploy webhook call
runs-on: ubuntu-18.04
needs: [build]
steps:
- name: Deploy docker container webhook
uses: joelwmale/webhook-action@master
env:
WEBHOOK_URL: ${{ secrets.DEPLOY_WEBHOOK_URL }}
4 changes: 1 addition & 3 deletions docker/mvp-dapp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ COPY . /home/app
RUN npx lerna bootstrap
RUN npx lerna run build

WORKDIR /home/app/packages/samples/mvp-dapp

CMD [ "node", "./dist/main.js" ]
CMD npx lerna run start:prod --scope=kuai-mvp-dapp
13 changes: 13 additions & 0 deletions docker/mvp-dapp/hooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"id": "redeploy-mvp-dapp",
"execute-command": "/bin/bash",
"pass-arguments-to-command": [
{
"source": "string",
"name": "./redeploy.sh"
}
],
"response-message": "Redeploying mvp dapp server."
}
]
10 changes: 10 additions & 0 deletions docker/mvp-dapp/redeploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!bin/bash

ORG="${DOCKER_ORG:-painterpuppets}"
IMAGE="${MVP_DAPP_IMAGE:-kuai-mvp-dapp}"
PORT="${MVP_DAPP_PORT:-80}"

docker pull $ORG/$IMAGE:latest
docker stop $(docker ps -q --filter ancestor=$ORG/$IMAGE)
docker system prune -f
docker run --network host -e PORT=$PORT -e HOST=0.0.0.0 -d --restart=always $ORG/$IMAGE
1 change: 0 additions & 1 deletion packages/samples/mvp-dapp/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { config } from '@ckb-lumos/lumos'
import { KoaRouterAdapter, CoR, TipHeaderListener } from '@ckb-js/kuai-io'
import cors from '@koa/cors'
import { router } from './app.controller'
import './type-extends'
import {
ActorReference,
Manager,
Expand Down

0 comments on commit 95a7f3b

Please sign in to comment.