CI/CD Integration
Automate pack compilation, validation, and deployment in your CI/CD pipeline.
Set up automated pack builds that compile, validate, and deploy packs on every code change.
Prerequisites
Section titled “Prerequisites”- packc installed locally
- CI/CD platform (GitHub Actions, GitLab CI, Jenkins, etc.)
- Version control repository
- Basic CI/CD knowledge
GitHub Actions
Section titled “GitHub Actions”Basic Pack Build
Section titled “Basic Pack Build”# .github/workflows/build-packs.ymlname: Build Packs
on: push: branches: [main, develop] paths: - 'prompts/**' - 'config/**' pull_request: branches: [main]
jobs: build: runs-on: ubuntu-latest
steps: - name: Checkout code uses: actions/checkout@v3
- name: Set up Go uses: actions/setup-go@v4 with: go-version: '1.22'
- name: Install packc run: go install github.com/AltairaLabs/PromptKit/tools/packc@latest
- name: Compile packs run: | mkdir -p packs packc compile --config arena.yaml --output packs/app.pack.json --id app
- name: Validate packs run: | packc validate packs/app.pack.json
- name: Upload packs uses: actions/upload-artifact@v3 with: name: compiled-packs path: packs/*.pack.jsonMulti-Environment Build
Section titled “Multi-Environment Build”# .github/workflows/build-multi-env.ymlname: Build Multi-Environment Packs
on: [push, pull_request]
jobs: build: strategy: matrix: environment: [dev, staging, prod]
runs-on: ubuntu-latest
steps: - uses: actions/checkout@v3
- uses: actions/setup-go@v4 with: go-version: '1.22'
- name: Install packc run: go install github.com/AltairaLabs/PromptKit/tools/packc@latest
- name: Compile $ pack run: | mkdir -p packs/$ packc compile \ --config config/arena.$.yaml \ --output packs/$/app.pack.json \ --id app-$
- name: Validate pack run: packc validate packs/$/app.pack.json
- name: Upload pack uses: actions/upload-artifact@v3 with: name: pack-$ path: packs/$/*.pack.jsonProduction Release
Section titled “Production Release”# .github/workflows/release-packs.ymlname: Release Packs
on: push: tags: - 'v*.*.*'
jobs: release: runs-on: ubuntu-latest
steps: - uses: actions/checkout@v3
- uses: actions/setup-go@v4 with: go-version: '1.22'
- name: Install packc run: go install github.com/AltairaLabs/PromptKit/tools/packc@latest
- name: Get version id: version run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Compile production pack run: | mkdir -p packs/prod packc compile \ --config config/arena.prod.yaml \ --output packs/prod/app-v$.pack.json \ --id app-v$
- name: Validate pack run: packc validate packs/prod/app-v$.pack.json
- name: Create release uses: softprops/action-gh-release@v1 with: files: packs/prod/*.pack.json body: | ## Prompt Pack Release v$
Compiled packs for production deployment.
Compiler: $(packc version)GitLab CI
Section titled “GitLab CI”Basic Pipeline
Section titled “Basic Pipeline”# .gitlab-ci.ymlstages: - build - validate - deploy
variables: PACK_ID: app GO_VERSION: "1.22"
before_script: - apt-get update && apt-get install -y golang-$GO_VERSION - go install github.com/AltairaLabs/PromptKit/tools/packc@latest - export PATH=$PATH:$(go env GOPATH)/bin
build:packs: stage: build script: - mkdir -p packs - packc compile --config arena.yaml --output packs/app.pack.json --id $PACK_ID artifacts: paths: - packs/*.pack.json expire_in: 1 day
validate:packs: stage: validate dependencies: - build:packs script: - packc validate packs/app.pack.json
deploy:production: stage: deploy dependencies: - build:packs only: - main script: - ./scripts/deploy-pack.sh packs/app.pack.json environment: name: productionMulti-Environment Pipeline
Section titled “Multi-Environment Pipeline”# .gitlab-ci.yml.build_template: stage: build script: - mkdir -p packs/$ENVIRONMENT - packc compile --config config/arena.$ENVIRONMENT.yaml --output packs/$ENVIRONMENT/app.pack.json --id app-$ENVIRONMENT - packc validate packs/$ENVIRONMENT/app.pack.json artifacts: paths: - packs/$ENVIRONMENT/*.pack.json
build:dev: extends: .build_template variables: ENVIRONMENT: dev only: - develop
build:staging: extends: .build_template variables: ENVIRONMENT: staging only: - staging
build:prod: extends: .build_template variables: ENVIRONMENT: prod only: - mainJenkins
Section titled “Jenkins”Declarative Pipeline
Section titled “Declarative Pipeline”// Jenkinsfilepipeline { agent any
environment { PACK_ID = 'app' GO_VERSION = '1.22' }
stages { stage('Setup') { steps { sh 'go version' sh 'go install github.com/AltairaLabs/PromptKit/tools/packc@latest' sh 'packc version' } }
stage('Compile') { steps { sh 'mkdir -p packs' sh "packc compile --config arena.yaml --output packs/app.pack.json --id ${PACK_ID}" } }
stage('Validate') { steps { sh 'packc validate packs/app.pack.json' } }
stage('Archive') { steps { archiveArtifacts artifacts: 'packs/*.pack.json', fingerprint: true } }
stage('Deploy') { when { branch 'main' } steps { sh './scripts/deploy-pack.sh packs/app.pack.json' } } }
post { success { echo 'Pack build successful!' } failure { echo 'Pack build failed!' } }}Multi-Branch Pipeline
Section titled “Multi-Branch Pipeline”// Jenkinsfilepipeline { agent any
stages { stage('Compile') { steps { script { def environment = env.BRANCH_NAME == 'main' ? 'prod' : env.BRANCH_NAME
sh "mkdir -p packs/${environment}" sh "packc compile --config config/arena.${environment}.yaml --output packs/${environment}/app.pack.json --id app-${environment}" sh "packc validate packs/${environment}/app.pack.json" } } } }}CircleCI
Section titled “CircleCI”# .circleci/config.ymlversion: 2.1
orbs: go: circleci/go@1.9
jobs: build-packs: docker: - image: cimg/go:1.22 steps: - checkout
- run: name: Install packc command: go install github.com/AltairaLabs/PromptKit/tools/packc@latest
- run: name: Compile packs command: | mkdir -p packs packc compile --config arena.yaml --output packs/app.pack.json --id app
- run: name: Validate packs command: packc validate packs/app.pack.json
- store_artifacts: path: packs destination: compiled-packs
- persist_to_workspace: root: . paths: - packs/*.pack.json
deploy-packs: docker: - image: cimg/base:stable steps: - attach_workspace: at: .
- run: name: Deploy packs command: ./scripts/deploy-pack.sh packs/app.pack.json
workflows: build-and-deploy: jobs: - build-packs - deploy-packs: requires: - build-packs filters: branches: only: mainDocker Integration
Section titled “Docker Integration”Build in Docker
Section titled “Build in Docker”# Dockerfile.packc-buildFROM golang:1.22 AS builder
# Install packcRUN go install github.com/AltairaLabs/PromptKit/tools/packc@latest
# Copy source filesWORKDIR /workspaceCOPY . .
# Compile packsRUN mkdir -p packs && \ packc compile --config arena.yaml --output packs/app.pack.json --id app && \ packc validate packs/app.pack.json
# Runtime imageFROM alpine:latestCOPY --from=builder /workspace/packs /packs
CMD ["ls", "-la", "/packs"]Build and extract packs:
# Build imagedocker build -f Dockerfile.packc-build -t packc-builder .
# Extract packsdocker run --rm -v $(pwd)/output:/output packc-builder cp -r /packs/. /output/Use in CI
Section titled “Use in CI”# .github/workflows/docker-build.yml- name: Build packs with Docker run: | docker build -f Dockerfile.packc-build -t packc-builder . docker run --rm -v $(pwd)/packs:/output packc-builder cp -r /packs/. /output/Makefile CI Integration
Section titled “Makefile CI Integration”# Makefile for CI/CD
.PHONY: ci-buildci-build: clean install compile validate
.PHONY: installinstall: @echo "Installing packc..." @go install github.com/AltairaLabs/PromptKit/tools/packc@latest @packc version
.PHONY: compilecompile: @echo "Compiling packs..." @mkdir -p packs @packc compile --config arena.yaml --output packs/app.pack.json --id app
.PHONY: validatevalidate: @echo "Validating packs..." @packc validate packs/app.pack.json
.PHONY: cleanclean: @echo "Cleaning build artifacts..." @rm -rf packs/
.PHONY: deploydeploy: ci-build @echo "Deploying packs..." @./scripts/deploy-pack.sh packs/app.pack.jsonCI usage:
# GitHub Actions- name: Build and deploy run: make deploy
# GitLab CIscript: - make ci-buildBest Practices
Section titled “Best Practices”1. Cache Dependencies
Section titled “1. Cache Dependencies”GitHub Actions:
- name: Cache Go modules uses: actions/cache@v3 with: path: ~/go/pkg/mod key: $-go-$GitLab CI:
cache: paths: - .go/pkg/mod2. Version Pinning
Section titled “2. Version Pinning”Pin packc version for reproducible builds:
- name: Install packc run: go install github.com/AltairaLabs/PromptKit/tools/packc@v0.1.03. Fail Fast
Section titled “3. Fail Fast”Stop pipeline on validation failure:
- name: Validate packs run: | for pack in packs/*.pack.json; do packc validate "$pack" || exit 1 done4. Artifact Management
Section titled “4. Artifact Management”Store and version pack artifacts:
- name: Upload with version uses: actions/upload-artifact@v3 with: name: packs-$ path: packs/*.pack.json retention-days: 305. Notifications
Section titled “5. Notifications”Send build notifications:
- name: Notify on success if: success() run: ./scripts/notify-success.sh
- name: Notify on failure if: failure() run: ./scripts/notify-failure.shTroubleshooting
Section titled “Troubleshooting”packc not found in CI
Section titled “packc not found in CI”Problem: Command not found after install
Solution: Add to PATH:
- name: Add to PATH run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATHCompilation fails in CI
Section titled “Compilation fails in CI”Problem: Files not found
Solution: Check working directory:
- name: List files run: | pwd ls -la ls -la config/Permission denied
Section titled “Permission denied”Problem: Can’t create directories
Solution: Ensure write permissions:
- name: Create directories run: mkdir -p packs && chmod -R 755 packsNext Steps
Section titled “Next Steps”- Organize Pack Files - Structure your packs
- Deployment Guide - Deploy packs to production
- Monitor Builds - Track build health