Skip to content

Commit

Permalink
pass GITHUB_ACTOR GITHUB_HEAD_REF to the build
Browse files Browse the repository at this point in the history
  • Loading branch information
openoms committed Dec 5, 2022
1 parent c0a6ea3 commit 7e1c757
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/amd64-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Run the build script
run: |
cd ci/amd64
bash packer.build.amd64.sh
bash packer.build.amd64.sh $GITHUB_ACTOR $GITHUB_HEAD_REF
- name: Compute checksum of the raw image
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/arm64-rpi-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Run the build script
run: |
cd ci/arm64-rpi
bash arm64-rpi.sh
bash arm64-rpi.sh $GITHUB_ACTOR $GITHUB_HEAD_REF
- name: Compute checksum of the raw image
run: |
Expand Down
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
SHELL = /bin/bash
GITHUB_USER = $(shell git remote -v | grep origin | head -1 | cut -d/ -f4)
CURRENT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)

amd64-image:
cd ci/amd64 && \
bash packer.build.amd64.sh
bash packer.build.amd64.sh $(GITHUB_USER) $(CURRENT_BRANCH)

cd builds/packer-debian-11.5-amd64-qemu && \
sha256sum debian-11.5-amd64.qcow2 > debian-11.5-amd64.qcow2.sha256
Expand All @@ -10,3 +14,17 @@ amd64-image:

cd builds/packer-debian-11.5-amd64-qemu && \
sha256sum debian-11.5-amd64.qcow2.gz > debian-11.5-amd64.qcow2.gz.sha256


arm64-rpi-image:
cd ci/arm64-rpi && \
bash arm64-rpi.sh $(GITHUB_USER) $(CURRENT_BRANCH)

cd ci/arm64-rpi/packer-builder-arm && \
sha256sum joininbox-arm64-rpi.img > joininbox-arm64-rpi.img.sha256

cd ci/arm64-rpi/packer-builder-arm && \
gzip -v9 joininbox-arm64-rpi.img

cd ci/arm64-rpi/packer-builder-arm && \
sha256sum joininbox-arm64-rpi.img.gz > joininbox-arm64-rpi.img.gz.sha256
4 changes: 3 additions & 1 deletion ci/amd64/debian/debian-11.5-amd64.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@
"HOME_DIR=/home/joinmarket",
"http_proxy={{user `http_proxy`}}",
"https_proxy={{user `https_proxy`}}",
"no_proxy={{user `no_proxy`}}"
"no_proxy={{user `no_proxy`}}",
"github_user={{user `github_user`}}",
"branch={{user `branch`}}"
],
"execute_command": "echo 'joininbox' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'",
"expect_disconnect": true,
Expand Down
3 changes: 0 additions & 3 deletions ci/amd64/debian/scripts/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ rm -rf /tmp/* /var/tmp/*
echo "force a new random seed to be generated"
rm -f /var/lib/systemd/random-seed

echo "delete the SSH keys (will be recreated on the first boot)"
rm /etc/ssh/ssh_host_*

echo "clear the history so our install isn't there"
rm -f /root/.wget-hsts
export HISTSIZE=0
6 changes: 4 additions & 2 deletions ci/amd64/debian/scripts/joininbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

echo 'Download the build_joininbox.sh script ...'
wget https://raw.githubusercontent.com/openoms/joininbox/master/build_joininbox.sh

echo 'Build Joininbox ...'
sudo bash build_joininbox.sh
echo 'Deleting SSH pub keys (will be recreated on the first boot) ...'
sudo bash build_joininbox.sh "${branch}" "${github_user}"

echo 'Delete SSH keys (will be recreated on the first boot)'
sudo rm /etc/ssh/ssh_host_*
echo 'OK'
16 changes: 15 additions & 1 deletion ci/amd64/packer.build.amd64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,21 @@ sudo apt-get install -y packer
echo -e "\nInstalling qemu..."
sudo apt-get install -y qemu-system

if [ $# -gt 0 ]; then
github_user=$1
else
github_user=openoms
fi

if [ $# -gt 1 ]; then
branch=$2
else
branch=master
fi

# Build the image
echo -e "\nBuilding image..."
cd debian
PACKER_LOG=1 packer build -only=qemu debian-11.5-amd64.json
PACKER_LOG=1 packer build \
-var github_user=${github_user} -var branch=${branch} \
-only=qemu debian-11.5-amd64.json
12 changes: 9 additions & 3 deletions ci/arm64-rpi/arm64-rpi.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
variable "branch" {}
variable "github_user" {}

source "arm" "joininbox-arm64-rpi" {
file_checksum_type = "sha256"
Expand Down Expand Up @@ -26,8 +28,8 @@ source "arm" "joininbox-arm64-rpi" {
image_path = "joininbox-arm64-rpi.img"
image_size = "8G"
image_type = "dos"
qemu_binary_destination_path = "/usr/bin/qemu-aarch64-static"
qemu_binary_source_path = "/usr/bin/qemu-aarch64-static"
qemu_binary_destination_path = "/usr/bin/qemu-arm-static"
qemu_binary_source_path = "/usr/bin/qemu-arm-static"
}

build {
Expand Down Expand Up @@ -56,14 +58,18 @@ build {
}

provisioner "shell" {
environment_vars = [
"github_user={{user `github_user`}}",
"branch={{user `branch`}}"
]
script = "build_joininbox.sh"
}

provisioner "shell" {
inline = [
"echo '# Deleting the SSH pub keys (will be recreate on the first boot) ...'",
"rm /etc/ssh/ssh_host_*",
"echo 'OK'",
"echo 'OK'"
]
}
}
27 changes: 21 additions & 6 deletions ci/arm64-rpi/arm64-rpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(l
sudo apt-get update -y && sudo apt-get install packer -y

echo -e "Installing Go..."
wget --progress=bar:force https://go.dev/dl/go1.18.4.linux-arm64.tar.gz
echo "35014d92b50d97da41dade965df7ebeb9a715da600206aa59ce1b2d05527421f go1.18.4.linux-arm64.tar.gz" | sha256sum -c -
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.18.4.linux-arm64.tar.gz
sudo rm -rf go1.18.4.linux-arm64.tar.gz
export PATH=$PATH:/usr/local/go/bin

wget --progress=bar:force https://go.dev/dl/go1.18.8.linux-amd64.tar.gz
echo "4d854c7bad52d53470cf32f1b287a5c0c441dc6b98306dea27358e099698142a go1.18.8.linux-amd64.tar.gz" | sha256sum -c -
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.18.8.linux-amd64.tar.gz
sudo rm -rf go1.18.8.linux-amd64.tar.gz


# Install Packer Arm Plugin
# clean for reruns
rm -rf packer-builder-arm
Expand All @@ -28,8 +30,21 @@ go build
cp ../arm64-rpi.pkr.hcl ./
cp ../../../build_joininbox.sh ./

if [ $# -gt 0 ]; then
github_user=$1
else
github_user=openoms
fi

if [ $# -gt 1 ]; then
branch=$2
else
branch=master
fi

# Build the image in docker
echo -e "\nBuilding packer image..."
docker run --rm --privileged -v /dev:/dev -v \
${PWD}:/build mkaczanowski/packer-builder-arm \
build arm64-rpi.pkr.hcl
${PWD}:/build mkaczanowski/packer-builder-arm build \
-var "github_user=${github_user}" -var "branch=${branch}" \
amd64-rpi.pkr.hcl

0 comments on commit 7e1c757

Please sign in to comment.