CircleCI-Public / circleci-config-sdk-ts

Generate CircleCI Configuration YAML from JavaScript or TypeScript. Use Dynamic Configuration and the Config SDK together for live generative config.
https://circleci-public.github.io/circleci-config-sdk-ts/
Apache License 2.0
82 stars 29 forks source link

Request: add support for docker_layer_caching in machine executor #146

Closed a-cordier closed 2 years ago

a-cordier commented 2 years ago

Is there an existing issue that is already proposing this?

Is your feature request related to a problem? Please describe it

It looks like generating a machine executor from the SDK does not allow to define the docker_layer_caching property.

The MachineExecutorShape object defines this property, but it is not handled by the generateContent method in the executor itself.

Describe the solution you'd like

Maybe adding a useDockerImageLayerCaching method to the MachineExecutor class

export class MachineExecutor extends Executor<MachineResourceClass> {
  image = 'ubuntu-2004:202010-01';
  docker_layer_caching?: boolean;

  generateContents(): MachineExecutorShape {
    return {
      image: this.image,
      docker_layer_caching: this.docker_layer_caching,
    };
  }

  // [..]

  withDockerLayerCaching(activate: boolean): MachineExecutor {
    this.docker_layer_caching = activate;
    return this;
  }
}

Teachability, documentation, adoption, migration strategy

Enabling docker image layer caching on machine executors

const myConfig = new CircleCI.Config();
const machine = new CircleCI.executors.MachineExecutor('large').withDockerLayerCaching(true);
const const reusableMachine = new CircleCI.reusable.ReusableExecutor('default', machine);

myConfig.addReusableExecutor(reusableMachine);

What is the motivation / use case for changing the behavior?

We are considering using the SDK to generate our continuation step and need this feature to match our existing config file

KyleTryon commented 2 years ago

Closed by #147, thanks again @a-cordier! Looking forward to seeing your avatar on the contributor's list.