Skip to content

Commit

Permalink
FEAT: Use packer copy file
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred78290 committed Oct 9, 2024
1 parent e9d3600 commit b97d113
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 29 deletions.
11 changes: 4 additions & 7 deletions bin/plateform/cloudstack/image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ function cloudmonkey() {
#===========================================================================================================================================
#
#===========================================================================================================================================
pushd ${CURDIR} > /dev/null
PREPARE_SCRIPT=${PWD}/prepare-image.sh
popd > /dev/null

if [ ${KUBERNETES_VERSION:0:1} != "v" ]; then
KUBERNETES_VERSION="v${KUBERNETES_VERSION}"
Expand Down Expand Up @@ -285,12 +288,6 @@ timezone: ${TZ}
package_update: false
package_upgrade: false
ssh_pwauth: true
write_files:
- encoding: gzip+base64
content: $(cat ${CURDIR}/prepare-image.sh | gzip -c9 | base64 -w 0)
owner: root:adm
path: /usr/local/bin/prepare-image.sh
permissions: '0755'
users:
- name: ${KUBERNETES_USER}
groups: users, admin
Expand Down Expand Up @@ -358,7 +355,7 @@ INIT_SCRIPT="/usr/local/bin/prepare-image.sh --container-runtime ${CONTAINER_ENG

pushd ${CACHE}/packer/
export PACKER_LOG=1
packer build -var INIT_SCRIPT="${INIT_SCRIPT}" template.json
packer build -var INIT_SCRIPT="${INIT_SCRIPT}" -var PREPARE_SCRIPT="${PREPARE_SCRIPT}" template.json
popd

echo_blue_bold "Created image ${TARGET_IMAGE} with kubernetes version ${KUBERNETES_VERSION}"
Expand Down
23 changes: 14 additions & 9 deletions bin/plateform/lxd/image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ while true ; do
esac
done

#===========================================================================================================================================
#
#===========================================================================================================================================
pushd ${CURDIR} > /dev/null
PREPARE_SCRIPT=${PWD}/prepare-image.sh
popd > /dev/null

if [ ${KUBERNETES_VERSION:0:1} != "v" ]; then
KUBERNETES_VERSION="v${KUBERNETES_VERSION}"
fi
Expand Down Expand Up @@ -165,12 +172,12 @@ config:
package_update: false
package_upgrade: false
ssh_pwauth: true
write_files:
- encoding: gzip+base64
content: $(cat ${CURDIR}/prepare-image.sh | gzip -c9 | base64 -w 0)
owner: root:adm
path: /usr/local/bin/prepare-image.sh
permissions: '0755'
# write_files:
# - encoding: gzip+base64
# content: $(cat ${CURDIR}/prepare-image.sh | gzip -c9 | base64 -w 0)
# owner: root:adm
# path: /usr/local/bin/prepare-image.sh
# permissions: '0755'
users:
- name: ${KUBERNETES_USER}
groups: users, admin
Expand All @@ -191,8 +198,6 @@ config:
preserve_sources_list: true
EOF

ls -l ${CACHE}/packer/profile/config.yaml

lxc profile edit ${LXD_REMOTE}${TARGET_IMAGE}-profile < ${CACHE}/packer/profile/config.yaml

if [ ${LXD_CONTAINER_TYPE} == "virtual-machine" ]; then
Expand Down Expand Up @@ -227,7 +232,7 @@ INIT_SCRIPT="/usr/local/bin/prepare-image.sh --container-runtime ${CONTAINER_ENG

pushd ${CACHE}/packer/
export PACKER_LOG=1
packer build -var INIT_SCRIPT="${INIT_SCRIPT}" template.json
packer build -var INIT_SCRIPT="${INIT_SCRIPT}" -var PREPARE_SCRIPT="${PREPARE_SCRIPT}" template.json
popd

echo_blue_bold "Created image ${TARGET_IMAGE} with kubernetes version ${KUBERNETES_VERSION}"
Expand Down
14 changes: 8 additions & 6 deletions bin/plateform/multipass/image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ while true ; do
esac
done

#===========================================================================================================================================
#
#===========================================================================================================================================
pushd ${CURDIR} > /dev/null
PREPARE_SCRIPT=${PWD}/prepare-image.sh
popd > /dev/null

if [ ${KUBERNETES_VERSION:0:1} != "v" ]; then
KUBERNETES_VERSION="v${KUBERNETES_VERSION}"
fi
Expand Down Expand Up @@ -114,12 +121,6 @@ timezone: ${TZ}
package_update: false
package_upgrade: false
ssh_pwauth: true
write_files:
- encoding: gzip+base64
content: $(cat ${CURDIR}/prepare-image.sh | gzip -c9 | base64 -w 0)
owner: root:adm
path: /usr/local/bin/prepare-image.sh
permissions: '0755'
users:
- name: ${KUBERNETES_USER}
groups: users, admin
Expand Down Expand Up @@ -193,6 +194,7 @@ packer build \
-var SSH_PRIVATE_KEY="${SSH_PRIVATE_KEY}" \
-var ISO_CHECKSUM="sha256:${ISO_CHECKSUM}" \
-var ISO_FILE="${ISO_FILE}" \
-var PREPARE_SCRIPT="${PREPARE_SCRIPT}" \
-var INIT_SCRIPT="${INIT_SCRIPT}" \
template.json

Expand Down
15 changes: 8 additions & 7 deletions bin/plateform/openstack/image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ while true ; do
esac
done

#===========================================================================================================================================
#
#===========================================================================================================================================
pushd ${CURDIR} > /dev/null
PREPARE_SCRIPT=${PWD}/prepare-image.sh
popd > /dev/null

if [ ${KUBERNETES_VERSION:0:1} != "v" ]; then
KUBERNETES_VERSION="v${KUBERNETES_VERSION}"
fi
Expand Down Expand Up @@ -139,12 +146,6 @@ timezone: ${TZ}
package_update: false
package_upgrade: false
ssh_pwauth: true
write_files:
- encoding: gzip+base64
content: $(cat ${CURDIR}/prepare-image.sh | gzip -c9 | base64 -w 0)
owner: root:adm
path: /usr/local/bin/prepare-image.sh
permissions: '0755'
users:
- name: ${KUBERNETES_USER}
groups: users, admin
Expand Down Expand Up @@ -206,7 +207,7 @@ INIT_SCRIPT="/usr/local/bin/prepare-image.sh --container-runtime ${CONTAINER_ENG

pushd ${CACHE}/packer/
export PACKER_LOG=1
packer build -var INIT_SCRIPT="${INIT_SCRIPT}" template.json
packer build -var INIT_SCRIPT="${INIT_SCRIPT}" -var PREPARE_SCRIPT="${PREPARE_SCRIPT}" template.json
popd

echo_blue_bold "Created image ${TARGET_IMAGE} with kubernetes version ${KUBERNETES_VERSION}"
Expand Down
14 changes: 14 additions & 0 deletions templates/packer/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@
}
],
"provisioners": [
{
"type": "file",
"source": "{{ user `PREPARE_SCRIPT` }}",
"destination": "/tmp/prepare-image.sh"
},
{
"type": "shell",
"execute_command": "sudo sh -xc '{{ .Vars }} {{ .Path }}'",
"inline": [
"cp /tmp/prepare-image.sh /usr/local/bin/prepare-image.sh",
"chown root:adm /usr/local/bin/prepare-image.sh",
"chmod +x /usr/local/bin/prepare-image.sh"
]
},
{
"type": "shell",
"execute_command": "sudo sh -xc '{{ .Vars }} {{ .Path }}'",
Expand Down

0 comments on commit b97d113

Please sign in to comment.