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

refactor: Use Git branch / tag for versioning #385

Merged
merged 3 commits into from
Nov 30, 2022

Conversation

dhoppe
Copy link
Contributor

@dhoppe dhoppe commented Nov 29, 2022

Summary of Pull Request

The build already has the timestamp as build_date. Consider using the current Git branch / tag as build_version, so that it is clear on which code base the image was built.

Type of Pull Request

  • This is a bugfix. type/bug
  • This is an enhancement or feature. type/feature or type/enhancement
  • This is a documentation update. type/docs
  • This is a refactoring update. type/refactor
  • This is a chore. type/chore
  • This is something else.
    Please describe:

Related to Existing Issues

Closes #388

Test and Documentation Coverage

  • Tests have been completed.
  • Documentation has been added or updated.

Breaking Changes?

  • Yes, there are breaking changes.
  • No, there are no breaking changes.

@dhoppe dhoppe requested a review from a team as a code owner November 29, 2022 09:21
@dhoppe
Copy link
Contributor Author

dhoppe commented Nov 29, 2022

@tenthirtyam Please let me know what you think about this code change and I will add the other operating systems / releases.

@tenthirtyam tenthirtyam changed the title chore: Use Git branch / tag instead of current year / month refactor: use git branch / tag for versioning Nov 29, 2022
@tenthirtyam
Copy link
Contributor

Hi @dhoppe 👋

Could you kindly open an enhancement request for this refactoring and link the pull request?

Thanks!

Ryan Johnson
Senior Staff Solutions Architect | Product Engineering @ VMware, Inc.

@tenthirtyam tenthirtyam added the type/refactor Refactor label Nov 29, 2022
@tenthirtyam tenthirtyam added this to the Backlog milestone Nov 29, 2022
@tenthirtyam tenthirtyam added the size/s Small label Nov 29, 2022
Copy link
Contributor

@tenthirtyam tenthirtyam left a comment

Choose a reason for hiding this comment

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

Initial testing from a git clone...

CONFIRM: Build a Ubuntu Server 22.04 LTS (cloud-init) Template for VMware vSphere?

Continue? (y/n)
y
Building a Ubuntu Server 22.04 LTS (cloud-init) Template for VMware vSphere...
Initializing HashiCorp Packer and required plugins...
Starting the build....
Error: Datasource.Execute failed: reference not found

  on /Users/tenthirtyam/Downloads/packer-examples-for-vsphere-build_version/builds/linux/ubuntu/22-04-lts/linux-ubuntu.pkr.hcl line 26:
  (source code not available)

Error: Unsupported attribute

  on /Users/tenthirtyam/Downloads/packer-examples-for-vsphere-build_version/builds/linux/ubuntu/22-04-lts/linux-ubuntu.pkr.hcl line 41:
  (source code not available)

This object does not have an attribute named "vm_name".

Error: Unsupported attribute

  on /Users/tenthirtyam/Downloads/packer-examples-for-vsphere-build_version/builds/linux/ubuntu/22-04-lts/linux-ubuntu.pkr.hcl line 54:
  (source code not available)

This object does not have an attribute named "build_version".

Error: Unsupported attribute

  on /Users/tenthirtyam/Downloads/packer-examples-for-vsphere-build_version/builds/linux/ubuntu/22-04-lts/linux-ubuntu.pkr.hcl line 34:
  (source code not available)

This object does not have an attribute named "git-repository".

Error: Unsupported attribute

  on /Users/tenthirtyam/Downloads/packer-examples-for-vsphere-build_version/builds/linux/ubuntu/22-04-lts/linux-ubuntu.pkr.hcl line 35:
  (source code not available)

This object does not have an attribute named "build_version".

@dhoppe dhoppe changed the title refactor: use git branch / tag for versioning refactor: Use Git branch / tag for versioning Nov 29, 2022
@dhoppe
Copy link
Contributor Author

dhoppe commented Nov 29, 2022

@tenthirtyam Could you please check if the Git plugin has been installed?

➜ packer plugins installed
/usr/local/bin/github.com/ethanmdavidson/git/packer-plugin-git_v0.3.2_x5.0_darwin_amd64
/usr/local/bin/github.com/hashicorp/vsphere/packer-plugin-vsphere_v1.1.0_x5.0_darwin_amd64

I do not have any issues, except the missing Ansible config related to OpenSSH 9.x.

CONFIRM: Build a Debian 11 Template for VMware vSphere?

Continue? (y/n)
y
Building a Debian 11 Template for VMware vSphere...
Initializing HashiCorp Packer and required plugins...
Starting the build....
vsphere-iso.linux-debian: output will be in this color.

==> vsphere-iso.linux-debian: Publishing build details for vsphere-iso.linux-debian to the HCP Packer registry
==> vsphere-iso.linux-debian: Creating VM...
==> vsphere-iso.linux-debian: Customizing hardware...
==> vsphere-iso.linux-debian: Adding SATA controller...
==> vsphere-iso.linux-debian: Mounting ISO images...
==> vsphere-iso.linux-debian: Adding configuration parameters...
==> vsphere-iso.linux-debian: Starting HTTP server on port 8054
==> vsphere-iso.linux-debian: Set boot order...
==> vsphere-iso.linux-debian: Power on VM...
==> vsphere-iso.linux-debian: Waiting 5s for boot...
==> vsphere-iso.linux-debian: HTTP server is working at http://10.0.30.10:8054/
==> vsphere-iso.linux-debian: Typing boot command...
==> vsphere-iso.linux-debian: Waiting for IP...
==> vsphere-iso.linux-debian: IP address: 10.0.30.153
==> vsphere-iso.linux-debian: Using SSH communicator to connect: 10.0.30.153
==> vsphere-iso.linux-debian: Waiting for SSH to become available...
==> vsphere-iso.linux-debian: Connected to SSH!
==> vsphere-iso.linux-debian: Provisioning with Ansible...
    vsphere-iso.linux-debian: Setting up proxy adapter for Ansible....
==> vsphere-iso.linux-debian: Executing Ansible: <sensitive>-playbook -e packer_build_name="linux-debian" -e packer_builder_type=vsphere-iso -e packer_http_addr=10.0.30.10:8054 --ssh-extra-args '-o IdentitiesOnly=yes' --extra-vars display_skipped_hosts=false --extra-vars BUILD_USERNAME=<sensitive> --extra-vars BUILD_SECRET=***** --extra-vars ANSIBLE_USERNAME=<sensitive> --extra-vars ANSIBLE_SECRET=***** -e <sensitive>_ssh_private_key_file=/var/folders/tn/mrc12tzn5td09f0kccnjc4gm0000gn/T/<sensitive>-key3857321146 -i /var/folders/tn/mrc12tzn5td09f0kccnjc4gm0000gn/T/packer-provisioner-<sensitive>137085278 /Users/<sensitive>/Dropbox/Code/packer/packer-examples-for-vsphere/<sensitive>/main.yml
    vsphere-iso.linux-debian:
    vsphere-iso.linux-debian: PLAY [all] *********************************************************************
==> vsphere-iso.linux-debian: failed to handshake
    vsphere-iso.linux-debian:
    vsphere-iso.linux-debian: TASK [Gathering Facts] *********************************************************
    vsphere-iso.linux-debian: fatal: [default]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Unable to negotiate with 127.0.0.1 port 60037: no matching host key type found. Their offer: ssh-rsa", "unreachable": true}
    vsphere-iso.linux-debian:
    vsphere-iso.linux-debian: PLAY RECAP *********************************************************************
    vsphere-iso.linux-debian: default                    : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0
    vsphere-iso.linux-debian:
==> vsphere-iso.linux-debian: Provisioning step had errors: Running the cleanup provisioner, if present...
==> vsphere-iso.linux-debian: Power off VM...
==> vsphere-iso.linux-debian: Destroying VM...
Build 'vsphere-iso.linux-debian' errored after 5 minutes 56 seconds: Error executing Ansible: Non-zero exit status: exit status 4

==> Wait completed after 5 minutes 56 seconds

==> Some builds didn't complete successfully and had errors:
--> vsphere-iso.linux-debian: Error executing Ansible: Non-zero exit status: exit status 4

==> Builds finished but no artifacts were created.
CONFIRM: Build a Ubuntu Server 22.04 LTS (cloud-init) Template for VMware vSphere?

Continue? (y/n)
y
Building a Ubuntu Server 22.04 LTS (cloud-init) Template for VMware vSphere...
Initializing HashiCorp Packer and required plugins...
Starting the build....
vsphere-iso.linux-ubuntu: output will be in this color.

==> vsphere-iso.linux-ubuntu: Publishing build details for vsphere-iso.linux-ubuntu to the HCP Packer registry
==> vsphere-iso.linux-ubuntu: Creating VM...
==> vsphere-iso.linux-ubuntu: Customizing hardware...
==> vsphere-iso.linux-ubuntu: Adding SATA controller...
==> vsphere-iso.linux-ubuntu: Mounting ISO images...
==> vsphere-iso.linux-ubuntu: Adding configuration parameters...
==> vsphere-iso.linux-ubuntu: Starting HTTP server on port 8023
==> vsphere-iso.linux-ubuntu: Set boot order...
==> vsphere-iso.linux-ubuntu: Power on VM...
==> vsphere-iso.linux-ubuntu: Waiting 5s for boot...
==> vsphere-iso.linux-ubuntu: HTTP server is working at http://10.0.30.10:8023/
==> vsphere-iso.linux-ubuntu: Typing boot command...
==> vsphere-iso.linux-ubuntu: Waiting for IP...
==> vsphere-iso.linux-ubuntu: IP address: 10.0.30.151
==> vsphere-iso.linux-ubuntu: Using SSH communicator to connect: 10.0.30.151
==> vsphere-iso.linux-ubuntu: Waiting for SSH to become available...
==> vsphere-iso.linux-ubuntu: Connected to SSH!
==> vsphere-iso.linux-ubuntu: Provisioning with Ansible...
    vsphere-iso.linux-ubuntu: Setting up proxy adapter for Ansible....
==> vsphere-iso.linux-ubuntu: Executing Ansible: <sensitive>-playbook -e packer_build_name="linux-ubuntu" -e packer_builder_type=vsphere-iso -e packer_http_addr=10.0.30.10:8023 --ssh-extra-args '-o IdentitiesOnly=yes' --extra-vars display_skipped_hosts=false --extra-vars BUILD_USERNAME=<sensitive> --extra-vars BUILD_SECRET=***** --extra-vars ANSIBLE_USERNAME=<sensitive> --extra-vars ANSIBLE_SECRET=***** -e <sensitive>_ssh_private_key_file=/var/folders/tn/mrc12tzn5td09f0kccnjc4gm0000gn/T/<sensitive>-key1156406299 -i /var/folders/tn/mrc12tzn5td09f0kccnjc4gm0000gn/T/packer-provisioner-<sensitive>2952056012 /Users/<sensitive>/Dropbox/Code/packer/packer-examples-for-vsphere/<sensitive>/main.yml
    vsphere-iso.linux-ubuntu:
    vsphere-iso.linux-ubuntu: PLAY [all] *********************************************************************
==> vsphere-iso.linux-ubuntu: failed to handshake
    vsphere-iso.linux-ubuntu:
    vsphere-iso.linux-ubuntu: TASK [Gathering Facts] *********************************************************
    vsphere-iso.linux-ubuntu: fatal: [default]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Unable to negotiate with 127.0.0.1 port 60059: no matching host key type found. Their offer: ssh-rsa", "unreachable": true}
    vsphere-iso.linux-ubuntu:
    vsphere-iso.linux-ubuntu: PLAY RECAP *********************************************************************
    vsphere-iso.linux-ubuntu: default                    : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0
    vsphere-iso.linux-ubuntu:
==> vsphere-iso.linux-ubuntu: Provisioning step had errors: Running the cleanup provisioner, if present...
==> vsphere-iso.linux-ubuntu: Power off VM...
==> vsphere-iso.linux-ubuntu: Destroying VM...
Build 'vsphere-iso.linux-ubuntu' errored after 6 minutes 52 seconds: Error executing Ansible: Non-zero exit status: exit status 4

==> Wait completed after 6 minutes 52 seconds

==> Some builds didn't complete successfully and had errors:
--> vsphere-iso.linux-ubuntu: Error executing Ansible: Non-zero exit status: exit status 4

==> Builds finished but no artifacts were created.

@tenthirtyam
Copy link
Contributor

@dhoppe - yes, it's the second plugin shown below:

packer plugins installed
/Users/tenthirtyam/.packer.d/plugins/github.com/rgl/windows-update/packer-plugin-windows-update_v0.14.1_x5.0_darwin_amd64
/Users/tenthirtyam/.packer.d/plugins/github.com/ethanmdavidson/git/packer-plugin-git_v0.3.2_x5.0_darwin_amd64
/Users/tenthirtyam/.packer.d/plugins/github.com/hashicorp/virtualbox/packer-plugin-virtualbox_v1.0.4_x5.0_darwin_amd64
/Users/tenthirtyam/.packer.d/plugins/github.com/hashicorp/vmware/packer-plugin-vmware_v1.0.7_x5.0_darwin_amd64
/Users/tenthirtyam/.packer.d/plugins/github.com/hashicorp/vsphere/packer-plugin-vsphere_v1.1.0_x5.0_darwin_amd64

@tenthirtyam tenthirtyam added size/m Medium and removed size/s Small labels Nov 29, 2022
@tenthirtyam
Copy link
Contributor

tenthirtyam commented Nov 29, 2022

The issue above was related to simply downloading the source and attempting to run as-provided.

The Configuration section of the README.md will need to be updated to reflect the use of:

Cloning from main:

git clone https://github.com/vmware-samples/packer-examples-for-vsphere.git
cd packer-examples-for-vsphere
git checkout -b foo
git tag bar

Download and Extract Release Archive:

cd packer-examples-for-vsphere
git init -b main
git add .
git commit -m init
git checkout -b foo
git tag bar

Copy link
Contributor

@tenthirtyam tenthirtyam left a comment

Choose a reason for hiding this comment

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

Please update the README.md based on #385 (comment).

@dhoppe
Copy link
Contributor Author

dhoppe commented Nov 29, 2022

Please update the README.md based on #385 (comment).

I just updated the documentation and found a logical error. I have only determined the last available tag, but not the one actually used.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@dhoppe dhoppe force-pushed the build_version branch 3 times, most recently from e09b0f8 to 1cae0ab Compare November 30, 2022 00:02
@tenthirtyam
Copy link
Contributor

tenthirtyam commented Nov 30, 2022

I just updated the documentation and found a logical error. I have only determined the last available tag, but not the one actually used.

I actually noticed the same with testing with multiple tags - just let me know when you're all set. This is a very nice enhancement - thank you!

@dhoppe
Copy link
Contributor Author

dhoppe commented Nov 30, 2022

I just updated the documentation and found a logical error. I have only determined the last available tag, but not the one actually used.

I actually noticed the same with testing with multiple tags - just let me know when you're all set. This is a very nice enhancement - thank you!

I think this pull request is ready to be merged. I already fixed that issue because I do not need to fetch the tags. The data source data.git-repository.cwd.head always points to the currently checked out branch.

PS: Time to go to bed. It is already late in Germany. ;)

@tenthirtyam
Copy link
Contributor

I'll review it tomorrow - thanks again for the enhancement suggestion!

Updates `README.md`:

- Adds link to `packer-plugin-git` as well as version used.
- Updates the order for the Configuration section.

Signed-off-by: Ryan Johnson <johnsonryan@vmware.com>
README.md Outdated Show resolved Hide resolved
Updates `README.md` to remove duplicate warning in the configuration section.

Signed-off-by: Ryan Johnson <johnsonryan@vmware.com>
Copy link
Contributor

@tenthirtyam tenthirtyam left a comment

Choose a reason for hiding this comment

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

Reviewed and testing the implementation and documentation updates - LGTM! 🚀

README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@tenthirtyam tenthirtyam merged commit 0a49cbc into vmware-samples:main Nov 30, 2022
@dhoppe dhoppe deleted the build_version branch November 30, 2022 19:57
tenthirtyam added a commit that referenced this pull request Nov 30, 2022
Updates `CHANGELOG.md` to include enhancements included in #385.

Signed-off-by: Ryan Johnson <johnsonryan@vmware.com>
@tenthirtyam tenthirtyam mentioned this pull request Nov 30, 2022
10 tasks
tenthirtyam added a commit that referenced this pull request Nov 30, 2022
Updates `CHANGELOG.md` to include enhancements included in #385.

Signed-off-by: Ryan Johnson <johnsonryan@vmware.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 Dec 31, 2022
@tenthirtyam tenthirtyam removed this from the Backlog milestone Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for using the git branch and tag for versioning
2 participants