.docker:
  image: node:16-alpine
  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'
    // highlight-start
    DAGGER_CLOUD_TOKEN: $DAGGER_CLOUD_TOKEN
    // highlight-end
.dagger:
  extends: [.docker]
  before_script:
    - apk add docker-cli curl
    - cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
build:
  extends: [.dagger]
  script:
    - npm ci
    - dagger run node index.mjs
    // highlight-start
    # for ephemeral runners only: override the default docker stop timeout and
    # give the Dagger Engine more time to push cache data to Dagger Cloud
    - docker stop -t 300 $(docker ps --filter name="dagger-engine-*" -q)
    // highlight-end
