This documentation outlines the CI/CD deployment process for the docker/genai-stack
project. If there is no existing CI/CD setup, the steps to establish one are provided at the end of this document.
Overview
Continuous Integration (CI) and Continuous Deployment (CD) automate the process of software development, testing, and release. For docker/genai-stack
, CI/CD can be implemented using platforms like GitHub Actions, GitLab CI, or CircleCI, depending on preferences and requirements.
Step 1: Setting Up a CI/CD Pipeline
Begin by defining a CI/CD pipeline configuration file based on your chosen tool. Below are examples for GitHub Actions and GitLab CI.
GitHub Actions Example
In your repository, create a .github/workflows/ci-cd.yml
file:
name: CI/CD Pipeline
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
services:
database:
image: neo4j:5.11
ports:
- 7687:7687
- 7474:7474
env:
NEO4J_AUTH: neo4j/password
options: >-
--health-cmd="wget --no-verbose --tries=1 --spider localhost:7474 || exit 1"
--health-interval=15s
--health-timeout=30s
--health-retries=10
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build Docker images
run: |
docker-compose build
- name: Run tests
run: |
docker-compose up -d
sleep 30 # Wait for services to be healthy
docker-compose exec api pytest tests/
- name: Deploy to production
run: |
docker-compose down
docker-compose up -d
GitLab CI Example
Create a .gitlab-ci.yml
file in the root of your repository:
stages:
- build
- test
- deploy
services:
- name: neo4j:5.11
alias: database
command: ["/bin/sh", "-c", "neo4j-admin set-initial-password password && neo4j console"]
build:
stage: build
image: docker:latest
services:
- docker:dind
script:
- docker-compose build
test:
stage: test
image: docker:latest
services:
- docker:dind
script:
- docker-compose up -d
- sleep 30 # Wait for services to be healthy
- docker-compose exec api pytest tests/
deploy:
stage: deploy
script:
- docker-compose down
- docker-compose up -d
Step 2: Environment Variables Management
Ensure all environment variables required by the services are configured in the CI/CD environment. This includes:
NEO4J_URI
NEO4J_PASSWORD
NEO4J_USERNAME
OPENAI_API_KEY
GOOGLE_API_KEY
OLLAMA_BASE_URL
LLM
EMBEDDING_MODEL
LANGCHAIN_ENDPOINT
LANGCHAIN_API_KEY
- AWS credentials if necessary.
GitHub Actions Example for Secrets
In GitHub, navigate to your repository settings, click on “Secrets and variables,” and then “Actions.” Add your environment variables as secrets:
NEO4J_URI=neo4j://database:7687
NEO4J_PASSWORD=password
OPENAI_API_KEY=your_openai_key
...
Step 3: Testing and Verification
Include automated testing in your CI pipeline to ensure code quality. As shown in previous examples, use a testing framework like pytest
:
docker-compose exec api pytest tests/
This command will execute tests located in the tests
directory of your API service.
Step 4: Deploying Changes
Once tests pass, the pipeline can be configured to handle deployments automatically. Use the docker-compose down
to stop and remove existing containers and docker-compose up -d
to start new ones.
Conclusion
If no CI/CD is currently set up for the project:
- Choose a CI/CD platform that aligns with your workflow.
- Create a pipeline configuration file based on the examples provided for GitHub Actions or GitLab CI.
- Ensure environment variables are appropriately set for your CI/CD environment.
- Implement automated testing within your pipeline.
- Configure deployment steps to facilitate smooth application updates.
With these steps, the docker/genai-stack
project can be effectively integrated into a CI/CD workflow, enhancing development efficiency and software reliability.
References:
- Sample CI/CD configurations adapted from common practices in CI tools documentation.