0
votes

Following is how our.drone.yml looks like (and template also listed below) this an example configuration very much how we want in our production. The reason we are using a template is that our staging and production have similar configurations with values different in them(hence circuit template). And we wanted to remove duplication using the template circuit.yaml.

But currently, we are unable to do so df I don’t define the test.yaml(template) and have test step imported without template (and have the circuit template define to avoid the duplicate declaration of staging and production build) the drone build fails with

"template converter: template name given not found

If I define the test step as a template. I see the test step working but on creating the tag I see the following error

{"commit":"28ac7ad3a01728bd1e9ec2992fee36fae4b7c117","event":"tag","level":"info","msg":"trigger: skipping build, no matching pipelines","pipeline":"test","ref":"refs/tags/v1.4.0","repo":"meetme2meat/drone-example","time":"2022-01-07T19:16:15+05:30"}
---
kind: template
load: test.yaml
data:
  commands:
    - echo "machine github.com login $${GITHUB_LOGIN} password $${GITHUB_PASSWORD}" > /root/.netrc
    - chmod 600 /root/.netrc
    - go clean -testcache
    - echo "Running test"
    - go test -race ./...
  

---
kind: template
load: circuit.yaml
data:
  deploy: deploy
  create_tags:
    commands:
      - echo "Deploying version $DRONE_SEMVER"
      - echo -n "$DRONE_SEMVER,latest" > .tags
  backend_image:
    version: ${DRONE_SEMVER}
    tags:
      - '${DRONE_SEMVER}'
      - latest

And the template is below

// test.yaml
kind: pipeline
type: docker
name: test
steps:
  - name: test
    image: golang:latest
    environment:
      GITHUB_LOGIN:
        from_secret: github_username
      GITHUB_PASSWORD:
        from_secret: github_token
    commands:
      {{range .input.commands }}
      - {{ . }}
      {{end}}
    volumes:
      - name: deps
        path: /go

  - name: build
    image: golang:alpine
    commands:
      - go build -v -o out .
    volumes:
      - name: deps
        path: /go

volumes:
  - name: deps
    temp: {}

trigger:
  branch:
    - main
  event:
    - push
    - pull_request
// circuit.yaml
kind: pipeline
type: docker
name: {{ .input.deploy }}
steps:
  - name: create-tags
    image: alpine
    commands:
    {{range .input.create_tags.commands }}
    - {{ . }}
    {{end}}

  - name: build
    image: plugins/docker
    environment:
      GITHUB_LOGIN:
        from_secret: github_username
      GITHUB_PASSWORD:
        from_secret: github_token
      VERSION: {{ .input.backend_image.version }}
      SERVICE: circuits
    settings:
      auto_tag: false
      repo: ghcr.io/meetme2meat/drone-ci-example
      registry: ghcr.io