NiklasRosenstein / flux-ci

Flux is your own private & lightweight CI server.
MIT License
26 stars 10 forks source link

Allow to override repository files by CI user controlled files #41

Closed gsantner closed 6 years ago

gsantner commented 6 years ago

This feature allows to override repository files by CI controlled folder.

I tried to keep the amount of changes at the lowest level so it is easy to review. No extra stuff, packages or like that needed. This all too is optional, doesn't create extra directories and doesn't fail if a override dir or it's parent don't exist.

This kind of opens doors for #31 - by just reading/writing file from override dir ;) . This again should be not very hard to accomplish.

gsantner commented 6 years ago

Here is small example to get a grasp:

Repository:

grafik

Flux: grafik

Builds from previously: grafik

Builds after I added the file in overrides: grafik

NiklasRosenstein commented 6 years ago

So you just invoke the builds manually in the Flux UI?

I like this change. If I have it in my mind correctly, the build artifact will contain your overwritten files. So that's a good thing if you change the overwritten files at some point and want to look back at an old build.

Ideally in the future we can upload/edit these files directly from the repository settings. :)

NiklasRosenstein commented 6 years ago

Thanks @gsantner !

gsantner commented 6 years ago

nothing changes from any existing workflow or Ui - just files get copied over after git clone/fetch

gsantner commented 6 years ago

testing around for stages support. first notes.

what I'm posting below is public domain for now.

import yaml
STAGE_PARAM="stage"

with open('glvp.yml','r') as f:
  x=f.read()

y = yaml.load(x)

# filter out templates (started with dot)
y = {k:v for (k,v) in y.items() if isinstance(k,str) and not k.startswith(".") }

print(yaml.dump(y))
y["stages"]
y.keys()
print("stages" in y)
stages = y.pop("stages") if "stages" in y else []
print("stages" in y)
print(stages)

print(yaml.dump(y))

# Scan for unspecified stages
for k, v in y.items():
  if isinstance(v, dict) and STAGE_PARAM in y[k] and isinstance(y[k][STAGE_PARAM],str):
    if not y[k][STAGE_PARAM] in stages:
      stages.append(y[k][STAGE_PARAM])

# Add default stage when nothing found
stages=["test"] if len(stages) == 0 else stages

# Assign default stage for those without a stage
for k, v in y.items():
  if isinstance(v, dict):
    y[k][STAGE_PARAM] = y[k][STAGE_PARAM] if STAGE_PARAM in y[k] and isinstance(y[k][STAGE_PARAM],str) else stages[0]

print(yaml.dump(y))