crane

April 4, 2023 ยท View on GitHub

crane logo - an origami crane

A GitLab CI ready image to upgrade services in Rancher. See the whole story on our blog at code.kiwi.com!

Python: 3.7 Code style: black Gitlab pipeline status (branch)

Usage

  1. Deploy your application on Rancher manually, with an image tagged with a git reference (our recommendation is to use the commit SHA, but you can also use git tags.)

  2. Get a Rancher Environment API key and add the API keypair as secret variables in the project, named RANCHER_ACCESS_KEY and RANCHER_SECRET_KEY.

  3. Also add RANCHER_URL and RANCHER_ENV_ID, preferably in secret variables, or in .gitlab-ci.yml. (In the example URL https://rancher.example.com/env/1a81/apps/stacks/1e551/services/1s1456/containers the environment ID is 1a81. This ID always starts with 1a.)

  4. Add something like this to your .gitlab-ci.yml:

    stages:
      # [...]
      - deploy
    
    deploy-production:
      stage: deploy
      image: kiwicom/crane:3.2.1
      script:
        - crane --stack my-app --service api --service worker
      environment:
        name: production
        url: https://my-app.example.com/
      when: manual
    

Settings

CLI flagEnvironment variableRequiredDefault
--urlRANCHER_URLYes
--access-keyRANCHER_ACCESS_KEYYes
--secret-keyRANCHER_SECRET_KEYYes
--envRANCHER_ENV_IDYes
--stackRANCHER_STACK_NAMEYes
--new-commitCRANE_NEW_COMMITNoHEAD
--new-imageCRANE_NEW_IMAGENoNone
--serviceRANCHER_SERVICE_NAMENoapp
--sidekickRANCHER_SIDEKICK_NAMENoNone
--batch-sizeCRANE_BATCH_SIZENo1
--batch-intervalCRANE_BATCH_INTERVALNo2
--start-firstCRANE_START_FIRSTNoFalse
--sleep-after-upgradeCRANE_SLEEP_AFTER_UPGRADENo0
--manual-finishCRANE_MANUAL_FINISHNoFalse

Integrations & Extensions

Slack

When --slack-token is set, crane can post an announcement to --slack-channel with details about the ongoing deployment. You can use --slack-link to add useful URLs to this announcements such as Datadog dashboards, Sentry issues, or the project repository. You can set --slack-channel multiple times; all channels will have the same annnouncement posted to them. If you're setting the channel names via the environment variable, separate them with a space.

CLI flagEnvironment variableDetails
--slack-tokenCRANE_SLACK_TOKENSlack API token
--slack-channelCRANE_SLACK_CHANNELSlack channels to announce in
--slack-linkCRANE_SLACK_LINKlinks to mention in Slack

Sentry

With --sentry-webhook, crane can post release details to Sentry. Release tracking is useful to provide additional context to errors tracked in Sentry.

CLI flagEnvironment variableDetails
--sentry-webhookCRANE_SENTRY_WEBHOOKSentry release webhook URL

Datadog

If you set an API key with --datadog-key, Crane will post successful and failed releases to your Datadog event feed. These events can then be marked on charts and displayed on dashboards.

CLI flagEnvironment variableDetails
--datadog-keyCRANE_DATADOG_KEYURLs to post release info to

Generic webhooks

With the --webhook-url option, you can specify URLs that crane will send release info to, in its own format. One use for this is for analytics; if somebody sets up a listener for these events, they'll have the data needed to identify correlations between releases and changes in user behavior or sales numbers.

CLI flagEnvironment variableDetails
--webhook-urlCRANE_WEBHOOK_URLURLs to post release info to
--webhook-tokenCRANE_WEBHOOK_TOKENAuth token for webhooks