Conditional builds, multiple files, best practices?

I’m trying to get my head around the best way of doing this:

I’ve got a few Dockerfiles together in a repo, https://github.com/baxterworks-build/Dockerfiles.

I’d like to only build and release certain Dockerfiles based on the commit message (putting a prefix: at the front). I realise this isn’t quite how it’s supposed to work.

I only just found out about the ability to publish docker images from drone.io so I’m pretty new to this

A simple pipeline would look like this:

---
kind: pipeline
steps:
- name: docker
  image: plugins/docker
  settings:
    username: voltagex
    password:
      from_secret: docker_auth
    repo: voltagex/fedora-mingw64-rtlsdr
    dockerfile: fedora-mingw64-rtlsdr/Dockerfile

What I was hoping is that I could use a variable in repo and dockerfile (using the idea here - Any way to share variables between steps)

Am I better off splitting up the repo? At the moment it looks like GitLab has good subgroup support that’d let me collect everything under one overarching “project”.

What do you think?

You can install the Starlark extension [1] which can be used to dynamically define your pipeline. This is going to be a bit more advanced if you are just getting started with Drone, so you will have to work through the learning curve and also get familiar with the Starlark language. The script would probably look something like this:

def main(ctx):
  image = ""

  if ctx.build.message.find("fedora-mingw64-rtlsdr") != 0:
    image = "fedora-mingw64-rtlsdr"
  else:
    # some other image

  return {
    "kind": "pipeline",
    "name": "default",
    "steps": [{
      "name": "build",
      "image": "plugins/docker",
      "settings": {
        "username": "voltagex",
        "password": { "from_secret": "docker_auth" },
        "dockerfile": "%s/Dockerfile" % image,
        "repo": "voltagex/%s" % image,
      }
    }]
  }

[1] https://github.com/drone/drone-convert-starlark

Thanks Ash. Is this possible to do on the free cloud hosted drone.io instances?

if ctx.build.message.find("fedora-mingw64-rtlsdr") != 0:

Shouldn’t this be :

if ctx.build.message.find("fedora-mingw64-rtlsdr") != -1:

As 0 is the return if found on the first character, and -1 if not found?