#Use the same code for Gitlab / Github Action with Dagger.io

1 messages · Page 1 of 1 (latest)

lavish wadi
#

Hi everyone, I'm new to the server !
Is it possible to make a Gitlab CI/CD pipeline (build / push) work on Gitlab and Github Action (identical code in both cases) using the Dagger.io tool ?

green iron
#

Hi @lavish wadi 👋 Yes that's exactly the power of Dagger! The idea is that you can write the code once, and run the same dagger call anywhere and it will run the same way

lavish wadi
#

Okay, but how do you include the Dagger.io part in the Gitlab CI /CD pipeline ? Do I have to rewrite “everything” in Node, Go or Python ?

green iron
#

Usually people "daggerize" their pipelines piece by piece. For example if there's a particularly complicated integration test step you could start with that and keep the rest of the existing pipeline the same. Here's an example of how to run dagger in gitlab https://docs.dagger.io/integrations/734201/gitlab

The following code samples demonstrate how to integrate Dagger with GitLab CI.

lavish wadi
#

Justement, j'ai déjà lu cette documentation, mais certains points sont encore un peu "obscur" pour moi, et il n'y a pas énormément de documentation sur le sujet...
Contenu de mon .gitlab-ci.yml :
default:
image: docker:24.0.2
services:
- docker:dind

include:

  • project: 'scafe/library/gitlab'
    ref: main
    file:
    • '/docker-image-build-project/build.gitlab-ci.yml'
    • '/docker-image-build-project/deploy.gitlab-ci.yml'

stages:

  • build
  • deploy

build-amd64:
stage: build
extends: .build-amd64

deploy-amd64:
stage: deploy
extends: .deploy-amd64

Daggerisation :
.docker:
image: docker:24.0.2
services:
- docker:${DOCKER_VERSION}-dind
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_VERIFY: '1'
DOCKER_TLS_CERTDIR: '/certs'
DOCKER_CERT_PATH: '/certs/client'
DOCKER_DRIVER: overlay2
DOCKER_VERSION: '20.10.16'
DAGGER_CLOUD_TOKEN: $DAGGER_CLOUD_TOKEN

include:

  • project: 'scafe/library/gitlab'
    ref: main
    file:
    • '/docker-image-build-project/build.gitlab-ci.yml'
    • '/docker-image-build-project/deploy.gitlab-ci.yml'

stages:

  • build
  • deploy

build:
extends: [.docker]
stage: build
before_script:
- apk add docker-cli curl
- cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
script:
- dagger run
- docker stop -t 300 $(docker ps --filter name="dagger-engine-*" -q)

deploy:
extends: [.docker]
stage: deploy
variables:
DAGGER_CLOUD_TOKEN: $DAGGER_CLOUD_TOKEN
script:
- echo "Image deployed"