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

Implement hcp_packer_registry block #11168

Merged
merged 21 commits into from
Jul 28, 2021

Conversation

sylviamoss
Copy link
Contributor

@sylviamoss sylviamoss commented Jul 27, 2021

  • Write tests
  • Add docs

Testing template

source "file" "basic-example" {
  content = "Lorem ipsum dolor sit amet"
  target = "dummy_artifact"
}

source "file" "basic-example-2" {
  content = "Lorem ipsum dolor sit amet"
}


build {
  hcp_packer_registry {
    description = <<EOT
Base Alpine container used across fakeorg to ensure the most
secure computing environment for team applications. The use of any other image is highly discouraged :DDDD.
    EOT

    labels = {
      "go" = "1.16.3",
      "ruby" = "3.0.1",
      "kernel" = "3.4.0",
      "fake" = "labels"
    }
  }

  name = "mosses-simple-artifact"
  sources = ["sources.file.basic-example"]

  source "source.file.basic-example-2" {
    target = "dummy_artifact_two"
  }
}

@sylviamoss sylviamoss changed the base branch from master to embed-corebuild-publisher July 27, 2021 10:15
Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good. I left a couple of questions.

hcl2template/types.build.go Show resolved Hide resolved
internal/packer_registry/client.go Show resolved Hide resolved
internal/packer_registry/env/env.go Outdated Show resolved Hide resolved
Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I left a few nits and one question. But this is otherwise good to go. Nicely done. Feel free to merge when ready.

"source.virtualbox-iso.ubuntu-1204",
]

source "source.amazon-ebs.ubuntu-1604" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice touch. Great to see this being captured in the test 🐛 👮

hcl2template/testdata/hcp_par/duplicate.pkr.hcl Outdated Show resolved Hide resolved
hcl2template/common_test.go Outdated Show resolved Hide resolved
}

func (b *HCPPackerRegistryBlock) WriteBucketConfig(bucket *packerregistry.Bucket) {
if b == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I learned this was possible 😆

Copy link
Contributor

@azr azr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heya, nice going ! I just had a few comments/concerns there and there, but I like the direction.

command/core_wrapper.go Show resolved Hide resolved
Comment on lines +3 to +12
name = "bucket-slug"

hcp_packer_registry {
description = <<EOT
Some description
EOT
labels = {
"foo" = "bar"
}
}
Copy link
Contributor

@azr azr Jul 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the bucket setting should be specific and not be taken from the build block, this could get quite confusing ! Like what if I want to name my build with something but push to another bucket ?

Suggested change
name = "bucket-slug"
hcp_packer_registry {
description = <<EOT
Some description
EOT
labels = {
"foo" = "bar"
}
}
name = "build-name"
hcp_packer_registry {
push_to = "alpine"
description = <<EOT
Some description
EOT
labels = {
"foo" = "bar"
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another question on the same topic, why not taking the description from the build and put that in the bucket too ?

Copy link
Contributor

@nywilken nywilken Jul 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the bucket setting should be specific and not be taken from the build block, this could get quite confusing ! Like what if I want to name my build with something but push to another bucket ?

This is fair. From the minimal viable configuration option stand point " A user should be able to push to PAR simply by adding a few environment variables" so this keeps to this promise as long as a build name is part of the configuration template. Or the user provides a HCP_PACKER_BUILD_NAME env variable along side the HCP creds.

That said I think that supporting a different build name in the future (it would be great to get beta feedback here) can be a simple thing to do. But for now it feels a little out of scope. Of course happy to be told differently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I will make the same logic for both slug and description. If not present in hcp_packer_registry, then use the ones from build.

Also, the description is not documented in the deployed docs. Is it missing or is it something new?

Copy link
Contributor

@azr azr Jul 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(talking to Wilken) I'd think the opposite, I think it would be quite easier to make of that a variable, and then pass it to the build and hcp blocks, to not repeat myself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pinging @SwampDragons as well for thoughts on last question.

Copy link
Contributor

@azr azr Jul 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a note here that I initially expected component type to be just the component that built that thing; so the docker builder, the amazon-ebs builder or the google-import pp; for example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, this is marketing, not a technical spec 😛

This is a technical spec. Otherwise it's not marketing, it's a lie.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When writing the service, I imagined "component-type" as literally the builder or post-processor that created the builder, without either name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, what Adrien said.

hcl2template/types.build.go Show resolved Hide resolved
hcl2template/types.build.go Show resolved Hide resolved
hcl2template/types.build.go Outdated Show resolved Hide resolved
hcl2template/types.build.hcp_packer_registry.go Outdated Show resolved Hide resolved
…packer_registry.mdx

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
@sylviamoss sylviamoss merged commit 26e39b5 into embed-corebuild-publisher Jul 28, 2021
@sylviamoss sylviamoss deleted the hcp_registry_block branch July 28, 2021 16:15
nywilken pushed a commit that referenced this pull request Aug 3, 2021
* parse hcp_packer_registry block

* Add config to hcp_packer_registry block

* get org and proj id from client secrets

* move org and proj id logic to client

* clean up client config

* rename InPARMode to HasHCPCredentials

* add HCP_PACKER_REGISTRY back to enable PAR when hcp block not present

* validate credentials when creating client

* fix - allow hcl2 config par enable without block

* fix build registration

* update error msg

* fix IsPAREnabled logic

* fix par enabled and bucket validation

* update hcp-sdk-go

* add hcp_packer_registry tests

* add some doc in the code

* add packer.io docs

* Update website/content/docs/templates/hcl_templates/blocks/build/hcp_packer_registry.mdx

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>

* remove copy and paste

* add slug option to hcp_packer_registry

* add slug docs

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
nywilken pushed a commit that referenced this pull request Aug 3, 2021
* parse hcp_packer_registry block

* Add config to hcp_packer_registry block

* get org and proj id from client secrets

* move org and proj id logic to client

* clean up client config

* rename InPARMode to HasHCPCredentials

* add HCP_PACKER_REGISTRY back to enable PAR when hcp block not present

* validate credentials when creating client

* fix - allow hcl2 config par enable without block

* fix build registration

* update error msg

* fix IsPAREnabled logic

* fix par enabled and bucket validation

* update hcp-sdk-go

* add hcp_packer_registry tests

* add some doc in the code

* add packer.io docs

* Update website/content/docs/templates/hcl_templates/blocks/build/hcp_packer_registry.mdx

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>

* remove copy and paste

* add slug option to hcp_packer_registry

* add slug docs

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
nywilken pushed a commit that referenced this pull request Aug 3, 2021
* parse hcp_packer_registry block

* Add config to hcp_packer_registry block

* get org and proj id from client secrets

* move org and proj id logic to client

* clean up client config

* rename InPARMode to HasHCPCredentials

* add HCP_PACKER_REGISTRY back to enable PAR when hcp block not present

* validate credentials when creating client

* fix - allow hcl2 config par enable without block

* fix build registration

* update error msg

* fix IsPAREnabled logic

* fix par enabled and bucket validation

* update hcp-sdk-go

* add hcp_packer_registry tests

* add some doc in the code

* add packer.io docs

* Update website/content/docs/templates/hcl_templates/blocks/build/hcp_packer_registry.mdx

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>

* remove copy and paste

* add slug option to hcp_packer_registry

* add slug docs

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
nywilken pushed a commit that referenced this pull request Aug 5, 2021
* Add working registry pkg

* Add custom error for handling the loading of PAR environment variables

* Working Publish to Build, with proper error handling for bucket names

* Update hcp-sdk-go to use branch instead of mod replace directive

* Update Packer build status configuration

* Add support for HCP_PACKER_BUILD_FINGERPRINT env

* Add support for publishing one or more PARtifacts from a single build

* add git shas to this branch

* Add ability to set provider name if available

* Add working RegistryBuilder type

* Add RegistryPostProcessor as wrapper post-processor

* When in PAR mode a empty RegistryPostProcessor is added to the end of
  the post-processor list to publish all final image data.

* Add support for updating a build from PAR that is not in a DONE state

* Fix a small issue with creation the initial builds for an empty
  iteration.

* Add PAR URL to post-processor display

* Implement hcp_packer_registry block (#11168)

* Update vendored Amazon plugin to v1.0.1-dev

* Fix panic when running a Packer registry build in a clean directory

* Remove the publishing of post-processor metadata from the registry
  post-processor.

* Remove metadata add from registry_builder

* Update registry builder to skip a build that was found to be DONE

Co-authored-by: Megan Marsh <megan@hashicorp.com>
Co-authored-by: Sylvia Moss <moss@hashicorp.com>
@github-actions
Copy link

I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants