From 8377f55a54c3136fb2c7bd841df0085c620c87c2 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 22 Jul 2020 16:01:25 +0100 Subject: [PATCH 1/5] packaging: debian package installation with post-install --- packaging/Makefile | 12 ++++--- packaging/post-install.sh | 51 +++++++++++++++++++++++++++++ packaging/test/ubuntu/Dockerfile | 2 +- packaging/test/ubuntu/entrypoint.sh | 12 +++---- 4 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 packaging/post-install.sh diff --git a/packaging/Makefile b/packaging/Makefile index 59cbde895..042532969 100644 --- a/packaging/Makefile +++ b/packaging/Makefile @@ -2,7 +2,7 @@ IMAGE:=php-packaging NAME:=apm-agent-php VERSION?=$(shell grep 'VERSION' ../src/ElasticApm/ElasticApm.php | cut -d= -f2 | tr -d " " | sed "s/'\(.*\)'.*/\1/g") OUTPUT:=build/packages - +PHP_AGENT_DIR:=/opt/elastic/apm-agent-php GIT_SHA ?= $(shell git rev-parse HEAD || echo "unknown") .PHONY: help @@ -32,10 +32,12 @@ create-%: build ## Create the specific package --description "PHP agent for Elastic APM\nGit Commit: ${GIT_SHA}" \ --package $(OUTPUT) \ --chdir /app \ - src/ext/modules/=/usr/share/php/extensions \ - README.md=/usr/share/doc/apm-agent-php/docs/README.md \ - src/ElasticApm=/usr/share/php/apm-agent-php \ - src/bootstrap_php_part.php=/usr/share/php/apm-agent-php/bootstrap_php_part.php + --after-install=packaging/post-install.sh \ + packaging/post-install.sh=$(PHP_AGENT_DIR)/bin/post-install.sh \ + src/ext/modules/=$(PHP_AGENT_DIR)/extensions \ + README.md=$(PHP_AGENT_DIR)/docs/README.md \ + src/ElasticApm=$(PHP_AGENT_DIR)/src \ + src/bootstrap_php_part.php=$(PHP_AGENT_DIR)/src/bootstrap_php_part.php @echo 'Creating sha512sum ...' @BINARY=$$(ls -1 $(PWD)/$(OUTPUT)/*.$*) ;\ sha512sum $$BINARY > $$BINARY.sha512 ;\ diff --git a/packaging/post-install.sh b/packaging/post-install.sh new file mode 100644 index 000000000..2759800e1 --- /dev/null +++ b/packaging/post-install.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +########### +# GLOBALS # +########### +PHP_AGENT_DIR=/opt/elastic/apm-agent-php +EXTENSION_FILE_PATH="${PHP_AGENT_DIR}/extensions/elastic_apm.so" +BOOTSTRAP_FILE_PATH="${PHP_AGENT_DIR}/src/bootstrap_php_part.php" + +################################################################################ +########################## FUNCTION CALLS BELOW ################################ +################################################################################ + +################################################################################ +#### Function php_ini_path ##################################################### +function php_ini_path() { + PHP_BIN=$(command -v php) + ${PHP_BIN} -d memory_limit=128M -i \ + | grep 'Configuration File (php.ini) Path =>' \ + | sed -e 's#Configuration File (php.ini) Path =>##g' \ + | head -n 1 \ + | awk '{print $1}' +} + +################################################################################ +#### Function add_extension_configuration_to_file ############################## +function add_extension_configuration_to_file() { + echo ' Extension configuration has just been added for the Elastic PHP agent.' + tee -a "$@" < /usr/local/etc/php/php.ini -echo 'elastic_apm.bootstrap_php_part_file=/usr/share/php/apm-agent-php/bootstrap_php_part.php' >> /usr/local/etc/php/php.ini dpkg -i build/packages/*.deb -cp /usr/share/php/extensions/elastic_apm.so /usr/local/lib/php/extensions/no-debug-non-zts-20170718/ -php -m + +## Verify if the elastic php agent is enabled +if ! php -m | grep 'elastic' ; then + echo 'Extension has not been installed.' + exit 1 +fi ## Validate the installation works as expected with composer composer install From cbad39b34c63add82fd68a4c050b0f18a80c93b5 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 22 Jul 2020 16:11:10 +0100 Subject: [PATCH 2/5] support different PHP versions --- packaging/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/Makefile b/packaging/Makefile index 042532969..e7db8f70f 100644 --- a/packaging/Makefile +++ b/packaging/Makefile @@ -3,6 +3,7 @@ NAME:=apm-agent-php VERSION?=$(shell grep 'VERSION' ../src/ElasticApm/ElasticApm.php | cut -d= -f2 | tr -d " " | sed "s/'\(.*\)'.*/\1/g") OUTPUT:=build/packages PHP_AGENT_DIR:=/opt/elastic/apm-agent-php +PHP_VERSION?=7.2 GIT_SHA ?= $(shell git rev-parse HEAD || echo "unknown") .PHONY: help @@ -85,6 +86,6 @@ rpm-install: ## Install the rpm installer to run some smoke tests .PHONY: deb-install deb-install: ## Install the deb installer to run some smoke tests @cd $(PWD)/packaging/test/ubuntu ;\ - docker build -t deb-install . ;\ + docker build --build-arg PHP_VERSION=$(PHP_VERSION) -t deb-install . ;\ cd - @docker run --rm -v $(PWD):/src -w /src deb-install From 764c49cc915a3549fc38576b245e8d9e5af6cfcc Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 22 Jul 2020 16:13:27 +0100 Subject: [PATCH 3/5] Rename goal to prepare To align same goals for different life cycles (build and packaging) --- DEVELOPMENT.md | 4 ++-- packaging/Makefile | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index a9fb14aec..a412f5c8a 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -34,8 +34,8 @@ To generate the packages then you can use the `packaging/Dockerfile`, see the be | --- | ```bash -## To build the docker image that will be used later on for packaging the project -make -C packaging build +## To prepare the docker image that will be used later on for packaging the project +make -C packaging prepare ## To create the rpm package make -C packaging rpm diff --git a/packaging/Makefile b/packaging/Makefile index e7db8f70f..8a7a625d8 100644 --- a/packaging/Makefile +++ b/packaging/Makefile @@ -11,11 +11,11 @@ GIT_SHA ?= $(shell git rev-parse HEAD || echo "unknown") help: ## Display this help text @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' -.PHONY: build -build: ## Build docker image for the packaging +.PHONY: prepare +prepare: ## Build docker image for the packaging @docker build -t $(IMAGE) . -create-%: build ## Create the specific package +create-%: prepare ## Create the specific package @echo 'Creating package ...' @mkdir -p $(PWD)/$(OUTPUT) @docker run --rm \ From be7bdf61142c319d02dbff25fc4549d843720713 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 22 Jul 2020 16:13:48 +0100 Subject: [PATCH 4/5] [ci] Support other PHP versions in the pipeline --- .ci/Jenkinsfile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 342cecbc4..63ec3b679 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -103,17 +103,12 @@ pipeline { } } stage('Package') { - // Only enable for one version to reuse the install stage output - when { - beforeAgent true - expression { return env.PHP_VERSION == '7.2' } - } steps { withGithubNotify(context: "Package-${PHP_VERSION}") { dir("${BASE_DIR}"){ - sh script: 'make -C packaging package', label: 'package' - sh script: 'make -C packaging info', label: 'package info' - sh script: 'make -C packaging deb-install', label: 'package deb-install' + sh script: "PHP_VERSION=${PHP_VERSION} make -C packaging package", label: 'package' + sh script: "PHP_VERSION=${PHP_VERSION} make -C packaging info", label: 'package info' + sh script: "PHP_VERSION=${PHP_VERSION} make -C packaging deb-install", label: 'package deb-install' } } } From b9752698c8f1f7e913a275887d09e698ee22c007 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 22 Jul 2020 16:27:24 +0100 Subject: [PATCH 5/5] packaging: notify if the extension is enabled --- packaging/post-install.sh | 43 +++++++++++++++++++++-------- packaging/test/ubuntu/entrypoint.sh | 2 +- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/packaging/post-install.sh b/packaging/post-install.sh index 2759800e1..b9e52b2d9 100644 --- a/packaging/post-install.sh +++ b/packaging/post-install.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash -########### -# GLOBALS # -########### +################################################################################ +############################ GLOBAL VARIABLES ################################## +################################################################################ PHP_AGENT_DIR=/opt/elastic/apm-agent-php EXTENSION_FILE_PATH="${PHP_AGENT_DIR}/extensions/elastic_apm.so" BOOTSTRAP_FILE_PATH="${PHP_AGENT_DIR}/src/bootstrap_php_part.php" @@ -12,20 +12,31 @@ BOOTSTRAP_FILE_PATH="${PHP_AGENT_DIR}/src/bootstrap_php_part.php" ################################################################################ ################################################################################ -#### Function php_ini_path ##################################################### -function php_ini_path() { +#### Function php_command ###################################################### +function php_command() { PHP_BIN=$(command -v php) - ${PHP_BIN} -d memory_limit=128M -i \ + ${PHP_BIN} -d memory_limit=128M "$@" +} + +################################################################################ +#### Function php_ini_file_path ################################################ +function php_ini_file_path() { + php_command -i \ | grep 'Configuration File (php.ini) Path =>' \ | sed -e 's#Configuration File (php.ini) Path =>##g' \ | head -n 1 \ | awk '{print $1}' } +################################################################################ +#### Function is_extension_installed ########################################### +function is_extension_installed() { + php_command -m | grep -q 'elastic' +} + ################################################################################ #### Function add_extension_configuration_to_file ############################## function add_extension_configuration_to_file() { - echo ' Extension configuration has just been added for the Elastic PHP agent.' tee -a "$@" <