Packer Errors on Attempt to Run A Script

Published

I have a Packer build that is using GitHub actions.
The build needs to run a bash script that dockerizes the applications.
I know it’s not best practice, but I have to ensure that the script can be used during the Packer build.

I get the following error:

Error: /15 04:59:23 packer-plugin-amazon_v1.0.6_x5.0_linux_amd64 plugin: 2022/01/15 04:59:23 [ERROR] Remote command exited with '1': chmod +x /tmp/script_1771.sh; ARTIFACT_TOKEN='<sensitive>' ARTIFACT_USER='octane-writer' BUILD_BRANCH='caching' BUILD_NUMBER='99' CI_ID='<some_url>' PACKER_BUILDER_TYPE='amazon-ebs' PACKER_BUILD_NAME='ubuntu' USE_PICSS='0' VAULT_APPROLE_IDS='<sensitive>'  /tmp/script_1771.sh

The remote script looks like this as per the inline provisioner based off what’s in the repository (WHICH I CANNOT SHARE BECAUSE IT’S AN INTERNAL REPO)!!! I have tried multiple ways in attempting to change the provisioner shell block, but have gotten nowhere.

The following was an attempt to see about passing it off to use the root user, but that fails as well:

Passing off commands to use the root user:

  provisioner "shell" {
    environment_vars = [
      "USE_PICSS=${var.USE_PICSS}",
      "ARTIFACT_USER=${var.ARTIFACT_USER}",
      "ARTIFACT_TOKEN=${var.ARTIFACT_TOKEN}",
      "VAULT_APPROLE_IDS=${var.VAULT_APPROLE_IDS}",
      "BUILD_NUMBER=${var.BUILD_NUMBER}",
      "BUILD_BRANCH=${var.BUILD_BRANCH}",
      "CI_ID=${var.CI_CD}"
    ]
    inline = [
      "echo '======================================'",
      "echo '         checking system+config       '",
      "echo '======================================'",
      "whoami",
      "sudo su -c 'cat /etc/shadow' -s /bin/sh root",
      "sudo su -c 'export USE_PICSS=${var.USE_PICSS}' -s /bin/sh root",
      "sudo su -c 'export ARTIFACT_USER=${var.ARTIFACT_USER}' -s /bin/sh root",
      "sudo su -c 'export ARTIFACT_TOKEN=${var.ARTIFACT_TOKEN}' -s /bin/sh root",
      "sudo su -c 'echo $ARTIFACT_USER",
      "sudo su -c 'echo $ARTIFACT_TOKEN",
      "echo '======================================'",
      "echo '           checking env               '",
      "echo '======================================'",
      "sudo su -c 'printenv' -s /bin/sh root",
      "echo '======================================'",
      "echo '           packer app                 '",
      "echo '======================================'",
      "cd /tmp/build-system/",
      "sed '2 i set -e' dockerized.sh",
      "sudo su -c  './dockerized.sh make r510_octane_defconfig' -s /bin/sh root",
      "sudo su -c  './dockerized.sh make -C output/r510_octane/ all' -s /bin/sh root"
    ]
  }

Here is the main one and what we are trying to get working:

  provisioner "shell" {
    environment_vars = [
      "USE_PICSS=${var.USE_PICSS}",
      "ARTIFACT_USER=${var.ARTIFACT_USER}",
      "ARTIFACT_TOKEN=${var.ARTIFACT_TOKEN}",
      "VAULT_APPROLE_IDS=${var.VAULT_APPROLE_IDS}",
      "BUILD_NUMBER=${var.BUILD_NUMBER}",
      "BUILD_BRANCH=${var.BUILD_BRANCH}",
      "CI_ID=${var.CI_CD}"
    ]
    inline = [
      "whoami",
      "export USE_PICSS=${var.USE_PICSS}",
      "export ARTIFACT_USER=${var.ARTIFACT_USER}",
      "export ARTIFACT_TOKEN=${var.ARTIFACT_TOKEN}",
      "printenv",
      "cd /tmp/build-system/",
      "sed '2 i set -x' dockerized.sh",
      "./dockerized.sh make r510_octane_defconfig",
      "./dockerized.sh make -C output/r510_octane/ all"
    ]
  }

I would appreciate any insights, I did find this: https://www.packer.io/docs/provisioners/shell#sudo-example

Unfortunately, I am pretty new to Packer and am trying to see how I can resolve this issue. Any advice and or help would be greatly appreciated here.

Source: Docker Questions

Published
Categorised as docker, packer Tagged ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq