Skip to content

Commit 13e8b0b

Browse files
authored
Introduce C++ into project together with conan dependencies (918) (#985)
1 parent 67ee736 commit 13e8b0b

File tree

434 files changed

+3823
-659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

434 files changed

+3823
-659
lines changed

.ci/Jenkinsfile

+90-37
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ pipeline {
3131
choice(name: 'AGENT_LOG_LEVEL', choices: LOG_LEVELS, description: "Agent's log level")
3232
choice(name: 'TESTS_LOG_LEVEL', choices: LOG_LEVELS, description: "Tests' log level")
3333
booleanParam(name: 'INCLUDE_TESTING', defaultValue: true, description: 'Should the testing stages be included?')
34-
booleanParam(name: 'ADD_LIBUNWIND_DEPENDENCY', defaultValue: false, description: 'Should Alpine (.apk) build have dependency on libunwind (to be able to log C call stack on crash)?')
3534
}
3635
stages {
3736
stage('Initializing'){
@@ -84,7 +83,7 @@ pipeline {
8483
}
8584
}
8685
}
87-
stage('Build binaries and basic testing') {
86+
stage('Build binaries') {
8887
options { skipDefaultCheckout() }
8988
when {
9089
beforeAgent true
@@ -94,50 +93,116 @@ pipeline {
9493
matrix {
9594
agent { label 'ubuntu-18.04 && immutable' }
9695
axes {
96+
axis {
97+
name 'BUILD_ARCHITECTURE'
98+
values 'linux-x86-64', 'linuxmusl-x86-64'
99+
}
100+
}
101+
102+
stages {
103+
stage('Build PHP extension') {
104+
steps {
105+
initWorkspace(context: "Build-${BUILD_ARCHITECTURE}") {
106+
sh script: "BUILD_ARCHITECTURE=${BUILD_ARCHITECTURE} make -f .ci/Makefile build", label: 'build'
107+
}
108+
withGithubNotify(context: "Build-${BUILD_ARCHITECTURE}") {
109+
dir("${BASE_DIR}"){
110+
stash includes: "agent/native/_build/${BUILD_ARCHITECTURE}-release/ext/elastic_apm-*", name: "built-extensions-${BUILD_ARCHITECTURE}"
111+
}
112+
}
113+
}
114+
}
115+
}
116+
}
117+
}
118+
stage('PHP tests of extension') {
119+
options { skipDefaultCheckout() }
120+
when {
121+
beforeAgent true
122+
expression { return env.ONLY_DOCS == "false" }
123+
}
124+
failFast false
125+
matrix {
126+
agent { label 'ubuntu-18.04 && immutable' }
127+
axes {
128+
axis {
129+
name 'BUILD_ARCHITECTURE'
130+
values 'linux-x86-64', 'linuxmusl-x86-64'
131+
}
97132
axis {
98133
name 'PHP_VERSION'
99134
// Make sure list of PHP versions supported by the Elastic APM PHP Agent is in sync.
100135
// See the comment in .ci/shared.sh
101136
values '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'
102137
}
103-
axis {
104-
name 'DOCKERFILE'
105-
values 'Dockerfile', 'Dockerfile.alpine'
106-
}
107138
}
139+
108140
stages {
109-
stage('Build PHP extension') {
141+
stage('Execute phpt tests') {
142+
when {
143+
beforeAgent true
144+
expression { return params.INCLUDE_TESTING }
145+
}
110146
steps {
111-
echo "params.INCLUDE_TESTING: ${params.INCLUDE_TESTING}"
112-
echo "params.ADD_LIBUNWIND_DEPENDENCY: ${params.ADD_LIBUNWIND_DEPENDENCY}"
113-
initWorkspace(context: "Build-${PHP_VERSION}") {
147+
initWorkspace(context: "PHPT-${PHP_VERSION}", tab: "tests") {
114148
// When running in the CI with multiple parallel stages
115149
// the access could be considered as a DDOS attack.
116-
retryWithSleep(retries: 3, seconds: 5, backoff: true) {
117-
sh script: "PHP_VERSION=${PHP_VERSION} DOCKERFILE=${DOCKERFILE} ADD_LIBUNWIND_DEPENDENCY=${params.ADD_LIBUNWIND_DEPENDENCY} make -f .ci/Makefile prepare", label: 'prepare docker image'
150+
retryWithSleep(retries: 3, seconds: 45, backoff: true) {
151+
sh script: "BUILD_ARCHITECTURE=${BUILD_ARCHITECTURE} PHP_VERSION=${PHP_VERSION} make -f .ci/Makefile prepare", label: 'prepare docker image'
118152
}
119-
sh script: "PHP_VERSION=${PHP_VERSION} DOCKERFILE=${DOCKERFILE} make -f .ci/Makefile build", label: 'build'
153+
unstash "built-extensions-${BUILD_ARCHITECTURE}"
154+
sh script: "BUILD_ARCHITECTURE=${BUILD_ARCHITECTURE} PHP_VERSION=${PHP_VERSION} make -f .ci/Makefile run-phpt-tests", label: 'run-phpt-tests'
120155
}
121156
}
122157
}
158+
}
159+
}
160+
}
161+
stage('Static analysis and tests') {
162+
options { skipDefaultCheckout() }
163+
when {
164+
beforeAgent true
165+
expression { return env.ONLY_DOCS == "false" }
166+
}
167+
failFast false
168+
matrix {
169+
agent { label 'ubuntu-18.04 && immutable' }
170+
axes {
171+
axis {
172+
name 'PHP_VERSION'
173+
// Make sure list of PHP versions supported by the Elastic APM PHP Agent is in sync.
174+
// See the comment in .ci/shared.sh
175+
values '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'
176+
}
177+
axis {
178+
name 'DOCKERFILE'
179+
values 'Dockerfile', 'Dockerfile.alpine'
180+
}
181+
}
182+
stages {
123183
stage('Static analysis and unit tests') {
124184
when {
125185
beforeAgent true
126186
expression { return params.INCLUDE_TESTING }
127187
}
128188
steps {
189+
echo "params.INCLUDE_TESTING: ${params.INCLUDE_TESTING}"
129190
echo "params.AGENT_LOG_LEVEL: ${params.AGENT_LOG_LEVEL}"
130191
echo "params.AGENT_LOG_LEVEL == null: " + (params.AGENT_LOG_LEVEL == null)
131192
echo "params.TESTS_LOG_LEVEL: ${params.TESTS_LOG_LEVEL}"
132193
echo "params.TESTS_LOG_LEVEL == null: " + (params.TESTS_LOG_LEVEL == null)
133194
echo "addEnvVarsFromParams([]): " + addEnvVarsFromParams([])
134-
withGithubNotify(context: "Static-Check-Unit-Tests-${PHP_VERSION}", tab: 'tests') {
195+
196+
initWorkspace(context: "Static-Check-Unit-Tests-${PHP_VERSION}", tab: "tests") {
135197
withEnv(addEnvVarsFromParams([])) {
136198
echo "env.ELASTIC_APM_LOG_LEVEL: ${env.ELASTIC_APM_LOG_LEVEL}"
137199
echo "env.TESTS_LOG_LEVEL: ${env.TESTS_LOG_LEVEL}"
138-
dir("${BASE_DIR}"){
139-
sh script: "PHP_VERSION=${PHP_VERSION} DOCKERFILE=${DOCKERFILE} make -f .ci/Makefile static-check-unit-test", label: 'static-check-unit-test'
200+
201+
retryWithSleep(retries: 3, seconds: 45, backoff: true) {
202+
sh script: "PHP_VERSION=${PHP_VERSION} DOCKERFILE=${DOCKERFILE} make -f .ci/Makefile prepare", label: 'prepare docker image'
140203
}
204+
205+
sh script: "PHP_VERSION=${PHP_VERSION} DOCKERFILE=${DOCKERFILE} make -f .ci/Makefile static-check-unit-test", label: 'static-check-unit-test'
141206
}
142207
}
143208
}
@@ -147,16 +212,6 @@ pipeline {
147212
}
148213
}
149214
}
150-
stage('Build parts for packages') {
151-
steps {
152-
withGithubNotify(context: "Generate-For-Package-${PHP_VERSION}") {
153-
dir("${BASE_DIR}"){
154-
sh script: "PHP_VERSION=${PHP_VERSION} DOCKERFILE=${DOCKERFILE} ADD_LIBUNWIND_DEPENDENCY=${params.ADD_LIBUNWIND_DEPENDENCY} make -f .ci/Makefile generate-for-package", label: 'generate-for-package'
155-
stash includes: 'src/ext/modules/*.so', name: "generate-for-package-${PHP_VERSION}-${DOCKERFILE}"
156-
}
157-
}
158-
}
159-
}
160215
}
161216
}
162217
}
@@ -374,10 +429,9 @@ pipeline {
374429
*/
375430
def packageGeneration(def args = [:]) {
376431
def local = args.get('local', false)
377-
args.versions.each { version ->
378-
unstash "generate-for-package-${version}-Dockerfile"
379-
unstash "generate-for-package-${version}-Dockerfile.alpine"
380-
}
432+
unstash "built-extensions-linux-x86-64"
433+
unstash "built-extensions-linuxmusl-x86-64"
434+
381435
if (local) {
382436
// VERSION=1.0.0 is needed to override the current version.
383437
// current version is >1.0.0, and this is the way we can
@@ -387,7 +441,8 @@ def packageGeneration(def args = [:]) {
387441
sh script: "mv build/packages build/local", label: 'prepare-local-upgrade-agent'
388442
} else {
389443
// Archive the so files to be downloaded if possible.
390-
archiveArtifacts(allowEmptyArchive: true, artifacts: 'src/ext/modules/*.so')
444+
archiveArtifacts(allowEmptyArchive: true, artifacts: 'agent/native/_build/*-release/ext/elastic_apm-*')
445+
391446
sh script: "make -C packaging package", label: 'package'
392447
sh script: "make -C packaging info", label: 'package info'
393448
// checksum files are regenerated by the signing component in the internal-ci instance.
@@ -419,8 +474,10 @@ def packageWorkspace(def args = [:], Closure body){
419474
unstash (args.shouldUseSignedBinaries ? env.SIGNED_ARTIFACTS : 'package')
420475
// When running in the CI sometimes the docker build might fail for
421476
// some environmental issues, let's retry
422-
retryWithSleep(retries: 3, seconds: 5, backoff: true) {
423-
sh script: "PHP_VERSION=${PHP_VERSION} make -C packaging ${args.prepareGoal}", label: "${args.prepareGoal} for ${PHP_VERSION}"
477+
retryWithSleep(retries: 3, seconds: 45, backoff: true) {
478+
if (args.prepareGoal != null) {
479+
sh script: "PHP_VERSION=${PHP_VERSION} make -C packaging ${args.prepareGoal}", label: "${args.prepareGoal} for ${PHP_VERSION}"
480+
}
424481
}
425482
body()
426483
}
@@ -546,7 +603,6 @@ def addEnvVarsFromParams(def withEnvList) {
546603
if (params.TESTS_LOG_LEVEL != null && !params.TESTS_LOG_LEVEL.equals(LOG_LEVEL_NOT_SET)) {
547604
withEnvList.add('ELASTIC_APM_PHP_TESTS_LOG_LEVEL=' + params.TESTS_LOG_LEVEL)
548605
}
549-
withEnvList.add('ADD_LIBUNWIND_DEPENDENCY=' + params.ADD_LIBUNWIND_DEPENDENCY)
550606
return withEnvList
551607
}
552608

@@ -574,7 +630,6 @@ def buildLabel(def args = [:]) {
574630
def lifecycleTesting(def args = [:]) {
575631
runTestingCommand(
576632
args + [
577-
prepareGoal: "prepare-${args.linuxPackageType}",
578633
testingCommand: "make -C packaging ${args.linuxPackageType}-lifecycle-testing"
579634
]
580635
)
@@ -583,7 +638,6 @@ def lifecycleTesting(def args = [:]) {
583638
def lifecycleTestingOnProdServerKind(def args = [:]) {
584639
runTestingCommand(
585640
args + [
586-
prepareGoal: "prepare-${args.linuxPackageType}-${args.prodServerKind}",
587641
testingCommand: "make -C packaging ${args.linuxPackageType}-lifecycle-testing-in-${args.prodServerKind}",
588642
]
589643
)
@@ -592,7 +646,6 @@ def lifecycleTestingOnProdServerKind(def args = [:]) {
592646
def phpUpgradeTesting(def args = [:]) {
593647
runTestingCommand(
594648
args + [
595-
prepareGoal: "prepare-${args.linuxPackageType}",
596649
testingCommand: "PHP_VERSION=${args.phpVersion} make -C packaging ${args.linuxPackageType}-php-upgrade-testing"
597650
]
598651
)

.ci/Makefile

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
ifeq ($(DOCKERFILE),)
2+
ifeq ($(BUILD_ARCHITECTURE), linuxmusl-x86-64)
3+
DOCKERFILE := Dockerfile.alpine
4+
else
5+
DOCKERFILE := Dockerfile
6+
endif
7+
endif
18

29
SHELL=/bin/bash -o pipefail
310
MAKEFLAGS += --no-print-directory
@@ -6,15 +13,20 @@ PHP_VERSION ?= 7.2
613
DOCKERFILE ?= Dockerfile
714
LOOPS ?= 50
815
SUFFIX :=
9-
ADD_LIBUNWIND_DEPENDENCY_BUILD_ARG_OPT:=
1016
ifeq ($(DOCKERFILE), Dockerfile.alpine)
1117
## This is only required to tag the docker images used for building/testing this project
1218
SUFFIX := -alpine
13-
ADD_LIBUNWIND_DEPENDENCY_BUILD_ARG_OPT:=--build-arg ADD_LIBUNWIND_DEPENDENCY=${ADD_LIBUNWIND_DEPENDENCY}
19+
endif
20+
21+
CONAN_USER_HOME:=/tmp/conan_user_home
22+
MAP_CONAN_HOME_TO_DOCKER_HOST_CMD_LINE_ARG:=
23+
ifdef MAP_CONAN_HOME_TO_DOCKER_HOST
24+
MAP_CONAN_HOME_TO_DOCKER_HOST_CMD_LINE_ARG:=-v "${MAP_CONAN_HOME_TO_DOCKER_HOST}:$(CONAN_USER_HOME)"
1425
endif
1526

1627
CURRENT_UID := $(shell id -u)
1728
CURRENT_GID := $(shell id -g)
29+
CURRENT_USER_HOME := $(shell echo ~)
1830

1931
.PHONY: help
2032
.DEFAULT_GOAL := help
@@ -26,19 +38,24 @@ prepare: ## Build docker image for building and testing the project
2638
@echo "::group::$@" # Helping to group logs in GitHub actions
2739
docker build \
2840
--build-arg PHP_VERSION=${PHP_VERSION} \
29-
${ADD_LIBUNWIND_DEPENDENCY_BUILD_ARG_OPT} \
3041
--tag $(IMAGE):${PHP_VERSION}$(SUFFIX) \
3142
-f ${DOCKERFILE} .
3243
@echo "::endgroup::"
3344

3445
.PHONY: build
35-
build: prepare ## Build the project
46+
build:
3647
@echo "::group::$@" # Helping to group logs in GitHub actions
3748
# docker as the current user
3849
docker run --rm -t \
3950
-u $(CURRENT_UID):$(CURRENT_GID) \
40-
-v $(PWD):/app \
41-
$(IMAGE):${PHP_VERSION}$(SUFFIX)
51+
-v $(PWD):/source \
52+
${MAP_CONAN_HOME_TO_DOCKER_HOST_CMD_LINE_ARG} \
53+
-w /source/agent/native \
54+
-e CONAN_USER_HOME=$(CONAN_USER_HOME) \
55+
elasticobservability/apm-agent-php-dev:native-build-gcc-12.2.0-$(BUILD_ARCHITECTURE)-0.0.2 \
56+
sh -c "cmake --preset $(BUILD_ARCHITECTURE)-release \
57+
&& cmake --build --preset $(BUILD_ARCHITECTURE)-release \
58+
&& /source/agent/native/_build/$(BUILD_ARCHITECTURE)-release/ext/unit_tests/unit_tests"
4259
@echo "::endgroup::"
4360

4461
.PHONY: static-check-unit-test
@@ -52,15 +69,16 @@ static-check-unit-test: prepare ## Test the static check and unit tests
5269
/app/.ci/static-check-unit-test.sh
5370
@echo "::endgroup::"
5471

55-
.PHONY: generate-for-package
56-
generate-for-package: prepare ## Generate the agent extension for the package
72+
.PHONY: run-phpt-tests
73+
run-phpt-tests: prepare ## Runs phpt tests
5774
@echo "::group::$@" # Helping to group logs in GitHub actions
5875
# docker as the current user
5976
docker run --rm -t \
77+
-e CHOWN_RESULTS_UID=$(CURRENT_UID) -e CHOWN_RESULTS_GID=$(CURRENT_GID) \
78+
-e BUILD_ARCHITECTURE=$(BUILD_ARCHITECTURE) \
6079
-v $(PWD):/app \
61-
-u $(CURRENT_UID):$(CURRENT_GID) \
6280
$(IMAGE):${PHP_VERSION}$(SUFFIX) \
63-
/app/.ci/generate-for-package.sh
81+
/app/.ci/run-phpt-tests.sh
6482
@echo "::endgroup::"
6583

6684
.PHONY: interactive
@@ -75,6 +93,7 @@ component-test: prepare ## Run component-test
7593
@echo "::group::$@" # Helping to group logs in GitHub actions
7694
# docker as root to install the extension
7795
docker run -t --rm \
96+
-e BUILD_ARCHITECTURE=$(BUILD_ARCHITECTURE) \
7897
-v $(PWD):/app \
7998
$(IMAGE):${PHP_VERSION}$(SUFFIX) \
8099
sh -c '/app/.ci/component-test.sh'

.ci/bump_version.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -xe
33

4-
sed -i.bck "s#\(VERSION = \).*;#\1'${VERSION}';#g" src/ElasticApm/ElasticApm.php
5-
sed -i.bck "s#\(PHP_ELASTIC_APM_VERSION\).*#\1 \"${VERSION}\"#g" src/ext/elastic_apm_version.h
4+
sed -i.bck "s#\(VERSION = \).*;#\1'${VERSION}';#g" agent/php/ElasticApm/ElasticApm.php
5+
sed -i.bck "s#\(PHP_ELASTIC_APM_VERSION\).*#\1 \"${VERSION}\"#g" agent/native/ext/elastic_apm_version.h
66

7-
git add src/ElasticApm/ElasticApm.php src/ext/elastic_apm_version.h
7+
git add agent/php/ElasticApm/ElasticApm.php agent/native/ext/elastic_apm_version.h

.ci/component-test.sh

+25-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,32 @@ set -xe -o pipefail
44
# Disable Elastic APM for any process outside the component tests to prevent noise in the logs
55
export ELASTIC_APM_ENABLED=false
66

7+
APP_FOLDER=/app
8+
PHP_API=$(php -i | grep -i 'PHP API' | sed -e 's#.* =>##g' | awk '{print $1}')
9+
PHP_EXECUTABLE=$(which php)
10+
11+
echo "BUILD ARCHITECTURE: $BUILD_ARCHITECTURE"
12+
13+
if [ -z "${BUILD_ARCHITECTURE}" ]
14+
then
15+
echo "\$BUILD_ARCHITECTURE is not specified, assuming linux-x86-64"
16+
BUILD_ARCHITECTURE=linux-x86-64
17+
fi
18+
echo "BUILD ARCHITECTURE: $BUILD_ARCHITECTURE"
19+
20+
21+
22+
AGENT_EXTENSION_DIR=$APP_FOLDER/agent/native/_build/$BUILD_ARCHITECTURE-release/ext
23+
AGENT_EXTENSION=$AGENT_EXTENSION_DIR/elastic_apm-$PHP_API.so
24+
25+
mkdir -p $APP_FOLDER/build
26+
27+
728
PHP_INI=/usr/local/etc/php/php.ini
8-
make install
9-
echo 'extension=elastic_apm.so' > ${PHP_INI}
10-
echo 'elastic_apm.bootstrap_php_part_file=/app/src/bootstrap_php_part.php' >> ${PHP_INI}
29+
echo "extension=${AGENT_EXTENSION}" > ${PHP_INI}
30+
echo "elastic_apm.bootstrap_php_part_file=${APP_FOLDER}/agent/php/bootstrap_php_part.php" >> ${PHP_INI}
1131
php -m
12-
cd /app
32+
cd "${APP_FOLDER}"
1333

1434
# Install 3rd party dependencies
1535
composer install
@@ -28,5 +48,5 @@ fi
2848

2949
# Run component tests
3050
mkdir -p ./build/
31-
composer run-script run_component_tests 2>&1 | tee /app/build/run_component_tests_output.txt
51+
composer run-script run_component_tests 2>&1 | tee ${APP_FOLDER}/build/run_component_tests_output.txt
3252

0 commit comments

Comments
 (0)