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

Help debugging issues #90

Merged
merged 11 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
46 changes: 30 additions & 16 deletions builder/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,36 @@ apt-get update && apt-get install -y packer
packer plugins install github.com/hashicorp/qemu
packer plugins install github.com/hashicorp/ansible

# do the build
if tools/build.sh "$IMAGE" >/var/log/image-build.log 2>&1; then
# compress the resulting image
QEMU_SOURCE_ID=$(hcl2tojson "$IMAGE" | jq -r '.source[0].qemu | keys[]')
VM_NAME=$(hcl2tojson "$IMAGE" | jq -r '.source[0].qemu.'"$QEMU_SOURCE_ID"'.vm_name')
QCOW_FILE="$VM_NAME.qcow2"
builder/refresh.sh vo.access.egi.eu "$(cat /var/tmp/egi/.refresh_token)" images
OS_TOKEN="$(yq -r '.clouds.images.auth.token' /etc/openstack/clouds.yaml)"
OUTPUT_DIR="$(dirname "$IMAGE")/output-$QEMU_SOURCE_ID"
cd "$OUTPUT_DIR"
qemu-img convert -O qcow2 -c "$VM_NAME" "$QCOW_FILE"
openstack --os-cloud images --os-token "$OS_TOKEN" \
object create egi_endorsed_vas "$QCOW_FILE"
ls -lh "$QCOW_FILE"
SHA="$(sha512sum -z "$QCOW_FILE" | cut -f1 -d" ")"
echo "SUCCESSFUL BUILD - $QCOW_FILE - $SHA" >>/var/log/image-build.log
QEMU_SOURCE_ID=$(hcl2tojson "$IMAGE" | jq -r '.source[0].qemu | keys[]')
VM_NAME=$(hcl2tojson "$IMAGE" \
| jq -r '.source[0].qemu.'"$QEMU_SOURCE_ID"'.vm_name')
QCOW_FILE="$VM_NAME.qcow2"

# Check if the image is already there
builder/refresh.sh vo.access.egi.eu "$(cat /var/tmp/egi/.refresh_token)" images
OS_TOKEN="$(yq -r '.clouds.images.auth.token' /etc/openstack/clouds.yaml)"
if openstack --os-cloud images --os-token "$OS_TOKEN" \
object show egi_endorsed_vas \
"$QCOW_FILE" > /dev/null ; then
# skip
echo "Skipped build as image is already uploaded" >>/var/log/image-build.log
enolfc marked this conversation as resolved.
Show resolved Hide resolved
else
if tools/build.sh "$IMAGE" >/var/log/image-build.log 2>&1; then
# compress the resulting image
QEMU_SOURCE_ID=$(hcl2tojson "$IMAGE" | jq -r '.source[0].qemu | keys[]')
VM_NAME=$(hcl2tojson "$IMAGE" | jq -r '.source[0].qemu.'"$QEMU_SOURCE_ID"'.vm_name')
QCOW_FILE="$VM_NAME.qcow2"
builder/refresh.sh vo.access.egi.eu "$(cat /var/tmp/egi/.refresh_token)" images
OS_TOKEN="$(yq -r '.clouds.images.auth.token' /etc/openstack/clouds.yaml)"
enolfc marked this conversation as resolved.
Show resolved Hide resolved
OUTPUT_DIR="$(dirname "$IMAGE")/output-$QEMU_SOURCE_ID"
cd "$OUTPUT_DIR"
qemu-img convert -O qcow2 -c "$VM_NAME" "$QCOW_FILE"
openstack --os-cloud images --os-token "$OS_TOKEN" \
object create egi_endorsed_vas "$QCOW_FILE"
ls -lh "$QCOW_FILE"
SHA="$(sha512sum -z "$QCOW_FILE" | cut -f1 -d" ")"
echo "SUCCESSFUL BUILD - $QCOW_FILE - $SHA" >>/var/log/image-build.log
fi
fi

echo "BUILD ENDED" >>/var/log/image-build.log
5 changes: 3 additions & 2 deletions builder/refresh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# 2 --> the refresh token
# 3 --> the list of clouds to update
#
# Will throw the OIDC TOKEN to output!
# Will throw the OIDC TOKEN to output if $GITHUB_ACTION is defined!

set -e

Expand All @@ -27,12 +27,13 @@ SCOPE="$SCOPE%20eduperson_entitlement:urn:mace:egi.eu:group:$VO:role=member#aai.
OIDC_TOKEN=$(curl -X POST "https://aai.egi.eu/auth/realms/egi/protocol/openid-connect/token" \
-d "grant_type=refresh_token&client_id=token-portal&scope=$SCOPE&refresh_token=$REFRESH_TOKEN" \
| jq -r ".access_token")
echo "::add-mask::$OIDC_TOKEN"
[ -n "$GITHUB_ACTION" ] && echo "::add-mask::$OIDC_TOKEN"
for cloud in "$@" ; do
SITE="$(yq -r ".clouds.$cloud.site" $CLOUDS_YAML)"
VO="$(yq -r ".clouds.$cloud.vo" $CLOUDS_YAML)"
OS_TOKEN="$(fedcloud openstack token issue --oidc-access-token "$OIDC_TOKEN" \
--site "$SITE" --vo "$VO" -j | jq -r '.[0].Result.id')"
[ -n "$GITHUB_ACTION" ] && echo "::add-mask::$OIDC_TOKEN"
echo "::add-mask::$OS_TOKEN"
yq -y -i '.clouds.'"$cloud"'.auth.token="'"$OS_TOKEN"'"' $CLOUDS_YAML
done
Expand Down
59 changes: 0 additions & 59 deletions ubuntu/datahub-jupyter-ubuntu-22.04.pkr.json

This file was deleted.

61 changes: 0 additions & 61 deletions ubuntu/docker-ubuntu-22.04.pkr.json

This file was deleted.

62 changes: 0 additions & 62 deletions ubuntu/small-ubuntu-20.04.pkr.json

This file was deleted.

62 changes: 0 additions & 62 deletions ubuntu/ubuntu-20.04.pkr.json

This file was deleted.

59 changes: 0 additions & 59 deletions ubuntu/ubuntu-22.04.pkr.json

This file was deleted.

2 changes: 1 addition & 1 deletion ubuntu/ubuntu-24.04.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ source "qemu" "ubuntu_24_04" {
"boot",
"<enter>"
]
boot_wait = "5s"
boot_wait = "6s"
disk_size = 8000
format = "qcow2"
headless = true
Expand Down
Loading
Loading