Continuous deployment ✅ #
Firstly, please match those requirements:
- basic knowledge of Kuzzle
- basic knowledge of Github Actions
- access private plugins
- init my app
- deploy my app
In this section you will find an example of how to deploy in the PaaS using Github Action, a continuous deployment process.
In the previous guide, we deployed by hands our application and we saw it properly updated online.
Now I want to automate it using Github Actions. (other CI/CD will not be covered but the principle stay the same)
Github Actions #
Github actions are triggered when a repository have a .github
folder and a workflows
folder inside it.
- Some sensitive information will need to be added in Github actions secret
- KUZZLE_PAAS_USERNAME
- KUZZLE_PAAS_PASSWORD
- KUZZLE_VAULT_KEY
- The rest of the information will be added in the workflow file as environment variables
name: Deploy Main Environment # The name of the workflow in Github interface
on: # Listener on when to trigger a pipeline
push:
branches:
- main # here the pipeline will be triggered on push into the main branch
env:
KUZZLE_PAAS_REGISTRY: harbor.paas.kuzzle.io # The registry url push image to
KUZZLE_PAAS_PROJECT: paas-project-koutoulou # Reprsenting the paas-project-name
KUZZLE_PAAS_ENVIRONMENT: main # The environment name to update
KUZZLE_PAAS_APPLICATION: api # The application to update
jobs:
build_and_push:
name: Backend artefact
runs-on: ubuntu-20.04
steps:
# Checkout the repository in the runner
- uses: actions/checkout@v3
# Set somes steps variables to be used later
- 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)"
# Login to the registry
- name: Login to registry
uses: docker/login-action@v1
with:
registry: ${{ env.KUZZLE_PAAS_REGISTRY }}
username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
# Login to our plugins repository
# https://docs.kuzzle.io/paas-console/1/introduction/main-concepts/
- name: Login to PaaS NPM registry
uses: kuzzleio/paas-action@v0.7.2
with:
username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
npmrc_output_dir: .
login_only: true
# Build the docker image, and push it to the configured registry
- name: Build and push
uses: docker/build-push-action@v2
with:
file: ./Dockerfile
context: .
push: true
# You can analyze the Dockerfile in our template to see why theses build args are needed
build-args: |
KUZZLE_ENV=${{ env.KUZZLE_PAAS_ENVIRONMENT }}
KUZZLE_VAULT_KEY=${{ secrets.KUZZLE_VAULT_KEY }}
# Url will be something like: https://harbor.paas.kuzzle.io/projet_name/main/api:78546b
tags: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ steps.vars.outputs.ref }}/${{ env.KUZZLE_PAAS_APPLICATION }}:${{ steps.vars.outputs.sha_short }}
deploy:
name: Deploy backend artefact
runs-on: ubuntu-20.04
needs: [build_and_push]
steps:
# Checkout the repository in the runner
- uses: actions/checkout@v3
# Set somes steps variables to be used later
- 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)"
# Deploy the application using kourou in your cluster
- name: Deploy to PaaS
uses: kuzzleio/paas-action@v0.7.2
with:
username: ${{ secrets.KUZZLE_PAAS_USERNAME }}
password: ${{ secrets.KUZZLE_PAAS_PASSWORD }}
project: ${{ env.KUZZLE_PAAS_PROJECT }}
environment: ${{ env.KUZZLE_PAAS_ENVIRONMENT }}
application: ${{ env.KUZZLE_PAAS_APPLICATION }}
# Url will be something like: https://harbor.paas.kuzzle.io/projet_name/main/api:78546b
image: ${{ env.KUZZLE_PAAS_REGISTRY }}/${{ env.KUZZLE_PAAS_PROJECT }}/${{ env.KUZZLE_PAAS_ENVIRONMENT }}/${{ env.KUZZLE_PAAS_APPLICATION }}:${{ steps.vars.outputs.sha_short }}
Conclusion #
Now you have a fully automated deployment process, you can now push your code and it will be deployed automatically.
Community #
Edit this page on Github(opens new window)