Join our community Discord , if you need some help.

Automatically deploy your application to staging

In this guide you will set up a deploy policy to automatically deploy every new git commit to staging.

Prerequisites

Automating staging deploys

To deploy every new main branch commit to staging, add the following deploy policy section to the .gimlet/staging.yaml file.

Also, change your image tag to follow your image tagging convention

# .gimlet/staging.yaml
app: frontend
env: staging
namespace: my-team
+deploy:
+ branch: main
+ event: push
chart:
repository: https://chart.onechart.dev
name: onechart
version: 0.32.0
values:
replicas: 2
image:
repository: myapp
- tag: 1.1.0
+ tag: "{{ .GITHUB_SHA }}"
ingress:
host: myapp.staging.mycompany.com
tlsEnabled: true

Gimlet supports multiple deploy conditions, but before this is going to work, you have to set up the missing link between your CI and Gimlet. Let's set it up now, shall we?

Before Gimlet can act on your new commits, it must know about every new artifact you build.

Your CI typically

  • runs tests
  • builds your app
  • and also builds a docker image

When it is ready with all that, it must signal Gimlet that there is a new releasable application version.

To do that, you have to extend your CI pipeline with an explicit step that ships this information to Gimlet.

Shipping artifact information to Gimlet

Gimlet has CI plugins that ship the needed artifact information.

First, set the GIMLET_SERVER and GIMLET_TOKEN secrets for your repository. These are GimletD API access credentials that you can get from your cluster administrator.

Then alter your Github Action pipeline to ship the artifact to GimletD.

name: Build
on:
push:
branches:
- 'main'

jobs:
shipping-artifact:
runs-on: ubuntu-latest
name: "Shipping artifact"
needs:
- docker-build
steps:
- name: Check out
uses: actions/checkout@v1
with:
fetch-depth: 1
+ - name: Shipping release artifact to Gimlet
+ id: shipping
+ uses: gimlet-io/gimlet-artifact-shipper-action@v0.4.2
+ env:
+ GIMLET_SERVER: $
+ GIMLET_TOKEN: $

If you do so, your Github Action will ship an artifact after everty docker image build.

Github Action shipping a Gimlet artifcat

Verify the shipped artifact

To verify the shipped artifact, use the Gimlet CLI:

$ export GIMLET_SERVER=<<Gimlet server URL>>
$ export GIMLET_TOKEN=<<Gilmet API token>>

$ gimlet artifact list

laszlocph/gimletd-test-repo-dc5b219d-a836-4f84-9890-8dfac2a0e993
1c3f577a - Just another monorepo commit (3 weeks ago) Laszlo Fogas
laszlocph/gimletd-test-repo@main https://github.com/laszlocph/gimletd-test-repo/commit/1c3f577a3b81963d3d9750da79d9ad8536890d9f
myapp -> staging @ push

By now, if GimletD is in place, it also already released your app to staging. Verify the latest commit in the gitops repo to see of GimletD had made the change, and on Kubernetes to see your updated application.