|
| 1 | +#!/usr/bin/env sh |
| 2 | +set -x |
| 3 | + |
| 4 | +## Create APK v3 package using abuild on Alpine 3.21+ |
| 5 | +## This produces packages compatible with apk-tools 3.x |
| 6 | + |
| 7 | +PACKAGE_ARCH="" |
| 8 | +if [ "${BUILD_ARCH}" = "x86-64" ]; then |
| 9 | + PACKAGE_ARCH="x86_64" |
| 10 | +elif [ "${BUILD_ARCH}" = "arm64" ]; then |
| 11 | + PACKAGE_ARCH="aarch64" |
| 12 | +else |
| 13 | + echo "Architecture not supported" |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +BUILD_TARGET="linuxmusl-${BUILD_ARCH}" |
| 18 | +BUILD_EXT_DIR=agent/native/_build/${BUILD_TARGET}-release/ext |
| 19 | +BUILD_LOADER_DIR=agent/native/_build/${BUILD_TARGET}-release/loader/code |
| 20 | + |
| 21 | +echo "Fetching agent libraries from ${BUILD_EXT_DIR}" |
| 22 | +echo "Package architecture ${PACKAGE_ARCH}" |
| 23 | + |
| 24 | +if [ ! -d "${BUILD_EXT_DIR}" ]; then |
| 25 | + echo "Agent libraries not built! Missing folder ${BUILD_EXT_DIR}" |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +touch build/elastic-apm.ini |
| 30 | + |
| 31 | +# Prepare extensions in temp dir |
| 32 | +EXTENSIONS_DIR=/tmp/extensions |
| 33 | +mkdir -p ${EXTENSIONS_DIR} |
| 34 | +cp ${BUILD_EXT_DIR}/*.so ${EXTENSIONS_DIR}/ |
| 35 | +cp ${BUILD_LOADER_DIR}/*.so ${EXTENSIONS_DIR}/ |
| 36 | + |
| 37 | +# Alpine pkgver does not allow dashes |
| 38 | +PKGVER=$(echo ${VERSION} | tr '-' '_') |
| 39 | + |
| 40 | +# Setup APKBUILD workspace |
| 41 | +WORK_DIR=/tmp/apk-v3-build |
| 42 | +ABUILD_DIR=${WORK_DIR}/${NAME} |
| 43 | +rm -rf ${WORK_DIR} |
| 44 | +mkdir -p ${ABUILD_DIR} |
| 45 | + |
| 46 | +# Post-install trigger |
| 47 | +cat > ${ABUILD_DIR}/${NAME}.post-install << 'EOF' |
| 48 | +#!/bin/sh |
| 49 | +/opt/elastic/apm-agent-php/bin/post-install.sh |
| 50 | +EOF |
| 51 | + |
| 52 | +# Pre-deinstall trigger |
| 53 | +cat > ${ABUILD_DIR}/${NAME}.pre-deinstall << 'EOF' |
| 54 | +#!/bin/sh |
| 55 | +/opt/elastic/apm-agent-php/bin/before-uninstall.sh |
| 56 | +EOF |
| 57 | + |
| 58 | +# Create APKBUILD |
| 59 | +cat > ${ABUILD_DIR}/APKBUILD << BUILDEOF |
| 60 | +# Maintainer: APM Team <info@elastic.co> |
| 61 | +pkgname=${NAME} |
| 62 | +pkgver=${PKGVER} |
| 63 | +pkgrel=0 |
| 64 | +pkgdesc="PHP agent for Elastic APM (Git Commit: ${GIT_SHA})" |
| 65 | +url="https://github.com/elastic/apm-agent-php" |
| 66 | +arch="all" |
| 67 | +license="Apache-2.0" |
| 68 | +depends="bash" |
| 69 | +install="\$pkgname.post-install \$pkgname.pre-deinstall" |
| 70 | +options="!check !fhs !strip !tracedeps" |
| 71 | +
|
| 72 | +package() { |
| 73 | + local dest="\$pkgdir${PHP_AGENT_DIR}" |
| 74 | +
|
| 75 | + install -d "\$dest/extensions" |
| 76 | + for f in ${EXTENSIONS_DIR}/*.so; do |
| 77 | + install -m755 "\$f" "\$dest/extensions/" |
| 78 | + done |
| 79 | +
|
| 80 | + mkdir -p "\$dest/src" |
| 81 | + cp -r /app/agent/php/* "\$dest/src/" |
| 82 | +
|
| 83 | + install -d "\$dest/etc" |
| 84 | + install -m644 /app/build/elastic-apm.ini "\$dest/etc/" |
| 85 | + install -m644 /app/packaging/elastic-apm-custom-template.ini "\$dest/etc/elastic-apm-custom.ini" |
| 86 | +
|
| 87 | + install -d "\$dest/bin" |
| 88 | + install -m755 /app/packaging/post-install.sh "\$dest/bin/post-install.sh" |
| 89 | + install -m755 /app/packaging/before-uninstall.sh "\$dest/bin/before-uninstall.sh" |
| 90 | +
|
| 91 | + install -d "\$dest/docs" |
| 92 | + install -m644 /app/README.md "\$dest/docs/README.md" |
| 93 | +} |
| 94 | +BUILDEOF |
| 95 | + |
| 96 | +#print debug info |
| 97 | +echo "APKBUILD content:" |
| 98 | +cat ${ABUILD_DIR}/APKBUILD || true |
| 99 | + |
| 100 | + |
| 101 | +# Build as non-root user (abuild requirement) |
| 102 | +chown -R builder:builder ${WORK_DIR} ${EXTENSIONS_DIR} |
| 103 | +OUTPUT_DIR=${WORK_DIR}/output |
| 104 | +su builder -c "cd ${ABUILD_DIR} && abuild -F -d -P ${OUTPUT_DIR}" |
| 105 | + |
| 106 | +# Find the built package |
| 107 | +APK_FILE=$(find ${OUTPUT_DIR} -name "*.apk" ! -name "APKINDEX*" | head -1) |
| 108 | +if [ -z "${APK_FILE}" ]; then |
| 109 | + echo "ERROR: No APK file found in build output" |
| 110 | + ls -laR ${OUTPUT_DIR} || true |
| 111 | + exit 1 |
| 112 | +fi |
| 113 | + |
| 114 | +# Copy to output with architecture in filename |
| 115 | +NEW_NAME="${NAME}-${PKGVER}-r0.${PACKAGE_ARCH}.apk" |
| 116 | +mkdir -p ${OUTPUT} |
| 117 | +cp ${APK_FILE} ${OUTPUT}/${NEW_NAME} |
| 118 | + |
| 119 | +# Create sha512 checksum |
| 120 | +cd ${OUTPUT} |
| 121 | +sha512sum "${NEW_NAME}" > "${NEW_NAME}.sha512" |
| 122 | + |
| 123 | +echo "APK v3 package created: ${OUTPUT}/${NEW_NAME}" |
0 commit comments