Skip to content

Create initial linting, apis, dockerfile, tests #33

Create initial linting, apis, dockerfile, tests

Create initial linting, apis, dockerfile, tests #33

name: Backend - E2E test
on:
pull_request_target:
branches:
- main
paths:
- "assistant/backend/**"
env:
DOCKER_TIMEOUT: 30
jobs:
build:
name: Backend E2E test
runs-on: ubuntu-latest
permissions: write-all
steps:
# Get the code
- name: Prep - Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
# Create local Docker image registry
- name: Prep - Local Image registry
run: |
docker run -d -p 5000:5000 --restart=always --name registry registry:2
# Build local Docker image
- name: Build - Docker image
working-directory: ./assistant/backend
run: |
# Build the Docker image
docker build --build-arg "JFROG_USER=${{ secrets.JFROG_IDENTITY_USER }}" --build-arg "JFROG_TOKEN=${{ secrets.JFROG_IDENTITY_TOKEN }}" -t ai-backend .
# Check the Docker image
- name: Build - Check Docker image
run: docker images ai-backend
# Push image to local registry
- name: Publish - Push image to local registry
run: |
docker tag ai-backend:latest localhost:5000/ai-backend:latest
docker push localhost:5000/ai-backend:latest
# Copy local registry configuration
- name: K3s - Configure local registry for k3s
run: |
mkdir -p ~/.k3s
cp .scripts/kubernetes/registries.yaml ~/.k3s/registries.yaml
# Install and configure K3s cluster
- name: K3s - Install and configure K3s cluster
run: .scripts/shell/k3s-installation.sh
# Verify K3s cluster
- name: K3s - Verify K3s cluster
run: |
kubectl get nodes
kubectl get ns
# Deploy the Docker image to the K3s cluster
## Ceare namespace
- name: Deploy - Create namespace
run: |
kubectl apply -f .scripts/kubernetes/ai-backend-namespace.yaml
## Create secret
- name: Deploy - Create secret on K3s
run: |
echo "${{ secrets.K3S_SECRET }}" > .scripts/kubernetes/ai-backend-secret.yaml
kubectl apply -f .scripts/kubernetes/ai-backend-secret.yaml
rm -f .scripts/kubernetes/ai-backend-secret.yaml
## Create configmap
- name: Deploy - Create configmap on K3s
run: |
echo "${{ secrets.K3S_CONFIGMAP }}" > .scripts/kubernetes/ai-backend-configmap.yaml
kubectl apply -f .scripts/kubernetes/ai-backend-configmap.yaml
rm -f .scripts/kubernetes/ai-backend-configmap.yaml
## Deploy pod and service (NodePort)
- name: Deploy - Create Backend and NodePort service
run: |
kubectl apply -f .scripts/kubernetes/ai-backend-deployment.yaml
## Check the deployment
- name: Deploy - Wait for deployment
run: .scripts/shell/deploy-wait-for-deployment.sh $DOCKER_TIMEOUT
# Backend health check - /api/v1/health/check
- name: Test - Health check
run: .scripts/shell/test-health-check.sh
# Backend resources check - /api/v1/resources
- name: Test - Cluster resources
run: .scripts/shell/test-api-v1-resources.sh