CI/CD Automation Scripts
The project utilizes several automation scripts in the CI/CD pipeline to streamline processes including testing, building, and deployment. Below is a detailed exploration of the automation scripts present within the repository, highlighting their purposes and configurations.
Workflows
The CI/CD automation is encapsulated in the GitHub Actions workflows located in the .github/workflows/
directory. The key workflow files include:
deploy.yml
This file defines the steps for deploying the application. It typically includes triggers for deployment, which could be on push to specific branches, pull requests, or manually triggered actions.
Example snippet:
name: Deploy on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up Docker uses: docker/setup-buildx-action@v1 - name: Build and push Docker image uses: docker/build-push-action@v2 with: context: . push: true tags: tidbai/frontend:latest
regression.yml
The regression workflow is responsible for running tests to ensure that new changes do not break existing functionality. This workflow can be triggered by pull requests or pushes.
Example snippet:
name: Regression Tests on: pull_request: branches: - main jobs: test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Install dependencies run: | cd e2e npm install - name: Run regression tests run: | cd e2e npm test
release.yml
Designed for creating and managing releases, this workflow handles version bumps, tagging, and potentially publishing to a package repository.
Example snippet:
name: Release on: push: tags: - 'v*.*.*' jobs: release: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Build and publish run: | npm run build npm publish
verify.yml
The verify workflow may include steps for linting, code formatting checks, or other verification processes.
Example snippet:
name: Verify Code on: pull_request: branches: - main jobs: verify: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Run linter run: | npm run lint
Docker Configuration
The CI/CD also leverages Docker for containerization. The root-level Dockerfile
orchestrates the build process for multiple environments and exposes the required port 3000 for the frontend service.
Key components of the Dockerfile:
- The Dockerfile is structured into multiple stages (deps, builder, runner).
- Installation of dependencies is efficiently handled to minimize image sizes and rebuild times.
- The application is built and prepared for production deployment.
Example snippet:
FROM node:20-alpine AS base
# Build dependencies
FROM base AS deps
WORKDIR /tidb.ai/frontend
COPY frontend/package.json ./frontend
RUN corepack enable pnpm
RUN pnpm i --frozen-lockfile
# Build application
FROM base AS builder
COPY . .
WORKDIR /tidb.ai/frontend
RUN pnpm run build:docker
# Production image
FROM base AS runner
WORKDIR /tidb.ai
COPY --from=builder /tidb.ai/frontend/app/.next/standalone .
EXPOSE 3000
CMD ["node", "app/server.js"]
Docker-Compose Integration
The docker-compose.yml
file facilitates the orchestration of multiple services during development and testing.
Key components of the docker-compose file:
- Multi-service architecture including Redis, backend, and frontend.
- Service dependencies, ensuring that services are started in the correct order.
- Port mappings and persistent storage configurations to manage state and logs.
Example snippet:
services:
frontend:
image: tidbai/frontend:0.2.8
ports:
- 3000:3000
Summary
The CI/CD automation within the project is effectively managed through GitHub Actions workflows and Docker management, optimizing deployment and testing processes. Each workflow script serves specific roles, from regression testing to deployments, while the Docker configurations ensure that the application is built and run in a controlled environment.