ShipEnvironments and deploy targets

Environments and deploy targets

Production, staging and preview environments, who approves a deploy, and where a deploy can go.

Guide6 min read

An environment is a named place a pipeline deploys to — production, staging, or a preview — with the rules for who may deploy there and the target it ships to. Manage them under the repository's Environments tab.

Kinds and approvals

Each environment is Production, Staging or Preview.

Turn on requires approval and a deploy to that environment waits until someone approves it. List the people allowed to approve; with nobody listed, any maintainer can. Whoever started the run cannot approve their own deploy, unless they own the repository.

A workflow job deploys to an environment with environment::

YAML
jobs:
  publish:
    needs: [build-site]
    environment: production

A job like this needs no steps:: the environment's deploy target supplies them.

Deploy targets

The deploy target is where an environment's deploys go. Each one has a driver:

DriverShips toStrategies
codepinion-containerA hosted app on CodePinion. Set up for you by deploy_app:.rolling, blue-green, canary
static-cdnA static site in your S3-compatible bucket, from artifact:.rolling
remote-serverYour own server, by rsync over SSH.rolling, blue-green
remote-dockerDocker Compose on your own server.rolling
remote-kubernetesYour own Kubernetes cluster.rolling
remote-docker-imageA container image run on your own server. Not available yet.rolling

Asking for a strategy the target cannot do fails before anything ships. For a complete workflow file for each target, see Deploy recipes.

remote-docker-image runs an image, and today only a hosted-app deploy builds one, so it cannot be chosen for an environment yet.

Target settings

Open the environment under Environments and choose a driver. The form asks for that driver's settings, and for a Credential: the name of a repository secret, added under Secrets first. The credential is written to a file inside the deploy job only, and is never shown again.

DriverCredential secret holds
static-cdnThe bucket's secret access key.
remote-serverThe SSH private key.
remote-dockerThe SSH private key.
remote-kubernetesThe whole kubeconfig file.

Every SSH target needs Known hosts, the server's pinned host key. Get it with ssh-keyscan -p 22 your.server.com and paste the output. Without it CodePinion refuses to connect, because it could not tell your server from an impostor.

static-cdn

SettingRequiredDefaultMeaning
S3 endpointYesThe storage API's base URL, such as https://storage.example.com.
BucketYesThe bucket the site is published into.
Access key IDYesThe bucket's access key. Its secret goes in the credential secret.
RegionNous-east-1Used only to sign requests; most S3-compatible servers accept any value.
Remove deleted filesNotrueDelete files no longer in the build. Set false only if something else writes to the bucket.
Key prefixNoPublish under this path in the bucket instead of at its root.

remote-server

SettingRequiredDefaultMeaning
HostYesThe server's hostname or public IP.
SSH userNodeployThe account CodePinion connects as.
Remote pathNo~/appWhere the code is copied to.
Known hostsYesThe server's pinned host key.
Post-deploy commandNoRun over SSH after the copy, such as sudo systemctl restart app. With blue-green it runs in the new release, before the switch.
Releases to keepNo5Blue-green only. How many earlier releases stay on disk, which is how far back a rollback can go.

remote-docker

SettingRequiredDefaultMeaning
HostYesThe server's hostname or public IP.
SSH userNodeployThe account CodePinion connects as.
Remote pathNo~/appWhere the code is copied before compose runs.
Compose fileNodocker-compose.ymlRelative to the remote path.
Known hostsYesThe server's pinned host key.

remote-kubernetes

SettingRequiredDefaultMeaning
Manifest pathNo.The directory or file to apply: with -k if it holds a kustomization.yaml, otherwise with -R -f.
NamespaceNoPassed as --namespace. The namespace must already exist.
Custom commandNoReplaces kubectl apply, such as a helm upgrade --install line.

Test connection on a saved target checks that CodePinion can reach it, without deploying anything.

Release strategies

Set strategy: on a deploy job:

  • rolling replaces instances a few at a time.
  • blue-green starts the new version beside the old one, then switches all traffic at once. On a hosted app it first waits for health_path to answer; on your own server the post-deploy command is the check.
  • canary sends a growing share of traffic to the new version in steps, waiting at each one:
YAML
strategy:
  type: canary
  steps: [10, 50, 100]
  interval: 300

Steps must climb and end at 100, with at most 10 of them. With no steps: a canary goes 10% then 100%; interval is the seconds each step waits, from 30 to 86,400 (default 300).

During a release

A canary's progress appears on its run, under Actions, as a Canary release panel showing the share of traffic on each version.

At each step CodePinion checks the new version:

  • If any of its containers has restarted since the release began, the canary rolls back on its own.
  • If not all of its containers are ready yet, it waits another interval instead of failing.
  • If it is healthy, it moves to the next step. After the last step, the new version becomes the stable one.

Maintainers can act on a running canary:

ButtonDoes
PauseHolds the current split until resumed.
ResumeCarries on from the current step.
Promote nowSkips the remaining steps and sends all traffic to the new version. Asks first.
Roll backSends all traffic back to the previous version at once. Does not ask.

To go back to an earlier release of any environment, use Re-deploy on that deployment under Environments, or Roll back on a hosted app's Deployments tab. A rollback goes through the environment's approval rule like any other deploy.

Static sites

A build job names the directory it produces with artifact:, and a deploy job ships it:

YAML
jobs:
  build-site:
    image: node
    steps:
      - run: npm ci
      - run: npm run build
    artifact:
      path: dist

  publish:
    needs: [build-site]
    environment: production

The full rules for every key are in the Workflow file reference.