Skip to content

Commit

Permalink
github actions to build and deploy to k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiningRay committed Nov 18, 2022
1 parent fba18af commit e952b30
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.github
.husky
node_modules
dist
build
61 changes: 61 additions & 0 deletions .github/workflows/_build_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Pull, build, push and deploy
on:
workflow_call:
inputs:
ckb-mode:
required: true
type: string
api-url:
required: true
type: string
k8s-namespace:
required: true
type: string
k8s-workload:
required: true
type: string
secrets:
GHCR_USERNAME:
required: true
GHCR_TOKEN:
required: true
KUBOARD_USERNAME:
required: true
KUBOARD_ACCESS_KEY:
required: true
KUBOARD_API_URL:
required: true
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 0

- name: Build and push
id: docker_build
uses: mr-smithers-excellent/docker-build-push@v5
with:
image: ckb-explorer-frontend
registry: ghcr.io
githubOrg: magickbase # optional
buildArgs: "API_URL=${{ inputs.api-url }},CHAIN_TYPE=${{ inputs.ckb-mode }}"
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Update image on K8S
uses: fjogeleit/http-request-action@v1
with:
url: ${{ secrets.KUBOARD_API_URL }}/cluster/ckb/kind/CICDApi/ops/resource/updateImageTag
method: 'PUT'
customHeaders: '{"Content-Type": "application/json", "Cookie": "KuboardUsername=${{ secrets.KUBOARD_USERNAME }}; KuboardAccessKey=${{ secrets.KUBOARD_ACCESS_KEY }}"}'
data: '{"kind":"deployments","namespace":"${{ inputs.k8s-namespace }}","name":"${{ inputs.k8s-workload }}","images":{"ckb-explorer-frontend":"${{ steps.docker_build.outputs.imageFullName }}:${{ steps.docker_build.outputs.tags }}"}}'
- name: Restart container
uses: fjogeleit/http-request-action@v1
with:
url: ${{ secrets.KUBOARD_API_URL }}/cluster/ckb/kind/CICDApi/ops/resource/restartWorkload
method: 'PUT'
customHeaders: '{"Content-Type": "application/json", "Cookie": "KuboardUsername=${{ secrets.KUBOARD_USERNAME }}; KuboardAccessKey=${{ secrets.KUBOARD_ACCESS_KEY }}"}'
data: '{"kind":"deployments","namespace":"${{ inputs.k8s-namespace }}","name":"${{ inputs.k8s-workload }}"}'


22 changes: 8 additions & 14 deletions .github/workflows/mainnet.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
name: CI
name: Deploy to mainnet

on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
uses: ./.github/workflows/_build_deploy.yml
with:
ckb-mode: mainnet
api-url: $MAINNET_API_URL
k8s-namespace: mainnet
k8s-workload: ckb-explorer-front
secrets: inherit

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 0

- name: Push to dokku
uses: dokku/github-action@master
with:
# specify the `main` branch as the remote branch to push to
branch: 'main'
git_push_flags: '--force'
git_remote_url: ${{ secrets.MAINNET_HOST_URL }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
24 changes: 8 additions & 16 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
name: CI
name: Deploy to staging

on:
push:
branches:
- develop
jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 0

- name: Push to dokku
uses: dokku/github-action@master
with:
# specify the `main` branch as the remote branch to push to
branch: 'develop'
git_push_flags: '--force'
git_remote_url: ${{ secrets.STAGING_HOST_URL }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
uses: ./.github/workflows/_build_deploy.yml
with:
ckb-mode: testnet
api-url: $STAGING_API_URL
k8s-namespace: staging
k8s-workload: ckb-explorer-front
secrets: inherit
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: CI
name: Unit Test

on: [push]

jobs:
build:
test:
runs-on: ubuntu-latest

steps:
Expand Down
23 changes: 8 additions & 15 deletions .github/workflows/testnet.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
name: CI
name: Deploy to testnet

on:
push:
branches:
- testnet
jobs:
deploy:
runs-on: ubuntu-latest
uses: ./.github/workflows/_build_deploy.yml
with:
ckb-mode: testnet
api-url: $TESTNET_API_URL
k8s-namespace: testnet
k8s-workload: ckb-explorer-front
secrets: inherit

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 0

- name: Push to dokku
uses: dokku/github-action@master
with:
# specify the `main` branch as the remote branch to push to
branch: 'testnet'
git_push_flags: '--force'
git_remote_url: ${{ secrets.TESTNET_HOST_URL }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ coverage/
*.tmp
*.swo

.env.local
.secrets
!.secrets.example
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12.22.8
4 changes: 4 additions & 0 deletions .secrets.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GHCR_TOKEN=ghp_....
GHCR_USERNAME=nervos
KUBOARD_USERNAME=devops
KUBOARD_ACCESS_KEY=...
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ RUN rm -rf ./*
COPY --from=builder /app/build ./
COPY front.conf /etc/nginx/conf.d/front.conf

EXPOSE 80
EXPOSE 80

0 comments on commit e952b30

Please sign in to comment.