Skip to content

Commit

Permalink
feat: update ci-cd
Browse files Browse the repository at this point in the history
  • Loading branch information
rolljee committed Dec 17, 2024
1 parent 6fd3e4c commit 13a8ada
Show file tree
Hide file tree
Showing 17 changed files with 1,847 additions and 117 deletions.
4 changes: 2 additions & 2 deletions .github/actions/functional-test-backend/wait-kuzzle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

tries=0
max_tries=60
max_tries=180
echo "[$(date)] - Waiting Kuzzle..."
echo ""

Expand All @@ -14,7 +14,7 @@ do
((tries=tries+1))

if [ $tries -eq $max_tries ]; then
docker-compose logs
docker compose logs
curl http://localhost:7512?pretty
echo "Cannot connect to Kuzzle after $tries tries. Aborting."
exit 1
Expand Down
181 changes: 152 additions & 29 deletions .github/workflows/deploy_main.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,78 @@ on:
- main

env:
NODE_VERSION: "18"
NODE_VERSION: '20'
KUZZLE_PAAS_REGISTRY: harbor.paas.kuzzle.io
KUZZLE_PAAS_PROJECT: <projectId>
KUZZLE_PAAS_PROJECT: projectId

######################################
# Uncomment this to deploy the expoter
######################################

# IOT_CONSOLE_URL: https://iot-main-projectId.paas.kuzzle.io
# PUPPETEER_SERVER_URL: http://exporter-main-projectId
# PUPPETEER_SERVER_PORT: 3000

jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Login to PaaS NPM registry
uses: kuzzleio/[email protected]
with:
username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
login_only: true
npmrc_output_dir: .

- name: Lint the app
uses: ./.github/actions/lint

functional-tests-backend:
name: Functional Tests
runs-on: ubuntu-20.04
needs: [lint]
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Login to PaaS NPM registry
uses: kuzzleio/[email protected]
with:
username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
login_only: true
npmrc_output_dir: .

- name: Functionnal tests
uses: ./.github/actions/functional-test-backend

push_backend:
name: Backend artefact
needs: [functional-tests-backend]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Get current commit short SHA
id: vars
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=ref::$(echo $GITHUB_REF | cut -d / -f 3)"
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Login to registry
uses: docker/login-action@v3
Expand All @@ -32,7 +87,7 @@ jobs:
password: ${{ secrets.KUZZLE_PAAS_REGISTRY_PASSWORD }}

- name: Login PaaS
uses: kuzzleio/paas-action@v1.1.0
uses: kuzzleio/paas-action@v1.2.2
with:
username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
Expand All @@ -43,59 +98,58 @@ jobs:
run: cp ./package-lock.json ./apps/api

- name: Build and push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v6
with:
file: ./apps/api/Dockerfile
context: ./apps/api
push: true
build-args: |
KUZZLE_VAULT_KEY=${{ secrets.KUZZLE_VAULT_KEY }}
KUZZLE_ENV=main
tags: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ steps.vars.outputs.ref }}/kuzzle:${{ steps.vars.outputs.sha_short }}
tags: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ github.ref_name }}/kuzzle:${{ steps.vars.outputs.sha_short }}

deploy_backend:
name: Deploy backend artefact
runs-on: ubuntu-20.04
needs: [push_backend]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Get current commit short SHA
id: vars
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=ref::$(echo $GITHUB_REF | cut -d / -f 3)"
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Install NodeJS
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Deploy to PaaS
uses: kuzzleio/paas-action@v1.1.0
uses: kuzzleio/paas-action@v1.2.2
with:
username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
project: ${{ env.KUZZLE_PAAS_PROJECT }}
environment: ${{ steps.vars.outputs.ref }}
environment: ${{ github.ref_name }}
application: api
rollback: true
timeout: 180
image: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ steps.vars.outputs.ref }}/kuzzle:${{ steps.vars.outputs.sha_short }}
image: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ github.ref_name }}/kuzzle:${{ steps.vars.outputs.sha_short }}

push_iot_console:
name: IoT Console artefact
needs: [functional-tests-backend]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Get current commit short SHA
id: vars
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=ref::$(echo $GITHUB_REF | cut -d / -f 3)"
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Login to registry
uses: docker/login-action@v3
Expand All @@ -105,7 +159,7 @@ jobs:
password: ${{ secrets.KUZZLE_PAAS_REGISTRY_PASSWORD }}

- name: Login PaaS
uses: kuzzleio/paas-action@v1.1.0
uses: kuzzleio/paas-action@v1.2.2
with:
username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
Expand All @@ -116,42 +170,111 @@ jobs:
run: cp ./package-lock.json ./apps/web

- name: Build and push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v6
with:
build-args: |
VUE_APP_BACKEND=${{ steps.vars.outputs.ref }}
VUE_APP_BACKEND=${{ github.ref_name }}
file: ./apps/web/Dockerfile
context: ./apps/web
push: true
tags: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ steps.vars.outputs.ref }}/iot:${{ steps.vars.outputs.sha_short }}
tags: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ github.ref_name }}/iot:${{ steps.vars.outputs.sha_short }}

deploy_iot_console:
name: Deploy IoT Console App to server
runs-on: ubuntu-20.04
needs: [push_iot_console]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Get current commit short SHA
id: vars
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=ref::$(echo $GITHUB_REF | cut -d / -f 3)"
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Install NodeJS
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Deploy to PaaS
uses: kuzzleio/paas-action@v1.1.0
uses: kuzzleio/paas-action@v1.2.2
with:
username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
project: ${{ env.KUZZLE_PAAS_PROJECT }}
environment: ${{ steps.vars.outputs.ref }}
environment: ${{ github.ref_name }}
application: iot
rollback: true
timeout: 180
image: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ steps.vars.outputs.ref }}/iot:${{ steps.vars.outputs.sha_short }}
image: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ github.ref_name }}/iot:${{ steps.vars.outputs.sha_short }}

######################################
# Uncomment this to deploy the expoter
######################################

# push_exporter:
# name: Exporter artefact
# needs: [functional-tests-backend]
# runs-on: ubuntu-20.04
# steps:
# - uses: actions/checkout@v4

# - name: Get current commit short SHA
# id: vars
# shell: bash
# run: |
# echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

# - name: Login to registry
# uses: docker/login-action@v3
# with:
# registry: ${{ env.KUZZLE_PAAS_REGISTRY }}
# username: ${{ secrets.KUZZLE_PAAS_REGISTRY_USERNAME }}
# password: ${{ secrets.KUZZLE_PAAS_REGISTRY_PASSWORD }}

# - name: Login PaaS
# uses: kuzzleio/[email protected]
# with:
# username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
# password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
# npmrc_output_dir: ./apps/exporter
# login_only: true

# - name: Copy package-lock.json
# run: cp ./package-lock.json ./apps/exporter

# - name: Build and push
# uses: docker/build-push-action@v6
# with:
# build-args: |
# IOT_CONSOLE_URL=${{ env.IOT_CONSOLE_URL}}
# file: ./apps/exporter/Dockerfile
# context: ./apps/exporter
# push: true
# tags: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ github.ref_name }}/exporter:${{ steps.vars.outputs.sha_short }}

# deploy_exporter:
# name: Deploy Exporter App to server
# runs-on: ubuntu-20.04
# needs: [push_exporter]
# steps:
# - uses: actions/checkout@v4

# - name: Get current commit short SHA
# id: vars
# shell: bash
# run: |
# echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

# - name: Deploy to PaaS
# uses: kuzzleio/[email protected]
# with:
# username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
# password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
# project: ${{ env.KUZZLE_PAAS_PROJECT }}
# environment: ${{ github.ref_name }}
# application: exporter
# rollback: true
# timeout: 180
# image: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ github.ref_name }}/exporter:${{ steps.vars.outputs.sha_short }}
32 changes: 13 additions & 19 deletions .github/workflows/development.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,52 @@ on:
pull_request: # All pull requests

env:
NODE_VERSION: "18"
NODE_VERSION: "20"

jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Login to PaaS NPM registry
uses: kuzzleio/paas-action@v1.1.0
uses: kuzzleio/paas-action@v1.2.2
with:
username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
login_only: true
npmrc_output_dir: ./
npmrc_output_dir: .

- name: Copy NPMRC
run: cp .npmrc ~/.npmrc


- uses: ./.github/actions/lint
- name: Lint the app
uses: ./.github/actions/lint

functional-tests-backend:
name: Functional Tests
runs-on: ubuntu-20.04
needs: [lint]
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Login to PaaS NPM registry
uses: kuzzleio/paas-action@v1.1.0
uses: kuzzleio/paas-action@v1.2.2
with:
username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
login_only: true
npmrc_output_dir: ./

- name: Copy NPMRC
run: cp .npmrc ~/.npmrc

npmrc_output_dir: .

- uses: ./.github/actions/functional-test-backend
- name: Functionnal tests
uses: ./.github/actions/functional-test-backend
9 changes: 9 additions & 0 deletions apps/api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
npm-debug.log
Dockerfile
.dockerignore
.git
.gitignore
README.md
tests
*.test.js
Loading

0 comments on commit 13a8ada

Please sign in to comment.