matthew-gill / ObjectOrientedDocker

Create Dockerfiles using PHP with multistage and inheritance
MIT License
5 stars 0 forks source link

Inheritance / reuse #2

Closed ciaranmcnulty closed 4 years ago

ciaranmcnulty commented 4 years ago

If I already have a file like Main in the examples, how do I modify it, especially to add a step in the middle of the build?

With inheritance, I would need to override the entire configure method, so don't really get the benefits of reuse.

If I use composition, I can't call configure and return something useful as far as I can see

Have you considered having the build be more like a list of steps, that can then be modified / sliced / spliced?

matthew-gill commented 4 years ago

If I understand your question then it's already possible:

If you have a stage which extends another but requires assets from another stage that's required (but not in the family tree), you would override the method getDependentStages to return an array of other stages required for the build.

so:

class Builder extends Dockerfile {
}

class SomeOtherStage extends Dockerfile {

}

class MyFinalStage extends Builder {
    public function configure(): void
    {
       $this->copyFromStage(SomeOtherStage::class, 'what', 'where);
    }

   public function getDependentStages(): array
   {
      return [
              SomeOtherStage::class,
      ];
   }
}

Is this what you meant?

matthew-gill commented 4 years ago

Maybe I misinterpreted your question, how about this PR: https://github.com/matthew-gill/ObjectOrientedDocker/pull/3

@ciaranmcnulty sorry there's no description, but hopefully the snapshot test makes sense.

matthew-gill commented 4 years ago

@ciaranmcnulty I've just merged a PR doing a major overhaul.. there's now this:

https://github.com/matthew-gill/ObjectOrientedDocker/blob/master/tests/MattGill/Snapshot/Composition/SimpleCompositionTest.php

And

https://github.com/matthew-gill/ObjectOrientedDocker/tree/master/src/Examples/Composition/Simple

So I'm going to close this issue... hope it helps!