Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass results from depends commands to root command #61

Open
kindermax opened this issue May 7, 2020 · 1 comment
Open

pass results from depends commands to root command #61

kindermax opened this issue May 7, 2020 · 1 comment

Comments

@kindermax
Copy link
Collaborator

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
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant