This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/docs/getting-started/1201-ci-environment.md
user.email d20ffbe8be website: hardcode version banner for 0.1 docs
O.1 docs is deprecated. Let's inform user to switch the the latest version

Signed-off-by: user.email <jf@dagger.io>
2022-04-13 15:58:51 +02:00

3.8 KiB

slug displayed_sidebar
/1201/ci-environment 0.2

Integrating with your CI environment

Dagger can be used with any CI environment (no migration required) and has two important advantages which make the overall experience less error-prone and more efficient:

  1. You don't write YAML, you write CUE - typed configuration with built-in formatting
  2. Configuration is executed in BuildKit, the execution engine at the heart of Docker

This makes any CI environment with Docker pre-installed work with Dagger out of the box. We started with CI environments that you told us you are using. We will configure a production deployment for the same application that we covered in the previous page.

:::note If you cannot find your CI environment below, let us know via this GitHub discussion. :::

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

<Tabs defaultValue="github-actions" groupId="ci-environment" values={[ {label: 'GitHub Actions', value: 'github-actions'}, {label: 'CircleCI', value: 'circleci'}, {label: 'GitLab', value: 'gitlab'}, {label: 'Jenkins', value: 'jenkins'}, {label: 'Tekton', value: 'tekton'}, ]}>


If you would like us to document CircleCI next, vote for it here: dagger#1677

.docker:
  image: docker:${DOCKER_VERSION}-git
  services:
    - docker:${DOCKER_VERSION}-dind
  variables:
    # See https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#docker-in-docker-with-tls-enabled-in-the-docker-executor
    DOCKER_HOST: tcp://docker:2376

    DOCKER_TLS_VERIFY: '1'
    DOCKER_TLS_CERTDIR: '/certs'
    DOCKER_CERT_PATH: '/certs/client'

    # Faster than the default, apparently
    DOCKER_DRIVER: overlay2

    DOCKER_VERSION: '20.10'

.dagger:
  extends: [.docker]
  variables:
    DAGGER_VERSION: 0.2.4
    DAGGER_LOG_FORMAT: plain
    DAGGER_CACHE_PATH: .dagger-cache

    ARGS: ''
  cache:
    key: dagger-${CI_JOB_NAME}
    paths:
      - ${DAGGER_CACHE_PATH}
  before_script:
    - apk add --no-cache curl
    - |
      # install dagger
      cd /usr/local
      curl -L https://dl.dagger.io/dagger/install.sh | sh
      cd -

      dagger version      
  script:
    - dagger project update
    - |
      dagger \
          do \
          --cache-from type=local,src=${DAGGER_CACHE_PATH} \
          --cache-to type=local,mode=max,dest=${DAGGER_CACHE_PATH} \
          ${ARGS}      

build:
  extends: [.dagger]
  variables:
    ARGS: build

With docker and dagger installed on your Jenkins agent.

pipeline {
  agent any
  environment {
    //https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#handling-credentials
    //e.g.
    //DH_CREDS=credentials('jenkins-dockerhub-creds')
    //AWS_ACCESS_KEY_ID     = credentials('jenkins-aws-secret-key-id')
    //AWS_SECRET_ACCESS_KEY = credentials('jenkins-aws-secret-access-key')
  }
  stages {
    stage("setup") {
      steps {
        //only needed if you don't commit the cue.mod directory to git
        //sh '''
        //  dagger project init
        //  dagger project update
        //'''
      }
    }
    stage("do") {
      steps {
        //substitute your action name for 'helloworld'
        //e.g. 'build' or 'push' or whatever you've created!
        sh 'dagger do helloworld --log-format=plain'
      }
    }
  }
}

If you would like us to document Tekton next, vote for it here: dagger#1677