Github actions workflow
Work flow with trigger events
name: BETA - Deploy Timesheet XXX service to K8S cluster
on:
push:
branches:
- beta
paths-ignore:
- 'api/**'
- 'deployment/XXX-api/**'
- '.github/workflows/api-**'
jobs:
BATCH-deployment-pipeline:
name: Run batch deployment pipeline with the beta env
uses: ./.github/workflows/xxx-deployment-pipeline.yml
with:
env: beta
module-name: xxx
namespace: XXX-batch-beta
service-name: XXX-batch
chart-path: deployment/XXX-batch/chart
cluster-url: https://vks.com/v1/qwrehdfagsfhgbx
branch: ${{github.ref}}
secrets:
harbor-pass: ${{ secrets.HARBOR_PASS }}
vks-sa-token: ${{ secrets.VKS_SA_TOKEN }}
redis-pass: ${{ secrets.XXX_REDIS_PASS }} mysql-pass: ${{ secrets.XXX_MYSQL_PASS }}
Workflow with manual trigger
name: RELEASE - Deploy Timesheet XXX service to K8S cluster
on:
workflow_dispatch:
inputs:
branch:
description: "Branch to build and deploy"
default: "master"
jobs:
BATCH-deployment-pipeline:
name: Run deployment pipeline with the release env
uses: ./.github/workflows/xxx-deployment-pipeline.yml
with:
env: release
module-name: batch
namespace: xxx-batch-release
service-name: xxx-api
chart-path: deployment/xxx-batch/chart
cluster-url: https://vks.com/v1/k8s/xxczvdfqwer
branch: ${{inputs.branch}}
secrets:
harbor-pass: ${{ secrets.HARBOR_PASS }}
vks-sa-token: ${{ secrets.VKS_SA_TOKEN }}
redis-pass: ${{ secrets.XXX_REDIS_PASS }}
mysql-pass: ${{ secrets.XXX_MYSQL_PASS }}
Pipeline
name: Pipeline for deploying XXX service to K8S cluster on:
workflow_call:
inputs:
env:
required: true
type: string
cluster-url:
required: true
type: string
namespace:
required: true
type: string
chart-path:
required: true
type: string
service-name:
required: true
type: string
module-name:
required: true
type: string
branch:
required: true
type: string
secrets:
harbor-pass:
required: true
vks-sa-token:
required: true
mysql-pass:
required: true
redis-pass:
required: true
jobs:
Checkout-build-and-push:
name: Checkout repository, build jar and docker build images and push images to harbor
environment: ${{ inputs.env }}
runs-on: rocky
steps:
- name: Check out repository code
uses: actions/checkout@v2.3.5
with:
ref: ${{ inputs.branch }}
- name: Set up Java 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: gradle
- name: Gradle Clean and Build
run: ./gradlew clean -p ${{ inputs.module-name }} bootJar -x test -x check --build-cache
- name: Login to Harbor
uses: docker/login-action@v2
with:
registry: harbor.google.com
username: harbor_user
password: ${{ secrets.harbor-pass }}
- name: Build and push docker image
uses: docker/build-push-action@v3
with:
context: .
file: ${{ inputs.module-name }}/Dockerfile
push: true
tags: harbor.google.com/ltv-timesheet/
${{ inputs.service-name }}-${{ inputs.env }}:${{ github.sha }}
- name: Cleaning old Docker images
run: docker image prune -f --all --filter "until=1h"
Deploy-Beta:
name: Deploy to VKS
environment: ${{ inputs.env }}
runs-on: rocky
needs: [Checkout-build-and-push]
steps:
- name: Check out repository code
uses: actions/checkout@v2.3.5
with:
ref: ${{ inputs.branch }}
- uses: yokawasa/action-setup-kube-tools@v0.9.2
with:
kubectl: '1.19.1'
helm: '3.11.3'
- name: Check kubectl version and helm version
run: |
kubectl version --client
helm version
- name: Set K8S authentication
run: |
kubectl config set-cluster github-actions --server=${{ inputs.cluster-url }}
kubectl config set-context github-actions --cluster=github-actions
kubectl config set-credentials user --token=${{ secrets.vks-sa-token }}
kubectl config set-context github-actions --user=user
kubectl config use-context github-actions
- name: Helm upgrade chart
run: |
kubectl create namespace ${{ inputs.namespace }} --dry-run=client -o yaml | kubectl apply -f -
helm upgrade ${{ inputs.service-name }} ${{ inputs.chart-path }} \
-i \
-n ${{ inputs.namespace }} \
-f ${{ inputs.chart-path }}/values/${{ inputs.env }}/values.yml \
--timeout 10m0s \
--atomic \
--cleanup-on-fail \
--set image.tag=${{ github.sha }} \
--set mysql.pass=${{ secrets.mysql-pass }} \
--set redis.pass=${{ secrets.redis-pass }}
- name: Notify
if: success() || failure()
uses: an/ikameshi@1.0.0
with:
if: success() || failure()
channel: channel_name
message: '[${{ github.workflow }}] <${{ github.server_url }} /${{ github.repository }}/actions/runs/${{ github.run_id }}|#${{ github.run_number }}> by ${{ github.actor }}'
nickname: 'Github Actions'
color: ${{ fromJSON('["red", "green"]')['success' == job.status] }}
icon_emoji: github
Comments
Post a Comment