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

Publish is not executed before deploy is executed #21522

Open
Nishikoh opened this issue Oct 13, 2024 · 2 comments · May be fixed by #21576
Open

Publish is not executed before deploy is executed #21522

Nishikoh opened this issue Oct 13, 2024 · 2 comments · May be fixed by #21576
Labels
backend: Terraform Terraform backend-related issues bug

Comments

@Nishikoh
Copy link
Contributor

Describe the bug
Publish is not executed before deploy is executed. I thought that the docker image would be published if the terraform code contained docker dependencies when performing experimental-deploy. However, contrary to my expectations, the publish was not executed.

Pants version
2.22.0

OS
Ubuntu 22.04

Additional info

#pants.toml
[GLOBAL]
pants_version = "2.22.0"
backend_packages = [
  "pants.backend.build_files.fmt.ruff",
  "pants.backend.docker",
  "pants.backend.experimental.terraform",
  "pants.backend.python",
]

[python]
interpreter_constraints = ["==3.11.*"]
# main.tf
terraform {
  backend "local" {
    path = "/tmp/tfstate/baz.tfstate"
  }
}

provider "random" {
  version = "3.6.2"
}

resource "random_id" "id" {
  byte_length = 7
}
# BUILD
terraform_module(name="main")
terraform_deployment(name="deploy", root_module=":main", dependencies=[":app-docker"])

docker_image(
  name="app-docker",
  registries=[
        "ghcr.io",
  ],
  repository="<MY USER NAME>/pants-deploy-example",
  image_tags=["latest"],
  instructions=[
    "FROM alpine",
    "RUN echo 'hello world' > /hello.txt",
  ]
)
# log
$ pants experimental-deploy --experimental-deploy-publish-dependencies :deploy 
22:16:13.67 [INFO] Deploying targets...

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # random_id.id will be created
  + resource "random_id" "id" {
      + b64_std     = (known after apply)
      + b64_url     = (known after apply)
      + byte_length = 7
      + dec         = (known after apply)
      + hex         = (known after apply)
      + id          = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.
╷
│ Warning: Version constraints inside provider configuration blocks are deprecated
│ 
│   on main.tf line 14, in provider "random":
│   14:   version = "3.6.2"
│ 
│ Terraform 0.13 and earlier allowed provider version constraints inside the provider configuration block, but that is now deprecated and will be removed
│ in a future version of Terraform. To silence this warning, move the provider version constraint into the required_providers block.
╵

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

random_id.id: Creating...
random_id.id: Creation complete after 0s [id=dzju5Fqrzw]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

✓ infra/terraform/app/baz:deploy deployed

The publish log does not appear to be flowing.

https://github.com/grihabor/pants/blob/dd11c333e71976bb135f1b75b3abd26e27959bd2/src/python/pants/core/goals/deploy.py#L214

@Nishikoh Nishikoh added the bug label Oct 13, 2024
@Nishikoh
Copy link
Contributor Author

When pants publish :app-dcocker is run by itself, it completes without problems.

$ pants publish :app-docker
22:24:31.91 [INFO] Completed: Building docker image ghcr.io/<MY USER NAME>/pants-deploy-example:latest
22:24:31.91 [INFO] Packaged app-docker.docker-info.json
The push refers to repository [ghcr.io/<MY USER NAME>/pants-deploy-example]
e97805dba242: Layer already exists 
63ca1fbb43ae: Layer already exists 
latest: digest: sha256:000271f8030b1409fe654d06416c5a67f506238fe9fc398611df7e8c704938b1 size: 734

✓ ghcr.io/<MY USER NAME>/pants-deploy-example:latest published.

@lilatomic
Copy link
Contributor

Unfortunately, items in the dependencies field are not published prior to experimental-deploy. I agree that it would be good to be able to publish some dependencies before deploying. I thought there was another issue for this, but I can't find it ATM.

The Pants engine actually supports this, although the Helm backend is really the only one to use it (and only then for Docker containers) ref. I think that extending the Terraform backend to support this (or implementing it in Pants core) would be a straightforward change.

@lilatomic lilatomic added the backend: Terraform Terraform backend-related issues label Oct 14, 2024
@lilatomic lilatomic linked a pull request Nov 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Terraform Terraform backend-related issues bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants