-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Summary
Extend sc cicd generate with a --template flag to allow generating specific workflow types (e.g., only pr-preview), rather than generating all configured templates at once.
Background
Simple Container is a cloud-agnostic deployment tool that simplifies microservice deployment across AWS, GCP, and Kubernetes. It provides:
- Infrastructure-as-Code using lightweight YAML configurations
- Automated deployments via
sc deploycommand - GitHub Actions integration via
sc cicd generate - Secrets management with
sc secretscommands
Currently, sc cicd generate generates all workflow types configured in server.yaml under workflow-generation.templates. This feature request proposes adding a --template flag to selectively generate specific workflows.
Motivation
PR preview environments are critical for modern development workflows:
- Code Review Quality - Reviewers can test changes in a live environment before approving
- Faster Feedback Loops - Developers see their changes deployed without waiting for merge
- Reduced Production Risks - Issues are caught earlier in isolated environments
- Stakeholder Demos - Non-technical stakeholders can preview features via unique URLs
Being able to generate just the pr-preview workflow independently would be useful for:
- Teams adding PR previews to an existing CI/CD setup
- Iterating on preview workflow configuration without regenerating all workflows
- Documentation and onboarding examples
Proposed Solution
Extended Command: sc cicd generate --template
# Generate only PR preview workflow for a stack
sc cicd generate --stack myorg/myapp --template pr-preview
# Generate multiple specific templates
sc cicd generate --stack myorg/myapp --template deploy --template pr-preview
# Dry run to preview what would be generated
sc cicd generate --stack myorg/myapp --template pr-preview --dry-run
# Generate all templates (current behavior, unchanged)
sc cicd generate --stack myorg/myappAvailable Templates
The --template flag would accept any of the existing workflow templates:
| Template | Description |
|---|---|
deploy |
Deploy stack on push to main/default branch |
destroy |
Destroy stack (with confirmation) |
destroy-parent |
Destroy parent infrastructure stack |
provision |
Provision infrastructure resources |
pr-preview |
Deploy ephemeral preview environments for PRs |
PR Preview Workflow Features
The generated pr-preview workflow includes:
| Feature | Description |
|---|---|
| Label-triggered deploys | Deploy only when a specific label (e.g., deploy-preview) is added to PR |
| Automatic cleanup | Destroy preview environment when PR is closed/merged |
| Dynamic URLs | Generate unique URLs like pr-123.preview.myapp.com |
| PR comments | Automatically comment with preview URL and cleanup status |
Generated PR Preview Workflow Behavior
PR Opened/Updated + "deploy-preview" label
│
▼
┌─────────────────────┐
│ Deploy Preview Env │
│ - Build container │
│ - Deploy to cloud │
│ - Create DNS record │
└─────────────────────┘
│
▼
┌─────────────────────┐
│ Comment on PR │
│ "Preview: https:// │
│ pr-123.app.com" │
└─────────────────────┘
PR Closed/Merged
│
▼
┌─────────────────────┐
│ Destroy Preview Env │
│ - Remove resources │
│ - Delete DNS record │
│ - Comment cleanup │
└─────────────────────┘
Configuration in server.yaml
To enable PR preview workflow generation, configure a preview environment and include pr-preview in templates:
cicd:
type: github-actions
config:
organization: "my-company"
environments:
staging:
type: staging
auto-deploy: true
production:
type: production
protection: true
# Preview environment for PR deployments
preview:
type: preview
protection: false
auto-deploy: true
runner: "ubuntu-latest"
pr-preview:
label-trigger: "deploy-preview"
domain-base: "preview.myapp.com"
workflow-generation:
enabled: true
templates: ["deploy", "destroy", "pr-preview"] # Include pr-previewBenefits
For Developers
- Generate only the workflow needed:
sc cicd generate --template pr-preview - Quick iteration on preview configuration
- No need to regenerate all workflows when updating one
For DevOps
- Selective workflow updates without touching production workflows
- Easier migration path for adding PR previews to existing setups
- Fine-grained control over generated files
For Organizations
- Improved code review process with live previews
- Faster release cycles
- Reduced production incidents
Alternatives Considered
- Generate all templates always - Current behavior; works but forces regeneration of all workflows
- Separate
sc cicd previewcommand - Adds complexity; extending existing command is simpler - Manual workflow creation - Error-prone and requires GitHub Actions expertise
Additional Context
Related Documentation
Similar Features in Other Tools
- Vercel Preview Deployments
- Netlify Deploy Previews
- Railway PR Environments
- Render Pull Request Previews
Implementation Notes
The existing codebase already has:
- PR preview template in
pkg/clouds/github/templates.go:346(prPreviewTemplate) - Template loading in
pkg/clouds/github/workflow_generator.go:52-58(LoadTemplates()) - Available templates via
GetWorkflowTemplateNames():["deploy", "destroy", "destroy-parent", "provision", "pr-preview"] - Generate command in
pkg/cmd/cmd_cicd/cmd_generate.go
Suggested Implementation
- Add
--templateflag tocmd_generate.go:
cmd.Flags().StringSliceVar(¶ms.Templates, "template", []string{},
"Generate specific templates only (e.g., --template pr-preview). Can be specified multiple times.")- Extend
GenerateParamsinpkg/assistant/cicd/service.go:
type GenerateParams struct {
// ... existing fields ...
Templates []string // Filter to generate only these templates
}- Filter templates in
WorkflowGenerator.GenerateWorkflows():
templatesToGenerate := wg.config.WorkflowGeneration.Templates
if len(filterTemplates) > 0 {
// Validate and use only specified templates
templatesToGenerate = filterTemplates
}