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

adding remote folder to shell provisioners scripts #1922

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion templates/al2023/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"provisioners": [
{
"type": "shell",
"remote_folder": "{{ user `remote_folder`}}",
Copy link
Member

@cartermckinnon cartermckinnon Aug 13, 2024

Choose a reason for hiding this comment

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

Does Packer leave behind all the scripts it uploads to the remote_folder? It'd be nice to clean them up if /home/ec2-user is going to be used as remote_folder

Copy link
Author

Choose a reason for hiding this comment

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

I basically replicated what we have on AL2
https://github.com/awslabs/amazon-eks-ami/blob/main/templates/al2/template.json
you can see remote_folder option is on all shell provisioners.
I will launch an instance using the generated AMI and check /home/ec2-user content to see if it was cleanup by packer.

Copy link
Author

Choose a reason for hiding this comment

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

I confirmed that /home/ec2-user/ is clean when connecting to the Instance using the generated AMI:


sh-5.2$ sudo su -
[root@ip-10-0-9-125 ~]# cd /home/ec2-user/
[root@ip-10-0-9-125 ec2-user]# ls -ltrh
total 0

"inline": [
"mkdir -p {{user `working_dir`}}/rootfs",
"mkdir -p {{user `working_dir`}}/shared",
Expand All @@ -139,6 +140,7 @@
},
{
"type": "shell",
"remote_folder": "{{ user `remote_folder`}}",
"inline": [
"sudo mkdir -p /etc/eks/log-collector-script/",
"sudo cp -v {{user `working_dir`}}/log-collector-script/eks-log-collector.sh /etc/eks/log-collector-script/"
Expand All @@ -151,12 +153,14 @@
},
{
"type": "shell",
"remote_folder": "{{ user `remote_folder`}}",
"inline": [
"sudo cp -rv {{user `working_dir`}}/rootfs/* /"
]
},
{
"type": "shell",
"remote_folder": "{{ user `remote_folder`}}",
"inline": [
"sudo chmod -R a+x {{user `working_dir`}}/shared/bin/",
"sudo cp -rv {{user `working_dir`}}/shared/bin/* /usr/bin/"
Expand Down Expand Up @@ -220,6 +224,7 @@
},
{
"type": "shell",
"remote_folder": "{{ user `remote_folder`}}",
"inline": [
"sudo rm -rf {{user `working_dir`}}"
]
Expand All @@ -242,7 +247,7 @@
"custom_data": {
"source_ami_name": "{{ build `SourceAMIName` }}",
"source_ami_id": "{{ build `SourceAMI` }}"
}
}
}
]
}