diff --git a/ci/README.md b/ci/README.md index 638ff4a55..f978fc2c1 100644 --- a/ci/README.md +++ b/ci/README.md @@ -163,12 +163,12 @@ The build_sdcard.sh is downloaded from the source branch and built with the opti The github workflow is running the job in an ubuntu-22.04 image. The amd64 image is built with running a qemu VM -* installs the base OS (Debian 11.5) +* installs the base OS (Debian) * connects with ssh and runs the scripts including the build_sdcard.sh -The arm64-rpi image genenaration runs in Docker in github actions and without Docker locally. -* the base image (RasberryOS) is started in the qemu VM -* packer runs the build_sdcard.sh directly in the VM +The arm64-rpi image generation runs in Docker in github actions and without Docker locally. +* the base image (RaspberryOS) is started in the qemu VM +* Packer runs the build_sdcard.sh directly in the VM After the image is built (and there is no exit with errors) the next steps are: * compute checksum of the qemu/raw image diff --git a/ci/amd64/packer.build.amd64-debian.sh b/ci/amd64/packer.build.amd64-debian.sh index 37d2868c1..6118ed5e3 100644 --- a/ci/amd64/packer.build.amd64-debian.sh +++ b/ci/amd64/packer.build.amd64-debian.sh @@ -11,27 +11,11 @@ sudo apt-get install -y packer echo -e "\nInstalling qemu..." sudo apt-get install -y qemu-system -if [ $# -gt 0 ]; then - pack=$1 -else - pack=lean -fi - -if [ $# -gt 1 ]; then - github_user=$2 -else - github_user=rootzoll -fi - -if [ $# -gt 2 ]; then - branch=$3 -else - branch=dev -fi +# set vars +source ../set_variables.sh +set_variables "$@" # Build the image echo -e "\nBuilding image..." cd debian -PACKER_LOG=1 packer build \ - --var pack=${pack} --var github_user=${github_user} --var branch=${branch} \ - -only=qemu amd64-debian.json +PACKER_LOG=1 packer build ${vars} -only=qemu amd64-debian.json diff --git a/ci/arm64-rpi/packer.build.arm64-rpi.local.sh b/ci/arm64-rpi/packer.build.arm64-rpi.local.sh index f64659773..20c2477a8 100644 --- a/ci/arm64-rpi/packer.build.arm64-rpi.local.sh +++ b/ci/arm64-rpi/packer.build.arm64-rpi.local.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -echo "\n# Install dependencies with apt" +echo -e "\n# Install dependencies with apt" if [ "$(uname -n)" = "ubuntu" ]; then sudo add-apt-repository -y universe fi @@ -36,44 +36,33 @@ fi echo -e "\n# Install Go" export PATH=$PATH:/usr/local/go/bin -if ! go version 2>/dev/null | grep "1.18.9"; then - wget --progress=bar:force https://go.dev/dl/go1.18.9.linux-amd64.tar.gz - echo "015692d2a48e3496f1da3328cf33337c727c595011883f6fc74f9b5a9c86ffa8 go1.18.9.linux-amd64.tar.gz" | sha256sum -c - || exit 1 - sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.18.9.linux-amd64.tar.gz - sudo rm -rf go1.18.9.linux-amd64.tar.gz +# https://go.dev/dl/ +GOVERSION="1.20.6" +GOHASH="b945ae2bb5db01a0fb4786afde64e6fbab50b67f6fa0eb6cfa4924f16a7ff1eb" +if ! go version 2>/dev/null | grep "${GOVERSION}"; then + wget --progress=bar:force https://go.dev/dl/go${GOVERSION}.linux-amd64.tar.gz + echo "${GOHASH} go${GOVERSION}.linux-amd64.tar.gz" | sha256sum -c - || exit 1 + sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go${GOVERSION}.linux-amd64.tar.gz + sudo rm -rf go${GOVERSION}.linux-amd64.tar.gz else - echo "# Go 1.18.9 is installed" + echo "# Go ${GOVERSION} is installed" fi echo -e "\n# Download the packer-builder-arm plugin" git clone https://github.com/mkaczanowski/packer-builder-arm cd packer-builder-arm -# pin to commit hash https://github.com/mkaczanowski/packer-builder-arm/commits/master -git reset --hard 6636c687ece53f7d1f5f2b35aa41f0e6132949c4 +# https://github.com/mkaczanowski/packer-builder-arm/releases +git reset --hard "v1.0.7" echo -e "\n# Build the packer-builder-arm plugin" go mod download go build || exit 1 -if [ $# -gt 0 ]; then - pack=$1 -else - pack=lean -fi - -if [ $# -gt 1 ]; then - github_user=$2 -else - github_user=rootzoll -fi - -if [ $# -gt 2 ]; then - branch=$3 -else - branch=dev -fi +# set vars +source ../set_variables.sh +set_variables "$@" cp ../arm64-rpi.pkr.hcl ./ cp ../raspiblitz.sh ./ echo -e "\n# Build the image" -packer build -var github_user=${github_user} -var branch=${branch} -var pack=${pack} arm64-rpi.pkr.hcl +packer build ${vars} arm64-rpi.pkr.hcl diff --git a/ci/arm64-rpi/packer.build.arm64-rpi.sh b/ci/arm64-rpi/packer.build.arm64-rpi.sh index c627a0ca3..8e13bc148 100644 --- a/ci/arm64-rpi/packer.build.arm64-rpi.sh +++ b/ci/arm64-rpi/packer.build.arm64-rpi.sh @@ -1,53 +1,12 @@ #!/bin/bash -e -if [ $# -gt 0 ]; then - pack=$1 -fi - -if [ $# -gt 1 ]; then - github_user=$2 -fi - -if [ $# -gt 2 ]; then - branch=$3 -fi - -if [ $# -gt 4 ]; then - image_link="$4" - image_checksum="$5" -fi - -# Initialize the variables string -vars="" - -# Add the pack variable if it is defined -if [ -n "${pack}" ]; then - vars="$vars -var pack=${pack}" -fi - -# Add the github_user variable if it is defined -if [ -n "${github_user}" ]; then - vars="$vars -var github_user=${github_user}" -fi - -# Add the branch variable if it is defined -if [ -n "${branch}" ]; then - vars="$vars -var branch=${branch}" -fi - -# Add the image_link variable if it is defined -if [ -n "${image_link}" ]; then - vars="$vars -var image_link=${image_link}" -fi - -# Add the image_checksum variable if it is defined -if [ -n "${image_checksum}" ]; then - vars="$vars -var image_checksum=${image_checksum}" -fi +# set vars +source ../set_variables.sh +set_variables "$@" # Build the image in docker echo -e "\nBuild Packer image..." # from https://hub.docker.com/r/mkaczanowski/packer-builder-arm/tags docker run --rm --privileged -v /dev:/dev -v ${PWD}:/build \ - mkaczanowski/packer-builder-arm:1.0.6@sha256:ca758415f498e6d4a1d7e82380d6f166d97262cb44af624ff586e6a6c96ad795 \ + mkaczanowski/packer-builder-arm@sha256:0ff8ce0cf33e37be6c351c8bcb2643835c7f3525b7f591808b91c04238d45695 \ build ${vars} arm64-rpi.pkr.hcl diff --git a/ci/set_variables.sh b/ci/set_variables.sh new file mode 100644 index 000000000..3e9e42372 --- /dev/null +++ b/ci/set_variables.sh @@ -0,0 +1,46 @@ +function set_variables() { + if [ $# -gt 0 ]; then + pack=$1 + fi + + if [ $# -gt 1 ]; then + github_user=$2 + fi + + if [ $# -gt 2 ]; then + branch=$3 + fi + + if [ $# -gt 4 ]; then + image_link="$4" + image_checksum="$5" + fi + + # Initialize the variables string + vars="" + + # Add the pack variable if it is defined + if [ -n "${pack}" ]; then + vars="$vars -var pack=${pack}" + fi + + # Add the github_user variable if it is defined + if [ -n "${github_user}" ]; then + vars="$vars -var github_user=${github_user}" + fi + + # Add the branch variable if it is defined + if [ -n "${branch}" ]; then + vars="$vars -var branch=${branch}" + fi + + # Add the image_link variable if it is defined + if [ -n "${image_link}" ]; then + vars="$vars -var image_link=${image_link}" + fi + + # Add the image_checksum variable if it is defined + if [ -n "${image_checksum}" ]; then + vars="$vars -var image_checksum=${image_checksum}" + fi +}