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

only does not worked as documented in HCL #10555

Closed
tduffield opened this issue Feb 2, 2021 · 4 comments · Fixed by #10571
Closed

only does not worked as documented in HCL #10555

tduffield opened this issue Feb 2, 2021 · 4 comments · Fixed by #10571

Comments

@tduffield
Copy link

tduffield commented Feb 2, 2021

Overview of the Issue

The only and except functionality does not work as documented here. The current documentation indicates that you need to specify the source name (e.g., source.foo.bar). In fact, you actually need to specify the source name without source (e.g., foo.bar). I've tested this with multiple different builders.

Reproduction Steps

  1. Install Packer Nightly
  2. Run Build

Packer version

Packer v1.7.0-dev

Simplified Packer Buildfile

Doesn't Work

source "docker" "positive" {
  image = "alpine"
  commit = true
}

source "docker" "negative" {
  image = "alpine"
  commit = true
}

build {
  name = "test"

  sources = [
    "source.docker.positive",
    "source.docker.negative",
  ]

  provisioner "shell" {
    only = ["source.docker.positive"]
    inline = ["echo 'Hello World'"]
  }

  provisioner "shell" {
    except = ["source.docker.positive"]
    inline = ["echo 'Goodbye World'"]
  }
}

Does Work

source "docker" "positive" {
  image = "alpine"
  commit = true
}

source "docker" "negative" {
  image = "alpine"
  commit = true
}

build {
  name = "test" 

  sources = [
    "source.docker.positive",
    "source.docker.negative",
  ]

  provisioner "shell" {
    only = ["docker.positive"]
    inline = ["echo 'Hello World'"]
  }

  provisioner "shell" {
    except = ["docker.positive"]
    inline = ["echo 'Goodbye World'"]
  }
}

Operating system and Environment details

macOS Big Sur

Log Fragments and crash.log files

❯ packer build only-except.pkr.hcl                 
docker.positive: output will be in this color.
docker.negative: output will be in this color.

==> docker.positive: Creating a temporary directory for sharing data...
==> docker.negative: Creating a temporary directory for sharing data...
==> docker.positive: Pulling Docker image: alpine
==> docker.negative: Pulling Docker image: alpine
    docker.negative: Using default tag: latest
    docker.positive: Using default tag: latest
    docker.positive: latest: Pulling from library/alpine
    docker.positive: Digest: sha256:08d6ca16c60fe7490c03d10dc339d9fd8ea67c6466dea8d558526b1330a85930
    docker.positive: Status: Image is up to date for alpine:latest
    docker.positive: docker.io/library/alpine:latest
==> docker.positive: Starting docker container...
    docker.positive: Run command: docker run -v /Users/tom/.packer.d/tmp459816055:/packer-files -d -i -t --entrypoint=/bin/sh -- alpine
    docker.negative: latest: Pulling from library/alpine
    docker.negative: Digest: sha256:08d6ca16c60fe7490c03d10dc339d9fd8ea67c6466dea8d558526b1330a85930
    docker.negative: Status: Image is up to date for alpine:latest
    docker.negative: docker.io/library/alpine:latest
==> docker.negative: Starting docker container...
    docker.negative: Run command: docker run -v /Users/tom/.packer.d/tmp044837423:/packer-files -d -i -t --entrypoint=/bin/sh -- alpine
    docker.positive: Container ID: 55edeb6d4398f191b8495d24cb5311df3593fef1e9ac9804c06e063a74a19105
    docker.negative: Container ID: f881a949b0fc20de3f96c354d556ba324f833f6e76c7d6077ce01113de290839
==> docker.positive: Using docker communicator to connect: 172.17.0.3
==> docker.negative: Using docker communicator to connect: 172.17.0.4
==> docker.positive: Provisioning with shell script: /var/folders/pk/4b61s3m93kv6nzbbgn80xrrh0000gp/T/packer-shell986056931
==> docker.negative: Provisioning with shell script: /var/folders/pk/4b61s3m93kv6nzbbgn80xrrh0000gp/T/packer-shell268983907
    docker.positive: Goodbye World
    docker.negative: Goodbye World
==> docker.positive: Committing the container
==> docker.negative: Committing the container
    docker.positive: Image ID: sha256:152401b410840a94d42e8cb32b0e33c9adb4e654d6d63388790cb270edb148e0
    docker.negative: Image ID: sha256:c026867f656738235288b36feb8c4f02192a6522c8f5399d9764cca7d705d8e0
==> docker.positive: Killing the container: 55edeb6d4398f191b8495d24cb5311df3593fef1e9ac9804c06e063a74a19105
==> docker.negative: Killing the container: f881a949b0fc20de3f96c354d556ba324f833f6e76c7d6077ce01113de290839
Build 'docker.positive' finished after 2 seconds 978 milliseconds.
Build 'docker.negative' finished after 3 seconds 24 milliseconds.

Full PACKER_LOG=1 Logs

@SwampDragons
Copy link
Contributor

Thanks for catching this! We'll fix it for the next website release.

@robtayl0r
Copy link

So which one is the correct syntax? The documentation or the actual implementation?

@SwampDragons
Copy link
Contributor

The implementation; we will push a fix to the docs.

@ghost
Copy link

ghost commented Mar 8, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants