From 3cf112e8499efd012410a43dcd8875c0ca338e42 Mon Sep 17 00:00:00 2001 From: Vinicius Mignot Date: Mon, 28 Aug 2023 08:13:59 -0300 Subject: [PATCH] feat(build): create debug symbols package --- .github/matrix-full.yml | 16 ++++-- BUILD.bazel | 91 +++++++++++++++++++++++++++++++ build/BUILD.bazel | 25 ++++++++- build/package/nfpm-debuginfo.yaml | 43 +++++++++++++++ 4 files changed, 170 insertions(+), 5 deletions(-) create mode 100644 build/package/nfpm-debuginfo.yaml diff --git a/.github/matrix-full.yml b/.github/matrix-full.yml index b32ca5effd54..ffe98a948363 100644 --- a/.github/matrix-full.yml +++ b/.github/matrix-full.yml @@ -10,23 +10,27 @@ build-packages: - label: ubuntu-20.04 image: ubuntu:20.04 package: deb + bazel-args: --//:debug_symbols_package=true check-manifest-suite: ubuntu-20.04-amd64 - label: ubuntu-22.04 package: deb + bazel-args: --//:debug_symbols_package=true check-manifest-suite: ubuntu-22.04-amd64 - label: ubuntu-22.04-arm64 package: deb - bazel-args: --platforms=//:generic-crossbuild-aarch64 + bazel-args: --platforms=//:generic-crossbuild-aarch64 --//:debug_symbols_package=true check-manifest-suite: ubuntu-22.04-arm64 # Debian - label: debian-10 image: debian:10 package: deb + bazel-args: --//:debug_symbols_package=true check-manifest-suite: debian-10-amd64 - label: debian-11 image: debian:11 package: deb + bazel-args: --//:debug_symbols_package=true check-manifest-suite: debian-11-amd64 # RHEL @@ -34,22 +38,24 @@ build-packages: image: centos:7 package: rpm package-type: el7 - bazel-args: --//:wasmx_el7_workaround=true + bazel-args: --//:wasmx_el7_workaround=true --//:debug_symbols_package=true check-manifest-suite: el7-amd64 - label: rhel-8 image: rockylinux:8 package: rpm package-type: el8 + bazel-args: --//:debug_symbols_package=true check-manifest-suite: el8-amd64 - label: rhel-9 image: rockylinux:9 package: rpm package-type: el9 + bazel-args: --//:debug_symbols_package=true check-manifest-suite: el9-amd64 - label: rhel-9-arm64 package: rpm package-type: el9 - bazel-args: --platforms=//:rhel9-crossbuild-aarch64 + bazel-args: --platforms=//:rhel9-crossbuild-aarch64 --//:debug_symbols_package=true check-manifest-suite: el9-arm64 # Amazon Linux @@ -57,16 +63,18 @@ build-packages: image: amazonlinux:2 package: rpm package-type: aws2 + bazel-args: --//:debug_symbols_package=true check-manifest-suite: amazonlinux-2-amd64 - label: amazonlinux-2023 image: amazonlinux:2023 package: rpm package-type: aws2023 + bazel-args: --//:debug_symbols_package=true check-manifest-suite: amazonlinux-2023-amd64 - label: amazonlinux-2023-arm64 package: rpm package-type: aws2023 - bazel-args: --platforms=//:aws2023-crossbuild-aarch64 + bazel-args: --platforms=//:aws2023-crossbuild-aarch64 --//:debug_symbols_package=true check-manifest-suite: amazonlinux-2023-arm64 build-images: diff --git a/BUILD.bazel b/BUILD.bazel index 2ca22d6d1d52..3a8f94c18f8a 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -107,6 +107,83 @@ nfpm_pkg( visibility = ["//visibility:public"], ) +#### debug package + +nfpm_pkg( + name = "kong-debuginfo_deb", + config = "//build:package/nfpm-debuginfo.yaml", + env = nfpm_env, + packager = "deb", + pkg_name = "kong-debuginfo", + visibility = ["//visibility:public"], +) + +nfpm_pkg( + name = "kong-debuginfo_apk", + config = "//build:package/nfpm-debuginfo.yaml", + env = nfpm_env, + packager = "apk", + pkg_name = "kong-debuginfo", + visibility = ["//visibility:public"], +) + +nfpm_pkg( + name = "kong-debuginfo_el9", + config = "//build:package/nfpm-debuginfo.yaml", + env = nfpm_env, + packager = "rpm", + pkg_name = "kong-debuginfo.el9", + visibility = ["//visibility:public"], +) + +nfpm_pkg( + name = "kong-debuginfo_el8", + config = "//build:package/nfpm-debuginfo.yaml", + env = nfpm_env, + packager = "rpm", + pkg_name = "kong-debuginfo.el8", + visibility = ["//visibility:public"], +) + +nfpm_pkg( + name = "kong-debuginfo_el7", + config = "//build:package/nfpm-debuginfo.yaml", + env = nfpm_env, + extra_env = { + "RPM_EXTRA_DEPS": "hostname", + }, + packager = "rpm", + pkg_name = "kong-debuginfo.el7", + visibility = ["//visibility:public"], +) + +nfpm_pkg( + name = "kong-debuginfo_aws2", + config = "//build:package/nfpm-debuginfo.yaml", + env = nfpm_env, + extra_env = { + "RPM_EXTRA_DEPS": "/usr/sbin/useradd", + "RPM_EXTRA_DEPS_2": "/usr/sbin/groupadd", + }, + packager = "rpm", + pkg_name = "kong-debuginfo.aws2", + visibility = ["//visibility:public"], +) + +nfpm_pkg( + name = "kong-debuginfo_aws2023", + config = "//build:package/nfpm-debuginfo.yaml", + env = nfpm_env, + extra_env = { + "RPM_EXTRA_DEPS": "/usr/sbin/useradd", + "RPM_EXTRA_DEPS_2": "/usr/sbin/groupadd", + "RPM_EXTRA_DEPS_3": "libxcrypt-compat", + }, + packager = "rpm", + pkg_name = "kong-debuginfo.aws2023", + visibility = ["//visibility:public"], +) + ###### flags # --//:debug=true @@ -245,6 +322,20 @@ config_setting( visibility = ["//visibility:public"], ) +# --//:debug_symbols_package=false +bool_flag( + name = "debug_symbols_package", + build_setting_default = False, +) + +config_setting( + name = "debug_symbols_package_flag", + flag_values = { + ":debug_symbols_package": "true", + }, + visibility = ["//visibility:public"], +) + ##### constraints, platforms and config_settings for cross-compile constraint_setting(name = "cross_build_setting") diff --git a/build/BUILD.bazel b/build/BUILD.bazel index 72db0776b293..8c3cde102c25 100644 --- a/build/BUILD.bazel +++ b/build/BUILD.bazel @@ -4,6 +4,7 @@ load("//build:build_system.bzl", "kong_directory_genrule", "kong_rules_group", " exports_files([ "package/nfpm.yaml", + "package/nfpm-debuginfo.yaml", ]) lib_deps = [ @@ -82,6 +83,26 @@ link_modules_dir = select({ "//conditions:default": "", }) +##### debug symbols +create_symbols_objects = select({ + "@kong//:debug_symbols_package_flag": """ + if [[ "$OSTYPE" == "linux"* ]]; then + mkdir -p ${BUILD_DESTDIR}/debug/openresty/nginx/modules ${BUILD_DESTDIR}/debug/openresty/lualib + objcopy --only-keep-debug ${BUILD_DESTDIR}/openresty/nginx/modules/ngx_wasm_module.so \ + ${BUILD_DESTDIR}/debug/openresty/nginx/modules/ngx_wasm_module.so.dbg + objcopy --only-keep-debug ${BUILD_DESTDIR}/openresty/lualib/libatc_router.so \ + ${BUILD_DESTDIR}/debug/openresty/lualib/libatc_router.so.dbg + objcopy --strip-unneeded ${BUILD_DESTDIR}/openresty/nginx/modules/ngx_wasm_module.so + objcopy --strip-unneeded ${BUILD_DESTDIR}/openresty/lualib/libatc_router.so + objcopy --add-gnu-debuglink=${BUILD_DESTDIR}/debug/openresty/nginx/modules/ngx_wasm_module.so.dbg \ + ${BUILD_DESTDIR}/openresty/nginx/modules/ngx_wasm_module.so + objcopy --add-gnu-debuglink=${BUILD_DESTDIR}/debug/openresty/lualib/libatc_router.so.dbg \ + ${BUILD_DESTDIR}/openresty/lualib/libatc_router.so + fi +""", + "//conditions:default": "", +}) + kong_directory_genrule( name = "kong", srcs = [ @@ -145,10 +166,12 @@ kong_directory_genrule( ATC_ROUTER=${WORKSPACE_PATH}/$(location @atc_router) cp $ATC_ROUTER ${BUILD_DESTDIR}/openresty/lualib/. + chmod -R "+rw" ${BUILD_DESTDIR}/openresty/lualib cp -r $(locations @protoc//:all_srcs) ${BUILD_DESTDIR}/kong/. - """ + install_lib_deps_cmd + install_lualib_deps_cmd + install_webui_cmd + link_modules_dir + install_wasm_deps_cmd + """ + """ + install_lib_deps_cmd + install_lualib_deps_cmd + install_webui_cmd + + create_symbols_objects + link_modules_dir + install_wasm_deps_cmd + """ mkdir -p ${BUILD_DESTDIR}/etc/kong cp kong.conf.default ${BUILD_DESTDIR}/etc/kong/kong.conf.default diff --git a/build/package/nfpm-debuginfo.yaml b/build/package/nfpm-debuginfo.yaml new file mode 100644 index 000000000000..18c64fc36ec9 --- /dev/null +++ b/build/package/nfpm-debuginfo.yaml @@ -0,0 +1,43 @@ +name: "${KONG_NAME}-debuginfo" +arch: ${ARCH} +platform: "linux" +version: "${KONG_VERSION}" +section: "default" +priority: "extra" +provides: +- kong-debuginfo +maintainer: "Kong Inc. " +description: | + This package provides debug information for package kong. Kong is a distributed gateway for APIs and Microservices, focused on high performance and reliability. +vendor: "Kong Inc." +license: "Apache-2.0" +contents: +- src: nfpm-prefix/debug/openresty + dst: /usr/local/openresty +replaces: +- ${KONG_REPLACES_1} +- ${KONG_REPLACES_2} +conflicts: +- ${KONG_CONFLICTS_1} +- ${KONG_CONFLICTS_2} +overrides: + deb: + depends: + - kong + rpm: + depends: + - kong + # Workaround for https://github.com/goreleaser/nfpm/issues/589 + - ${RPM_EXTRA_DEPS} + - ${RPM_EXTRA_DEPS_2} + - ${RPM_EXTRA_DEPS_3} + apk: + depends: + - kong + +rpm: + signature: + # PGP secret key (can also be ASCII-armored), the passphrase is taken + # from the environment variable $NFPM_RPM_PASSPHRASE with a fallback + # to $NFPM_PASSPHRASE. + key_file: ${RPM_SIGNING_KEY_FILE}