Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature/support-apk
Browse files Browse the repository at this point in the history
* upstream/master:
  Add ENVIRONMENT configuration option
  Change composer installation in docker (elastic#128)
  Add tests/APM_Agents_shared directory
  [packaging] support multiple PHP API (elastic#121)
  [Packaging] restore php.ini if something bad happened (elastic#116)
  [CI] Cosmetic changes in the stage names (elastic#115)
  • Loading branch information
v1v committed Aug 18, 2020
2 parents 737c032 + f05ca03 commit 89f79e2
Show file tree
Hide file tree
Showing 22 changed files with 292 additions and 78 deletions.
81 changes: 65 additions & 16 deletions .ci/Jenkinsfile
Expand Up @@ -44,6 +44,7 @@ pipeline {
beforeAgent true
expression { return env.ONLY_DOCS == "false" }
}
failFast false
matrix {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
Expand All @@ -70,9 +71,9 @@ pipeline {
}
}
}
stage('Test') {
stage('PHPT Tests') {
steps {
withGithubNotify(context: "Test-${PHP_VERSION}", tab: 'tests') {
withGithubNotify(context: "PHPT-Tests-${PHP_VERSION}", tab: 'tests') {
dir("${BASE_DIR}"){
sh script: "PHP_VERSION=${PHP_VERSION} make -f .ci/Makefile test", label: 'test'
}
Expand All @@ -84,40 +85,86 @@ pipeline {
}
}
}
stage('Install') {
stage('Generate for package') {
steps {
withGithubNotify(context: "Install-${PHP_VERSION}") {
withGithubNotify(context: "Generate-For-Package-${PHP_VERSION}") {
dir("${BASE_DIR}"){
sh script: "PHP_VERSION=${PHP_VERSION} make -f .ci/Makefile install", label: 'install'
sh script: "PHP_VERSION=${PHP_VERSION} make -f .ci/Makefile generate-for-package", label: 'generate-for-package'
stash includes: 'src/ext/modules/*.so', name: "generate-for-package-${PHP_VERSION}"
}
}
}
}
stage('Composer') {
stage('PHPUnit Tests') {
steps {
withGithubNotify(context: "Composer-${PHP_VERSION}") {
withGithubNotify(context: "PHPUnit-Tests-${PHP_VERSION}", tab: 'tests') {
dir("${BASE_DIR}"){
sh script: "PHP_VERSION=${PHP_VERSION} make -f .ci/Makefile composer", label: 'composer'
}
}
}
}
stage('Package') {
}
}
}
stage('Package Generation') {
when {
beforeAgent true
expression { return env.ONLY_DOCS == "false" }
}
options { skipDefaultCheckout() }
steps {
withGithubNotify(context: "Package", tab: 'artifacts') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
unstash 'generate-for-package-7.2'
unstash 'generate-for-package-7.3'
unstash 'generate-for-package-7.4'
sh script: "make -C packaging package", label: 'package'
sh script: "make -C packaging info", label: 'package info'
stash includes: 'build/packages/*', name: 'package'
}
}
}
post {
always {
dir("${BASE_DIR}"){
archiveArtifacts(allowEmptyArchive: true, artifacts: "build/packages/*")
}
}
}
}
stage('Package-Test') {
when {
beforeAgent true
expression { return env.ONLY_DOCS == "false" }
}
failFast false
matrix {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
axes {
axis {
name 'PHP_VERSION'
values '7.2', '7.3', '7.4'
}
}
stages {
stage('Package Test') {
steps {
withGithubNotify(context: "Package-${PHP_VERSION}") {
withGithubNotify(context: "Package-Test-${PHP_VERSION}") {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
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'
unstash 'package'
sh script: "PHP_VERSION=${PHP_VERSION} make -C packaging install", label: 'package install'
}
}
}
post {
always {
dir("${BASE_DIR}"){
junit(allowEmptyResults: true, keepLongStdio: true, testResults: "**/log_as_junit.xml")
archiveArtifacts(allowEmptyArchive: true, artifacts: "build/packages/${PHP_VERSION}/*")
}
junit(allowEmptyResults: true, keepLongStdio: true, testResults: "${BASE_DIR}/**/log_as_junit.xml")
}
}
}
Expand All @@ -127,7 +174,9 @@ pipeline {
stage('Testing') {
when {
beforeAgent true
expression { return env.ONLY_DOCS == "false" }
// TODO: && false in place to disable this particular section for the time being.
// as agreed to avoid any misleading until this particular section has been implemented.
expression { return env.ONLY_DOCS == "false" && false }
}
matrix {
// TODO: This should be uncommented out when the implementation is in place
Expand Down
6 changes: 3 additions & 3 deletions .ci/Makefile
Expand Up @@ -32,13 +32,13 @@ test: prepare ## Test the project
$(IMAGE):${PHP_VERSION} \
make test

.PHONY: install
install: prepare ## Install the agent
.PHONY: generate-for-package
generate-for-package: prepare ## Generate the agent extension for the package
# docker as root to install the extension
docker run --rm -t \
-v $(PWD):/app \
$(IMAGE):${PHP_VERSION} \
make install
/app/.ci/generate-for-package.sh

.PHONY: composer
composer: prepare ## Run composer
Expand Down
31 changes: 31 additions & 0 deletions .ci/generate-for-package.sh
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -exo pipefail

HYPHEN="-"
MODULES_DIR=/app/src/ext/modules
NAME=elastic_apm
## Prepare context where to copy the previous generated so files
GENERATED=$(mktemp -d /tmp/dir-XXXX)
SEARCH="${MODULES_DIR}/*${HYPHEN}*.so"
if ls "${SEARCH}" 1> /dev/null 2>&1; then
cp -f "${SEARCH}" "${GENERATED}" || true
fi

## Generate so file
make clean
make

## Fetch PHP api version to be added to the so file that has been generated
PHP_API=$(php -i | grep -i 'PHP API' | sed -e 's#.* =>##g' | awk '{print $1}')

## Rename so file with the PHP api
mv "${MODULES_DIR}/${NAME}.so" "${MODULES_DIR}/${NAME}${HYPHEN}${PHP_API}.so"

## Remove la files
find "${MODULES_DIR}" -name "*.la" -print0 | xargs -0 rm -f

## Restore previous so files.
if ls "${SEARCH}" 1> /dev/null 2>&1; then
cp -f "${SEARCH}" ${MODULES_DIR}/
fi
4 changes: 2 additions & 2 deletions DEVELOPMENT.md
Expand Up @@ -16,8 +16,8 @@ PHP_VERSION=7.2 make -f .ci/Makefile build
## To test the library
PHP_VERSION=7.2 make -f .ci/Makefile test

## To install the library
PHP_VERSION=7.2 make -f .ci/Makefile install
## To generate the agent extension with the existing PHP API
PHP_VERSION=7.2 make -f .ci/Makefile generate-for-package

## To install with composer
PHP_VERSION=7.2 make -f .ci/Makefile composer
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Expand Up @@ -3,18 +3,18 @@ FROM php:${PHP_VERSION}-fpm

RUN apt-get -qq update \
&& apt-get -qq install -y \
build-essential \
autoconf \
build-essential \
curl \
libcurl4-openssl-dev \
procps \
unzip \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('sha384', 'composer-setup.php') === 'e5325b19b381bfd88ce90a5ddb7823406b2a38cff6bb704b0acc289a09c8128d4a8ce2bbafcd1fcbdc38666422fe2806') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php --install-dir=/usr/bin --filename=composer \
RUN php -r "copy('https://raw.githubusercontent.com/composer/getcomposer.org/baecae060ee7602a9908f2259f7460b737839972/web/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('sha384', 'composer-setup.php') === '572cb359b56ad9ae52f9c23d29d4b19a040af10d6635642e646a7caa7b96de717ce683bd797a92ce99e5929cc51e7d5f') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php --install-dir=/usr/bin --filename=composer --version=1.10.10 \
&& php -r "unlink('composer-setup.php');"

WORKDIR /app/src/ext
Expand Down
22 changes: 13 additions & 9 deletions packaging/Makefile
Expand Up @@ -13,13 +13,17 @@ export FPM_FLAGS=
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: clean
clean: ## Clean the generated packages
rm -f $(PWD)/$(OUTPUT)/*.*

.PHONY: prepare
prepare: ## Build docker image for the packaging
@docker build -t $(IMAGE) .

create-%: prepare ## Create the specific package
@echo "Creating package $* ..."
@mkdir -p $(PWD)/$(OUTPUT)/$(PHP_VERSION)
@mkdir -p $(PWD)/$(OUTPUT)
@docker run --rm \
-v $(PWD):/app \
-w /app $(IMAGE) \
Expand All @@ -33,7 +37,7 @@ create-%: prepare ## Create the specific package
--license 'ASL 2.0' \
--vendor 'Elasticsearch, Inc.' \
--description "PHP agent for Elastic APM\nGit Commit: ${GIT_SHA}" \
--package $(OUTPUT)/$(PHP_VERSION) \
--package $(OUTPUT) \
--chdir /app ${FPM_FLAGS} \
--after-install=packaging/post-install.sh \
packaging/post-install.sh=$(PHP_AGENT_DIR)/bin/post-install.sh \
Expand All @@ -42,10 +46,10 @@ create-%: prepare ## Create the specific package
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)/$(PHP_VERSION)/*.$*) ;\
@BINARY=$$(ls -1 $(PWD)/$(OUTPUT)/*.$*) ;\
sha512sum $$BINARY > $$BINARY.sha512 ;\
sed -i.bck "s#$(PWD)/$(OUTPUT)/$(PHP_VERSION)/##g" $$BINARY.sha512 ;\
rm $(PWD)/$(OUTPUT)/$(PHP_VERSION)/*.bck
sed -i.bck "s#$(PWD)/$(OUTPUT)/##g" $$BINARY.sha512 ;\
rm $(PWD)/$(OUTPUT)/*.bck

.PHONY: apk
apk: FPM_FLAGS="--depends=bash"
Expand Down Expand Up @@ -74,27 +78,27 @@ info: apk-info deb-info rpm-info tar-info ## Show the package metadata for all
.PHONY: apk-info
apk-info: ## Show the apk package metadata
@cd $(PWD) ;\
BINARY=$$(ls -1 $(OUTPUT)/$(PHP_VERSION)/*.apk) ;\
BINARY=$$(ls -1 $(OUTPUT)/*.apk) ;\
docker run --rm -v $(PWD):/app -w /app --entrypoint /sbin/apk $(IMAGE) manifest $$BINARY

.PHONY: deb-info
deb-info: ## Show the deb package metadata
@cd $(PWD) ;\
BINARY=$$(ls -1 $(OUTPUT)/$(PHP_VERSION)/*.deb) ;\
BINARY=$$(ls -1 $(OUTPUT)/*.deb) ;\
docker run --rm -v $(PWD):/app -w /app --entrypoint /usr/bin/dpkg $(IMAGE) --info $$BINARY ;\
docker run --rm -v $(PWD):/app -w /app --entrypoint /usr/bin/dpkg $(IMAGE) -c $$BINARY

.PHONY: rpm-info
rpm-info: ## Show the rpm package metadata
@cd $(PWD) ;\
BINARY=$$(ls -1 $(OUTPUT)/$(PHP_VERSION)/*.rpm) ;\
BINARY=$$(ls -1 $(OUTPUT)/*.rpm) ;\
docker run --rm -v $(PWD):/app -w /app --entrypoint /usr/bin/rpm $(IMAGE) -qip $$BINARY ;\
docker run --rm -v $(PWD):/app -w /app --entrypoint /usr/bin/rpm $(IMAGE) -qlp $$BINARY

.PHONY: tar-info
tar-info: ## Show the tar package metadata
@cd $(PWD) ;\
BINARY=$$(ls -1 $(OUTPUT)/$(PHP_VERSION)/*.tar) ;\
BINARY=$$(ls -1 $(OUTPUT)/*.tar) ;\
docker run --rm -v $(PWD):/app -w /app --entrypoint /usr/bin/tar $(IMAGE) -tvf $$BINARY

.PHONY: apk-install
Expand Down

0 comments on commit 89f79e2

Please sign in to comment.