CI/CD Integration

Integrate the LegionEdge Platform with your CI/CD pipelines

The LegionEdge Platform integrates with popular CI/CD systems to automate deployments, run tests against platform resources, and manage environment promotion.

GitHub Actions

Deploy on Push

# .github/workflows/deploy.yml
name: Deploy to LegionEdge
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "20"

      - name: Install dependencies
        run: npm ci

      - name: Run tests
        run: npm test

      - name: Deploy to staging
        uses: legionedge/deploy-action@v2
        with:
          api-key: ${{ secrets.LEGIONEDGE_API_KEY }}
          project-id: ${{ vars.LEGIONEDGE_PROJECT_ID }}
          environment: staging

      - name: Promote to production
        if: github.ref == 'refs/heads/main'
        uses: legionedge/deploy-action@v2
        with:
          api-key: ${{ secrets.LEGIONEDGE_API_KEY }}
          project-id: ${{ vars.LEGIONEDGE_PROJECT_ID }}
          environment: production
          promote-from: staging

Deploy on Release

name: Release Deploy
on:
  release:
    types: [published]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: legionedge/deploy-action@v2
        with:
          api-key: ${{ secrets.LEGIONEDGE_API_KEY }}
          project-id: ${{ vars.LEGIONEDGE_PROJECT_ID }}
          environment: production
          version: ${{ github.event.release.tag_name }}

GitLab CI

# .gitlab-ci.yml
stages:
  - test
  - deploy-staging
  - deploy-production

test:
  stage: test
  image: node:20
  script:
    - npm ci
    - npm test

deploy-staging:
  stage: deploy-staging
  image: node:20
  script:
    - npm install -g @legionedge/cli
    - legionedge deploy --project $LEGIONEDGE_PROJECT_ID --env staging
  environment:
    name: staging
  only:
    - main

deploy-production:
  stage: deploy-production
  image: node:20
  script:
    - npm install -g @legionedge/cli
    - legionedge deploy --project $LEGIONEDGE_PROJECT_ID --env production --promote-from staging
  environment:
    name: production
  when: manual
  only:
    - main

Custom Pipelines with the CLI

Install the LegionEdge CLI for any CI/CD system:

npm install -g @legionedge/cli

Common CLI Commands

# Authenticate
legionedge auth login --api-key $LEGIONEDGE_API_KEY

# Deploy
legionedge deploy --project proj_abc123 --env staging

# Check deployment status
legionedge deploy status --project proj_abc123 --env staging

# Promote to production
legionedge deploy promote --project proj_abc123 --from staging --to production

# Rollback
legionedge deploy rollback --project proj_abc123 --env production

Deployment Automation with SDK

For advanced workflows, use the SDK directly in your pipeline scripts:

// scripts/deploy.ts
import { LegionEdge } from "@legionedge/sdk";

const client = new LegionEdge({
  apiKey: process.env.LEGIONEDGE_API_KEY!,
});

async function deploy() {
  const projectId = process.env.LEGIONEDGE_PROJECT_ID!;
  const environment = process.env.DEPLOY_ENV || "staging";
  const commitSha = process.env.CI_COMMIT_SHA || "unknown";

  const deployment = await client.deployments.create({
    projectId,
    environment,
    source: {
      type: "git",
      commit: commitSha,
    },
    config: {
      instances: environment === "production" ? 4 : 2,
    },
  });

  console.log(`Deployment started: ${deployment.id}`);

  // Wait for deployment to complete
  const result = await client.deployments.waitForCompletion(deployment.id, {
    timeout: 300_000, // 5 minutes
    pollInterval: 5_000,
  });

  if (result.status === "failed") {
    console.error(`Deployment failed: ${result.error}`);
    process.exit(1);
  }

  console.log(`Deployment successful: ${result.url}`);
}

deploy();

Run it from any CI system:

npx tsx scripts/deploy.ts

Environment Variables Reference

VariableDescription
LEGIONEDGE_API_KEYAPI key for authentication
LEGIONEDGE_PROJECT_IDTarget project ID
DEPLOY_ENVTarget environment
CI_COMMIT_SHAGit commit SHA (auto-set by most CI systems)

Next Steps