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

Ark doesn't use /var/cache/chef when leveraged from Chef Automate #201

Closed
qubitrenegade opened this issue Nov 23, 2017 · 2 comments
Closed
Labels
Stale This is marked as stale and will be closed shortly

Comments

@qubitrenegade
Copy link

qubitrenegade commented Nov 23, 2017

Cookbook version

Ark: 3.1.0

Chef-client version

13.4.19

Platform Details

CentOS 7.4, vsphere VMs. Basically 3 VMs built from same 7.4 template, one runs Automate software, other two are "build nodes". The build nodes then use ark to download/"install" (it's go, can you really "install" it?) the terraform package, and build VMs as described by the build cookbook.

Scenario:

Download "package" to consistent location when used in Automate context. Or at very minimum, don't download package on EVERY phase when installed from "default" cookbook.

I can see a scenario where in say the deploy phase we need to install phase specific tools as a non root user. Install pyenv, specific version of python, and some modules for the dbuild user, then execute some commands as dbuild against the build using ...::shell::out

Or, as non root user, install inspec, run inspec against specific nodes. You might want to install "newest" inspec on each run. (or whatever the newest is available from your repo)

Steps to Reproduce:

This is my .delivery/build_cookbook/recipes/default.rb

tf_url = 'https://releases.hashicorp.com/terraform/0.11.0/terraform_0.11.0_linux_amd64.zip'
tf_version = '0.11.0'
tf_checksum = '402b4333792967986383670134bb52a8948115f83ab6bda35f57fa2c3c9e9279'

ark 'terraform' do
  url tf_url
  version tf_version
  checksum tf_checksum
  has_binaries ['terraform']
  append_env_path false
  strip_components 0
  action :install
end

run any phase of automate. If you run Verify, and have just one build node, you'll have terraform downloaded 3 times.

/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/{unit,lint,syntax}/cache/terraform-0.11.0.zip

(just to be clear that's:

/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/unit/cache/terraform-0.11.0.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/terraform-0.11.0.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/syntax/cache/terraform-0.11.0.zip

Expected Result:

terraform binary downloaded to /var/cache/chef regardless of phase of automate (or not downloaded every phase of automate if called from default.rb). Terraform unpacked to /usr/local/terraform-#{version} and linked to /usr/local/terraform

Actual Result:

Package is downloaded to cache directory for each phase of the Automate pipeline process:

/var/opt/delivery/workspace/<automate server name>/<automate org name>/<workflow org name>/<cookbook name>/<target? branch>/<stage>/<phase>/cache/terraform-0.11.0.zip

/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/terraform-0.11.0.zip

This is the output of the Chef run from various automate phases:

##############################################
Acceptance

  * ark[terraform] action install
    * directory[/usr/local/terraform-0.11.0] action create (up to date)
    * remote_file[/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/acceptance/provision/cache/terraform-0.11.0.zip] action create
      - create new file /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/acceptance/provision/cache/terraform-0.11.0.zip
      - update content in file /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/acceptance/provision/cache/terraform-0.11.0.zip from none to 402b43
      (file sizes exceed 10000000 bytes, diff output suppressed)
    * execute[unpack /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/acceptance/provision/cache/terraform-0.11.0.zip] action nothing (skipped due to action :nothing)
    * execute[set owner on /usr/local/terraform-0.11.0] action nothing (skipped due to action :nothing)
    * link[/usr/local/bin/terraform] action create (up to date)
    * link[/usr/local/terraform] action create (up to date)
    * template[/etc/profile.d/terraform.sh] action create (skipped due to only_if)
    * ruby_block[adding '/usr/local/terraform-0.11.0/bin' to chef-client ENV['PATH']] action run (skipped due to only_if)
    * execute[unpack /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/acceptance/provision/cache/terraform-0.11.0.zip] action run
      - execute unzip -q -o /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/acceptance/provision/cache/terraform-0.11.0.zip -d /usr/local/terraform-0.11.0
    * execute[set owner on /usr/local/terraform-0.11.0] action run
      - execute chown -R root:0 /usr/local/terraform-0.11.0


##############################################
build lint

  * ark[terraform] action install
    * directory[/usr/local/terraform-0.11.0] action create (up to date)
    * remote_file[/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/lint/cache/terraform-0.11.0.zip] action create
      - create new file /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/lint/cache/terraform-0.11.0.zip
      - update content in file /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/lint/cache/terraform-0.11.0.zip from none to 402b43
      (file sizes exceed 10000000 bytes, diff output suppressed)
    * execute[unpack /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/lint/cache/terraform-0.11.0.zip] action nothing (skipped due to action :nothing)
    * execute[set owner on /usr/local/terraform-0.11.0] action nothing (skipped due to action :nothing)
    * link[/usr/local/bin/terraform] action create (up to date)
    * link[/usr/local/terraform] action create (up to date)
    * template[/etc/profile.d/terraform.sh] action create (skipped due to only_if)
    * ruby_block[adding '/usr/local/terraform-0.11.0/bin' to chef-client ENV['PATH']] action run (skipped due to only_if)
    * execute[unpack /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/lint/cache/terraform-0.11.0.zip] action run
      - execute unzip -q -o /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/lint/cache/terraform-0.11.0.zip -d /usr/local/terraform-0.11.0
    * execute[set owner on /usr/local/terraform-0.11.0] action run
      - execute chown -R root:0 /usr/local/terraform-0.11.0


################################################
build create


  * ark[terraform] action install
    * directory[/usr/local/terraform-0.11.0] action create (up to date)
    * remote_file[/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/quality/cache/terraform-0.11.0.zip] action create
      - create new file /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/quality/cache/terraform-0.11.0.zip
      - update content in file /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/quality/cache/terraform-0.11.0.zip from none to 402b43
      (file sizes exceed 10000000 bytes, diff output suppressed)
    * execute[unpack /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/quality/cache/terraform-0.11.0.zip] action nothing (skipped due to action :nothing)
    * execute[set owner on /usr/local/terraform-0.11.0] action nothing (skipped due to action :nothing)
    * link[/usr/local/bin/terraform] action create (up to date)
    * link[/usr/local/terraform] action create (up to date)
    * template[/etc/profile.d/terraform.sh] action create (skipped due to only_if)
    * ruby_block[adding '/usr/local/terraform-0.11.0/bin' to chef-client ENV['PATH']] action run (skipped due to only_if)
    * execute[unpack /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/quality/cache/terraform-0.11.0.zip] action run
      - execute unzip -q -o /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/quality/cache/terraform-0.11.0.zip -d /usr/local/terraform-0.11.0
    * execute[set owner on /usr/local/terraform-0.11.0] action run
      - execute chown -R root:0 /usr/local/terraform-0.11.0

####################################################
verify lint

  * ark[terraform] action install
    * directory[/usr/local/terraform-0.11.0] action create (up to date)
    * remote_file[/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/terraform-0.11.0.zip] action create
      - create new file /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/terraform-0.11.0.zip
      - update content in file /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/terraform-0.11.0.zip from none to 402b43
      (file sizes exceed 10000000 bytes, diff output suppressed)
    * execute[unpack /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/terraform-0.11.0.zip] action nothing (skipped due to action :nothing)
    * execute[set owner on /usr/local/terraform-0.11.0] action nothing (skipped due to action :nothing)
    * link[/usr/local/bin/terraform] action create (up to date)
    * link[/usr/local/terraform] action create (up to date)
    * template[/etc/profile.d/terraform.sh] action create (skipped due to only_if)
    * ruby_block[adding '/usr/local/terraform-0.11.0/bin' to chef-client ENV['PATH']] action run (skipped due to only_if)
    * execute[unpack /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/terraform-0.11.0.zip] action run
      - execute unzip -q -o /var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/terraform-0.11.0.zip -d /usr/local/terraform-0.11.0
    * execute[set owner on /usr/local/terraform-0.11.0] action run
      - execute chown -R root:0 /usr/local/terraform-0.11.0

Ruminations

ohai seems to return multiple cache dirs when run from an Automate context. Ark appears to pick the first one.

allowing the user to specify the download/cache dir seems to be the easiest...? I feel like there's pitfalls which is why Chef::Config[:cache_dir] was used in the first place?

maybe I'm overthinking it and there's an attribute that says "if this /usr/local/foo link exists don't download anything". I specifically just stopped writing this and re read the README and didn't see a way documented... admittedly haven't dug through the code to see if that exists.

I'm running a scaled down environment, but just one cookbook run through using this build cookbook,

[root@builder01enwdco ~]# find / -type f -name '*terraform*' | perl -pi -e 's/<sanitation regex>/<anonymization>/g' | grep -v '\.rb\|\.tfvars'
/usr/local/terraform-0.10.7/terraform
/usr/local/terraform-0.11.0/terraform
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/acceptance/provision/cache/terraform-0.10.7.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/acceptance/provision/cache/remote_file/https___releases_hashicorp_com_terraform_0_11_0_terraform_0_11_0-e959cc1c303a06103638cbce7c8d53e9.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/acceptance/provision/cache/remote_file/https___releases_hashicorp_com_terraform_0_10_7_terraform_0_10_7-5d5dc3ab791b5302bca76f410682b39b.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/acceptance/provision/cache/terraform-0.11.0.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/unit/cache/terraform-0.10.7.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/unit/cache/remote_file/https___releases_hashicorp_com_terraform_0_10_7_terraform_0_10_7-5d5dc3ab791b5302bca76f410682b39b.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/security/cache/terraform-0.10.7.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/security/cache/remote_file/https___releases_hashicorp_com_terraform_0_10_7_terraform_0_10_7-5d5dc3ab791b5302bca76f410682b39b.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/syntax/cache/terraform-0.10.7.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/syntax/cache/remote_file/https___releases_hashicorp_com_terraform_0_10_7_terraform_0_10_7-5d5dc3ab791b5302bca76f410682b39b.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/lint/cache/terraform-0.10.7.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/lint/cache/remote_file/https___releases_hashicorp_com_terraform_0_11_0_terraform_0_11_0-e959cc1c303a06103638cbce7c8d53e9.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/lint/cache/remote_file/https___releases_hashicorp_com_terraform_0_10_7_terraform_0_10_7-5d5dc3ab791b5302bca76f410682b39b.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/lint/cache/terraform-0.11.0.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/publish/cache/terraform-0.10.7.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/publish/cache/remote_file/https___releases_hashicorp_com_terraform_0_10_7_terraform_0_10_7-5d5dc3ab791b5302bca76f410682b39b.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/quality/cache/terraform-0.10.7.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/build/quality/cache/remote_file/https___releases_hashicorp_com_terraform_0_10_7_terraform_0_10_7-5d5dc3ab791b5302bca76f410682b39b.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/unit/cache/terraform-0.10.7.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/unit/cache/remote_file/https___releases_hashicorp_com_terraform_0_11_0_terraform_0_11_0-e959cc1c303a06103638cbce7c8d53e9.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/unit/cache/remote_file/https___releases_hashicorp_com_terraform_0_10_7_terraform_0_10_7-5d5dc3ab791b5302bca76f410682b39b.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/unit/cache/terraform-0.11.0.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/syntax/cache/terraform-0.10.7.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/syntax/cache/remote_file/https___releases_hashicorp_com_terraform_0_10_7_terraform_0_10_7-5d5dc3ab791b5302bca76f410682b39b.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/terraform-0.10.7.zip
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/remote_file/https___releases_hashicorp_com_terraform_0_11_0_terraform_0_11_0-e959cc1c303a06103638cbce7c8d53e9.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/remote_file/https___releases_hashicorp_com_terraform_0_10_7_terraform_0_10_7-5d5dc3ab791b5302bca76f410682b39b.json
/var/opt/delivery/workspace/automate-server.com/myorg/workflow-org/my_cookbook/master/verify/lint/cache/terraform-0.11.0.zip

OK OK, it was one cookbook, but I ran it through a few times... still, this is just one of the build nodes... the other build nodes look similar, but each of the .zip s is wasted bandwidth, disk space, etc...

what do they say? Four hardest things in computer programming, caching, naming things, and off by one errors?

Anyway, I think I see how to add a "path" option to the ark provider.... I'd be willing to do a PR if you don't think you'd go against the ethos of the Ark cookbook. Otherwise, if that's misguided, what would be a good way to solve the problem?

This could also totally just be a function of Automate... so solving it here in Ark is a band-aid fix for a broken bone... I'm ok with that. But would like to pursue fixing a fundamental issue with automate if so discovered.

We had issues with the Terraform cookbook. This stanza is essentially all we need (we don't use public URL, my tf_url is actually https://my.internal.repo/terraform/current.zip, but the above was written as steps to reproduce)

Thanks for reading all my ramblings!

  • Q
@github-actions
Copy link

github-actions bot commented Jan 8, 2021

Marking stale due to inactivity. Remove stale label or comment or this will be closed in 7 days. Alternatively drop by the #sous-chefs channel on the Chef Community Slack and we'll be happy to help! Thanks, Sous-Chefs.

@github-actions github-actions bot added the Stale This is marked as stale and will be closed shortly label Jan 8, 2021
@github-actions
Copy link

Closing due to inactivity. If this is still an issue please reopen or open another issue. Alternatively drop by the #sous-chefs channel on the Chef Community Slack and we'll be happy to help! Thanks, Sous-Chefs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale This is marked as stale and will be closed shortly
Projects
None yet
Development

No branches or pull requests

1 participant