Skip to content

Commit

Permalink
Update from base builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Neilpang committed Sep 10, 2024
1 parent 6cb010b commit 78d348d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 40 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ jobs:
env:
SEC_VBOX : ${{ secrets.SEC_VBOX }}
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false
- uses: actions/checkout@v4
- name: Creating Web console
uses: vmactions/cf-tunnel@v0
Expand All @@ -50,7 +56,7 @@ jobs:
- name: Upload Release Asset
if: "contains(github.ref, 'refs/tags/')"
id: upload-release-asset
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
102 changes: 63 additions & 39 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex


_conf="$1"
Expand Down Expand Up @@ -120,22 +120,49 @@ else
exit 1
fi

$vmsh startVM $osname

sleep 2
echo "VM image size immediately after install:"
ls -lh ${osname}.qcow2


###############################################
start_and_wait() {
$vmsh startVM $osname
sleep 2
if [ -e "hooks/waitForLoginTag.sh" ]; then
echo "hooks/waitForLoginTag.sh"
cat "hooks/waitForLoginTag.sh"
. "hooks/waitForLoginTag.sh"
else
waitForText "$VM_LOGIN_TAG"
fi

if [ -e "hooks/waitForLoginTag.sh" ]; then
echo "hooks/waitForLoginTag.sh"
cat "hooks/waitForLoginTag.sh"
. "hooks/waitForLoginTag.sh"
else
waitForText "$VM_LOGIN_TAG"
fi
sleep 3
}

shutdown_and_wait() {
ssh $osname "$VM_SHUTDOWN_CMD"

sleep 30

if $vmsh isRunning $osname; then
if ! $vmsh shutdownVM $osname; then
echo "shutdown error"
fi
fi

sleep 3
while $vmsh isRunning $osname; do
sleep 5
done
}

restart_and_wait() {
shutdown_and_wait
start_and_wait
}

###############################################

start_and_wait

inputKeys "string root; enter; sleep 1;"
if [ "$VM_ROOT_PASSWORD" ]; then
Expand Down Expand Up @@ -184,25 +211,19 @@ echo " ServerAliveInterval 1" >>.ssh/config
EOF


###############################################################


if [ -e "hooks/postBuild.sh" ]; then
echo "hooks/postBuild.sh"
cat "hooks/postBuild.sh"
ssh $osname sh<"hooks/postBuild.sh"
fi


ssh $osname 'cat ~/.ssh/id_rsa.pub' >$osname-$VM_RELEASE-id_rsa.pub


if [ "$VM_PRE_INSTALL_PKGS" ]; then
echo "$VM_INSTALL_CMD $VM_PRE_INSTALL_PKGS"
ssh $osname sh <<<"$VM_INSTALL_CMD $VM_PRE_INSTALL_PKGS"
# Reboot here, possible there were system updates done that need
# a reboot to take effect before more operations can be done
restart_and_wait
fi

ssh $osname 'cat ~/.ssh/id_rsa.pub' >$osname-$VM_RELEASE-id_rsa.pub

#upload reboot.sh
if [ -e "hooks/reboot.sh" ]; then
Expand All @@ -220,7 +241,6 @@ END
EOF
fi


#set cronjob
ssh "$osname" sh <<EOF
chmod +x /reboot.sh
Expand All @@ -235,37 +255,41 @@ crontab -l
EOF


ssh $osname "$VM_SHUTDOWN_CMD"

sleep 30

###############################################################

if $vmsh isRunning $osname; then
if ! $vmsh shutdownVM $osname; then
echo "shutdown error"
fi
# Install any requested packages
if [ "$VM_PRE_INSTALL_PKGS" ]; then
echo "$VM_INSTALL_CMD $VM_PRE_INSTALL_PKGS"
ssh $osname sh <<<"$VM_INSTALL_CMD $VM_PRE_INSTALL_PKGS"
fi

while $vmsh isRunning $osname; do
sleep 5
done
if [ -e "hooks/finalize.sh" ]; then
echo "hooks/finalize.sh"
cat "hooks/finalize.sh"
ssh $osname sh<"hooks/finalize.sh"
fi

# Done!
shutdown_and_wait

##############################################################

if [ "$VM_ISO_LINK" ]; then
echo "Clean up ISO for more space"
sudo rm -f ${osname}.iso
fi

echo "contents of home directory:"
ls -lah

echo "free space:"
df -h

ova="$osname-$VM_RELEASE.qcow2"


echo "Exporting $ova"
$vmsh exportOVA $osname "$ova"

cp ~/.ssh/id_rsa $osname-$VM_RELEASE-host.id_rsa


echo "contents after export:"
ls -lah


Expand Down

0 comments on commit 78d348d

Please sign in to comment.