lets icon indicating copy to clipboard operation
lets copied to clipboard

pass results from depends commands to root command

Open kindermax opened this issue 4 years ago • 1 comments

Example

commands:
  build-image:
    persist_checksum: true
    checksum:
      - requirements.txt
    cmd: docker build -t img:${LETS_CHECKSUM} -f Dockerfile .

  unpack-container:
    depends: [build-image]
    cmd: |
      if [[ ${LETS_BUILD_IMAGE_CHECKSUM_CHANGED} = true ]]; then
        cid=`docker create img:${LETS_BUILD_IMAGE_CHECKSUM}`;
        docker cp ${cid}:/usr/ ./local/usr
        docker rm ${cid}
      fi

In this example, we have build-image command with persist_checksum: true. If this command runs, it will generate env LETS_CHECKSUM_CHANGED and LETS_CHECKSUM.

It would be very convenient to pass this env vars to unpack-container as build-image is in it's depends so we could use those envs in root cmd.

env vars can be named by pattern LETS_<UPPERCASED_AND_UNDERSCORED_CMD_NAME>_CHECKSUM and so on.

kindermax avatar May 07 '20 14:05 kindermax

as a workaround we can do like

commands:
  build-image:
    persist_checksum: true
    checksum: &build-image-checksum
      - requirements.txt
    cmd: docker build -t img:${LETS_CHECKSUM} -f Dockerfile .

  unpack-container:
    depends: [build-image]
    checksum: *build-image-checksum
    persist_checksum: true
    cmd: |
      if [[ ${LETS_CHECKSUM_CHANGED} = true ]]; then
        cid=`docker create img:${LETS_CHECKSUM}`;
        docker cp ${cid}:/usr/ ./local/usr
        docker rm ${cid}
      fi

but it has some limitation - we can not split these two commands into separate files as it will break anchors and aliases

kindermax avatar May 07 '20 14:05 kindermax