Deploy recipes
Complete workflow files to copy for every kind of deploy: hosted apps, static sites, your own server, Docker Compose and Kubernetes.
Complete workflow files for every kind of deploy CodePinion can do. Copy one into .codepinion/workflows/, change the names, and push. Every key is explained in the Workflow file reference; every deploy target's settings are in Environments and deploy targets.
Choose a recipe
| You want to | Recipe | Strategies |
|---|---|---|
| Run your app on CodePinion | Hosted app | rolling, blue-green, canary |
| Publish a static site to your own bucket | Static site | rolling |
| Copy your code to a server over SSH | Your server | rolling, blue-green |
| Run Docker Compose on your server | Docker Compose | rolling |
| Apply manifests to your own Kubernetes cluster | Kubernetes | rolling |
| Ship to staging, then production after approval | Staging, then production | any the target supports |
| Deploy only when someone clicks a button | Deploy by hand | any the target supports |
| Block a deploy that adds a leaked key or a vulnerable package | Scan, then deploy | any |
There are two kinds of deploy job:
deploy_app: <slug>builds one of the repository's hosted apps and runs it on CodePinion. Nothing to configure first.environment: <name>ships to an environment you create under Environments, with a deploy target that says where the code goes. Create the environment and its target before you push the workflow, or the job fails with "environment is not configured".
Hosted app: test, then deploy
Ships the app only if the tests pass. With no strategy:, the release is rolling.
name: release
on:
push:
branches: [main]
jobs:
test:
image: node
steps:
- run: npm ci
- run: npm test
ship:
needs: [test]
deploy_app: my-api
Replace my-api with the app's slug, shown on its page.
Blue-green
The new version starts beside the old one. Traffic moves only once the new version answers health_path, and all at once. If it never becomes healthy, the old version keeps serving.
name: release
on:
push:
branches: [main]
jobs:
test:
image: node
steps:
- run: npm ci
- run: npm test
ship:
needs: [test]
deploy_app: my-api
strategy:
type: blue-green
health_path: /healthz
health_path must answer with a status from 200 to 399 once the app is ready to serve. Without it, traffic moves as soon as the new version's container is running.
Canary
The new version gets a small share of traffic first. Every interval seconds CodePinion checks it and, if it is healthy, moves to the next step.
name: release
on:
push:
branches: [main]
jobs:
test:
image: node
steps:
- run: npm ci
- run: npm test
ship:
needs: [test]
deploy_app: my-api
strategy:
type: canary
health_path: /healthz
steps: [10, 50, 100]
interval: 300
This sends 10% of traffic to the new version, then 50%, then all of it, waiting five minutes at each step. What counts as healthy, and how to pause or stop a canary, is under During a release.
Scan, then deploy
Adds a security scan that the deploy waits for. The release is stopped if the push brings in a committed key, a vulnerable dependency or risky code at high or above.
name: release
on:
push:
branches: [main]
jobs:
test:
image: python
steps:
- run: pip install -r requirements.txt
- run: pytest
security:
security_scan:
fail_on: high
deploy:
needs: [test, security]
deploy_app: web
Static site
A build job produces a directory and names it with artifact:. The deploy job uploads that directory to your bucket on any S3-compatible storage.
name: site
on:
push:
branches: [main]
jobs:
build-site:
image: node
steps:
- run: npm ci
- run: npm run build
artifact:
path: dist
publish:
needs: [build-site]
environment: production
Set up production with the static-cdn target. The bucket's secret access key goes in a repository secret, named as the target's credential.
Your server, over SSH
Copies the repository to your server with rsync, then runs your post-deploy command there. Set up the environment with the remote-server target.
name: deploy
on:
push:
branches: [main]
jobs:
test:
image: python
steps:
- run: pip install -r requirements.txt
- run: pytest
deploy:
needs: [test]
environment: production
With a rolling release the files are copied over the live directory, so for a moment the server has a mix of old and new files.
Blue-green on your server
Each release goes into its own directory, releases/<id>/, under the target's remote path. The post-deploy command runs inside the new release. Only if it succeeds does the current symlink move to it, so a failed command leaves the old release serving.
name: deploy
on:
push:
branches: [main]
jobs:
test:
image: python
steps:
- run: pip install -r requirements.txt
- run: pytest
deploy:
needs: [test]
environment: production
strategy:
type: blue-green
Point your web server at <remote path>/current, not at the remote path itself. The last few releases stay on disk (Releases to keep, default 5), which is how far back a rollback can go.
Docker Compose on your server
Copies the repository to your server, then runs docker compose up -d there with your compose file. Set up the environment with the remote-docker target.
name: deploy
on:
push:
branches: [main]
jobs:
test:
image: node
steps:
- run: npm ci
- run: npm test
deploy:
needs: [test]
environment: production
The images are built on your server, from the compose file. Compose replaces only the services that changed.
Your Kubernetes cluster
Runs kubectl apply against your cluster with the manifests in your repository. A directory with a kustomization.yaml is applied with -k; any other directory or file with -R -f, which includes subfolders. Set up the environment with the remote-kubernetes target and keep the kubeconfig in a repository secret.
name: deploy
on:
push:
branches: [main]
jobs:
test:
image: python
steps:
- run: pip install -r requirements.txt
- run: pytest
deploy:
needs: [test]
environment: production
To use Helm instead, set the target's Custom command, for example helm upgrade --install web ./chart -n web. Your own Deployments already roll without downtime, so rolling is the only strategy here.
Staging, then production
Deploys to staging on every push to main, then waits for an approval before production. Create both environments, and turn on requires approval for production.
name: promote
on:
push:
branches: [main]
jobs:
test:
image: node
steps:
- run: npm ci
- run: npm test
staging:
needs: [test]
environment: staging
production:
needs: [staging]
environment: production
strategy:
type: blue-green
The production job waits under Actions until someone approves it. Approvers are the people listed on the environment, or any maintainer if nobody is listed. Whoever started the run cannot approve it, unless they own the repository.
The strategy must be one the production target supports; blue-green here assumes remote-server.
Deploy by hand
Adds a Run workflow button that deploys only when someone clicks it and picks where to.
name: deploy
on:
workflow_dispatch:
inputs:
target:
type: choice
description: Where to deploy
options: [staging, production]
default: staging
jobs:
staging:
if: inputs.target == 'staging'
environment: staging
production:
if: inputs.target == 'production'
environment: production
Running a workflow needs contributor access to the repository.
Not possible yet
- A prebuilt image on your own server. The
remote-docker-imagetarget runs a container image, and today only a hosted-app deploy builds one, into CodePinion's own registry. Use Docker Compose and build on the server for now. - Blue-green or canary on Kubernetes or Docker Compose. These targets roll only. Asking for another strategy fails before anything ships.
- Canary anywhere but a hosted app.