This guide covers how to use OpenMorph in containerized environments, particularly for CI/CD pipelines.
# Pull the latest image
docker pull ghcr.io/developerkunal/openmorph:latest
# Transform files in current directory
docker run --rm -v $(pwd):/workspace ghcr.io/developerkunal/openmorph:latest \
--input /workspace --dry-run# Build production image
docker build -t openmorph:latest .
# Build development image with shell access
docker build -f Dockerfile.dev -t openmorph:dev .
# Build with distroless (most secure)
docker build -f Dockerfile.distroless -t openmorph:distroless .- Base:
scratch(minimal attack surface) - Size: ~10MB
- Security: Non-root user, no shell
- Use case: Production CI/CD pipelines
- Base:
gcr.io/distroless/static:nonroot - Size: ~15MB
- Security: Enhanced security with distroless
- Use case: High-security environments
- Base:
alpine:3.20 - Size: ~50MB
- Features: Shell access, debugging tools (jq, yq, vim)
- Use case: Development and debugging
name: Transform OpenAPI Specs
on:
push:
paths: ["specs/**"]
jobs:
transform:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Transform OpenAPI specs
run: |
docker run --rm \
-v ${{ github.workspace }}:/workspace \
-v ${{ github.workspace }}/output:/output \
ghcr.io/developerkunal/openmorph:latest \
--input /workspace/specs \
--config /workspace/openmorph.yaml \
--output /output/transformed-spec.yaml \
--backup
- name: Upload transformed specs
uses: actions/upload-artifact@v4
with:
name: transformed-specs
path: output/transform-specs:
image: ghcr.io/developerkunal/openmorph:latest
stage: transform
script:
- openmorph --input ./specs --config ./openmorph.yaml --output ./output/transformed.yaml
artifacts:
paths:
- output/
expire_in: 1 week
only:
changes:
- specs/**/*pipeline {
agent any
stages {
stage('Transform OpenAPI') {
steps {
script {
docker.image('ghcr.io/developerkunal/openmorph:latest').inside('-v $WORKSPACE:/workspace') {
sh '''
openmorph \
--input /workspace/specs \
--config /workspace/openmorph.yaml \
--output /workspace/output/transformed.yaml \
--backup
'''
}
}
}
}
}
}- task: Docker@2
displayName: "Transform OpenAPI specs"
inputs:
command: "run"
image: "ghcr.io/developerkunal/openmorph:latest"
arguments: |
-v $(System.DefaultWorkingDirectory):/workspace
-v $(System.DefaultWorkingDirectory)/output:/output
containerCommand: |
--input /workspace/specs
--config /workspace/openmorph.yaml
--output /output/transformed.yaml
--backup# Start development environment
docker-compose up openmorph-dev
# This gives you a shell with openmorph available# Run CI/CD profile
docker-compose --profile ci up openmorph-ci# docker-compose.override.yml
version: "3.8"
services:
openmorph:
command:
[
"--input",
"/workspace/my-specs",
"--config",
"/workspace/my-config.yaml",
"--output",
"/output/result.yaml",
]Mount your OpenAPI specification files:
docker run --rm -v /path/to/specs:/workspace ghcr.io/developerkunal/openmorph:latest --input /workspaceMount configuration file:
docker run --rm \
-v /path/to/specs:/workspace \
-v /path/to/openmorph.yaml:/config/openmorph.yaml \
ghcr.io/developerkunal/openmorph:latest \
--input /workspace \
--config /config/openmorph.yamlMount output directory for results:
docker run --rm \
-v /path/to/specs:/workspace \
-v /path/to/output:/output \
ghcr.io/developerkunal/openmorph:latest \
--input /workspace \
--output /output/transformed.yaml# Enable debug output
docker run --rm -e OPENMORPH_DEBUG=1 -v $(pwd):/workspace ghcr.io/developerkunal/openmorph:latest
# Set working directory
docker run --rm -e WORKDIR=/custom/path -v $(pwd):/custom/path ghcr.io/developerkunal/openmorph:latest# Instead of :latest
docker pull ghcr.io/developerkunal/openmorph:v1.2.3docker run --rm -v $(pwd):/workspace:ro ghcr.io/developerkunal/openmorph:latestThe production images run as non-root user automatically.
docker run --rm --memory=512m --cpus=1 -v $(pwd):/workspace ghcr.io/developerkunal/openmorph:latestdocker build -f Dockerfile.distroless -t openmorph:secure .# Enable debug output
docker run --rm -e OPENMORPH_DEBUG=1 -v $(pwd):/workspace ghcr.io/developerkunal/openmorph:latest
# Use development image for debugging
docker run --rm -it -v $(pwd):/workspace openmorph:dev bash# If you encounter permission issues
docker run --rm --user $(id -u):$(id -g) -v $(pwd):/workspace ghcr.io/developerkunal/openmorph:latestdocker run --rm ghcr.io/developerkunal/openmorph:latest --version- Use .dockerignore - Reduces build context size
- Multi-stage builds - Smaller final images
- Layer caching - Order instructions for optimal caching
- Resource limits - Prevent resource exhaustion in CI/CD
docker run --rm -v $(pwd):/workspace ghcr.io/developerkunal/openmorph:latest \
--input /workspace \
--inline-map "x-custom:x-vendor" \
--dry-rundocker run --rm -v $(pwd):/workspace ghcr.io/developerkunal/openmorph:latest \
--input /workspace \
--config /workspace/openmorph.yaml \
--output /workspace/output.yaml# Process multiple directories
for dir in spec1 spec2 spec3; do
docker run --rm -v $(pwd)/$dir:/workspace ghcr.io/developerkunal/openmorph:latest \
--input /workspace \
--output /workspace/transformed.yaml
done