尝试 运行 脚本时出现打包程序错误
Packer Errors on Attempt to Run A Script
我有一个使用 GitHub 操作的 Packer 版本。
构建需要 运行 一个 bash 对应用程序进行 docker 化的脚本。
我知道这不是最佳实践,但我必须确保在 Packer 构建期间可以使用该脚本。
我收到以下错误:
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
根据存储库中的内容,根据内联供应器,远程脚本看起来像这样(我不能共享它,因为它是一个内部回购)!!!我尝试了多种方法来尝试更改供应商 shell
块,但一无所获。
以下是试图将其传递给 root 用户的尝试,但也失败了:
假冒命令以使用 root 用户:
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"
]
}
这是主要内容,也是我们正在努力开展的工作:
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"
]
}
如果有任何见解,我将不胜感激,我确实找到了这个:https://www.packer.io/docs/provisioners/shell#sudo-example
不幸的是,我对 Packer 还很陌生,正在尝试了解如何解决此问题。任何建议和/或帮助将不胜感激。
所以我想通了,有效负载已交付,但 Packer 用户使用的是不同的 shell 并且脚本以特定代码退出并且无法正常工作。所以我定义了 valid_exit_codes
并在脚本前面用 bash
调用它们并且它起作用了:
provisioner "shell" {
valid_exit_codes = [
"0",
"1",
"2"
]
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",
"echo $SHELL",
"export USE_PICSS=${var.USE_PICSS}",
"export ARTIFACT_USER=${var.ARTIFACT_USER}",
"export ARTIFACT_TOKEN=${var.ARTIFACT_TOKEN}",
"printenv",
"cd /tmp/build-system/",
"pwd",
"ls -laH",
"sed '2 i set -x' dockerized.sh",
"bash ./dockerized.sh make r510_octane_defconfig",
"bash ./dockerized.sh make -C output/r510_octane/ all"
]
}
我有一个使用 GitHub 操作的 Packer 版本。 构建需要 运行 一个 bash 对应用程序进行 docker 化的脚本。 我知道这不是最佳实践,但我必须确保在 Packer 构建期间可以使用该脚本。
我收到以下错误:
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
根据存储库中的内容,根据内联供应器,远程脚本看起来像这样(我不能共享它,因为它是一个内部回购)!!!我尝试了多种方法来尝试更改供应商 shell
块,但一无所获。
以下是试图将其传递给 root 用户的尝试,但也失败了:
假冒命令以使用 root 用户:
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"
]
}
这是主要内容,也是我们正在努力开展的工作:
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"
]
}
如果有任何见解,我将不胜感激,我确实找到了这个:https://www.packer.io/docs/provisioners/shell#sudo-example
不幸的是,我对 Packer 还很陌生,正在尝试了解如何解决此问题。任何建议和/或帮助将不胜感激。
所以我想通了,有效负载已交付,但 Packer 用户使用的是不同的 shell 并且脚本以特定代码退出并且无法正常工作。所以我定义了 valid_exit_codes
并在脚本前面用 bash
调用它们并且它起作用了:
provisioner "shell" {
valid_exit_codes = [
"0",
"1",
"2"
]
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",
"echo $SHELL",
"export USE_PICSS=${var.USE_PICSS}",
"export ARTIFACT_USER=${var.ARTIFACT_USER}",
"export ARTIFACT_TOKEN=${var.ARTIFACT_TOKEN}",
"printenv",
"cd /tmp/build-system/",
"pwd",
"ls -laH",
"sed '2 i set -x' dockerized.sh",
"bash ./dockerized.sh make r510_octane_defconfig",
"bash ./dockerized.sh make -C output/r510_octane/ all"
]
}