Skip to content

Commit

Permalink
Enable build with Elastic conan artifactory (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
intuibase authored Jan 10, 2024
1 parent 1f7899b commit 4f2bc45
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .ci/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ build:
-e CONAN_USER_HOME=$(CONAN_USER_HOME) \
elasticobservability/apm-agent-php-dev:native-build-gcc-12.2.0-$(BUILD_ARCHITECTURE)-0.0.2 \
sh -c "cmake --preset $(BUILD_ARCHITECTURE)-release \
&& cmake --build --preset $(BUILD_ARCHITECTURE)-release \
&& cmake --build --preset $(BUILD_ARCHITECTURE)-release -j$(nproc)\
&& ctest --preset $(BUILD_ARCHITECTURE)-release --verbose"
@echo "::endgroup::"

Expand Down
82 changes: 77 additions & 5 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ make -f .ci/Makefile help
```


_NOTE_:
_NOTE_:

* `PHP_VERSION` can be set to a different PHP version.
* For testing of Alpine specific binaries you must run "prepare" task with `DOCKERFILE=Dockerfile.alpine` environment variable set to build proper docker image.
* For testing of Alpine specific binaries you must run "prepare" task with `DOCKERFILE=Dockerfile.alpine` environment variable set to build proper docker image.

### Local development with direct calls to cmake inside docker container
\
Expand Down Expand Up @@ -127,7 +127,7 @@ Jenkins build parameters can be used to run build+test CI pipeline with a custom
## Building and updating docker images used to build the agent extension

If you want to update images used to build native extension, you need to go into `agent/native/building/dockerized` folder and modify Dockerfile stored in images folder. In this moment, there are two Dockerfiles:
`Dockerfile_musl` for Linux x86_64 with musl libc implementation and `Dockerfile_glibc` for all other x86_64 distros with glibc implementation.
`Dockerfile_musl` for Linux x86_64 with musl libc implementation and `Dockerfile_glibc` for all other x86_64 distros with glibc implementation.
Then you need to increment image version in `docker-compose.yml`. Remember to update Dockerfiles for all architectures, if needed. To build new images, you just need to call:
```bash
docker-compose build
Expand All @@ -154,8 +154,8 @@ If you want to update images used for testing, you need to go into `packaging/te
|alpine|Testing of apk packages|
|centos|Testing of rpm packages|
|ubuntu|Testing of deb packages|
|ubuntu/apache|Tesing of deb packages with Apache/mod_php|
|ubuntu/fpm|Tesing of deb packages with Apache/php-fpm|
|ubuntu/apache|Tesing of deb packages with Apache/mod_php|
|ubuntu/fpm|Tesing of deb packages with Apache/php-fpm|

Then you need to increment image version in `docker-compose.yml`.\
To build new images, you just need to call:
Expand All @@ -177,3 +177,75 @@ If everything works as you expected, you just need to push new image to dockerhu
docker push elasticobservability/apm-agent-php-dev:packages-test-apk-php-7.2-0.0.1
```
It should be done for all images you modified.

## Building and publishing conan artifacts

First, please remember that you need to perform all steps inside a proper docker container. This will ensure that each package receives the same unique identifier (and package will be used in CI build).

The following are instructions for building and uploading artifacts for the linux-x86-64 architecture

Execution of container. All you need to do here is to use latest container image revision and replace path to your local repository.
```bash
docker run -ti -v /your/forked/repository/path/apm-agent-php:/source -w /source/agent/native elasticobservability/apm-agent-php-dev:native-build-gcc-12.2.0-linux-x86-64-0.0.2 bash
```

In container environment we need to configure project - it will setup build environment, conan environment and build all required conan dependencies
```bash
cmake --preset linux-x86-64-release
```

Now we need to load python virtual environment created in previous step. This will enable path to conan tool.
```bash
source _build/linux-x86-64-release/python_venv/bin/activate
```

You can list all local conan packages simply by calling:
```bash
conan search
```

it should output listing similar to this:
```bash
recipes:

boost/1.82.0
cmocka/1.1.5
gtest/1.13.0
libcurl/8.0.1
libiconv/1.17
libssh2/1.11.0
libunwind/1.6.2
libxml2/2.9.9
openssl/3.1.3
php-headers-72/1.0@elastic/local
php-headers-73/1.0@elastic/local
php-headers-74/1.0@elastic/local
php-headers-80/1.0@elastic/local
php-headers-81/1.0@elastic/local
php-headers-82/1.0@elastic/local
pkgconf/1.9.3
pkgconf/1.9.3@elastic/local
sqlite3/3.29.0
xz_utils/5.4.4
zlib/1.3

```

Now you need to login into conan as elastic user. Package upload is allowed only for mainteiners.
```bash
conan user -r ElasticConan user@elastic.co
```

Now you can upload package to conan artifactory.

`--all` option will upload all revisions of `php-headers-72` you have stored in your .conan/data folder (keep it in mind if you're sharing conan cache folder between containers). You can remove it, then conan will ask before uploading each version.
```bash
conan upload php-headers-72 --all -r=ElasticConan
```

Now you can check conan artifactory for new packages here:
https://artifactory.elastic.dev/ui/repos/tree/General/apm-agent-php-dev

and in "raw" format here:
https://artifactory.elastic.dev/ui/native/apm-agent-php-dev/

47 changes: 47 additions & 0 deletions agent/native/building/cmake/elastic_conan_export.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,50 @@ function(elastic_conan_alias)
COMMAND_ERROR_IS_FATAL ANY
)
endfunction()

function(conan_update_remote)
# Update a remote
# Arguments URL and NAME are required, INDEX, COMMAND and VERIFY_SSL are optional
# Example usage:
# conan_add_remote(NAME bincrafters INDEX 1
# URL https://api.bintray.com/conan/bincrafters/public-conan
# VERIFY_SSL True)
set(oneValueArgs URL NAME INDEX COMMAND VERIFY_SSL)
cmake_parse_arguments(CONAN "" "${oneValueArgs}" "" ${ARGN})

if(DEFINED CONAN_INDEX)
set(CONAN_INDEX_ARG "-i ${CONAN_INDEX}")
endif()
if(DEFINED CONAN_COMMAND)
set(CONAN_CMD ${CONAN_COMMAND})
else()
conan_check(REQUIRED DETECT_QUIET)
endif()
set(CONAN_VERIFY_SSL_ARG "True")
if(DEFINED CONAN_VERIFY_SSL)
set(CONAN_VERIFY_SSL_ARG ${CONAN_VERIFY_SSL})
endif()
message(STATUS "Conan: Updating ${CONAN_NAME} remote repository (${CONAN_URL}) verify ssl (${CONAN_VERIFY_SSL_ARG})")
execute_process(COMMAND ${CONAN_CMD} remote update ${CONAN_NAME} ${CONAN_INDEX_ARG} ${CONAN_URL} ${CONAN_VERIFY_SSL_ARG}
RESULT_VARIABLE return_code)
if(NOT "${return_code}" STREQUAL "0")
message(FATAL_ERROR "Conan remote failed='${return_code}'")
endif()
endfunction()


function(conan_remove_remote)
# Update a remote
# Argument NAME is required
# Example usage:
# conan_remove_remote(NAME bincrafters)
set(oneValueArgs NAME)
cmake_parse_arguments(CONAN "" "${oneValueArgs}" "" ${ARGN})

message(STATUS "Conan: Removing ${CONAN_NAME} remote repository")
execute_process(COMMAND ${CONAN_CMD} remote remove ${CONAN_NAME}
RESULT_VARIABLE return_code)
if(NOT "${return_code}" STREQUAL "0")
message(FATAL_ERROR "Conan remote failed='${return_code}'")
endif()
endfunction()
4 changes: 4 additions & 0 deletions agent/native/building/cmake/elastic_conan_installer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ include(conan)
conan_check()

include(elastic_conan_export)

# attach Elastic conan remote and make it default
conan_add_remote(NAME ElasticConan URL https://artifactory.elastic.dev/artifactory/api/conan/apm-agent-php-dev INDEX 0)
conan_update_remote(NAME conancenter URL https://center.conan.io INDEX 1)

0 comments on commit 4f2bc45

Please sign in to comment.