From 067c002ee1af5eb93a7ee0fed7284c6e24322831 Mon Sep 17 00:00:00 2001 From: Michal Nowacki Date: Wed, 27 Dec 2023 12:38:46 -0500 Subject: [PATCH] containerized development environment --- build-services.mk | 47 +++++++++++++++++++++++++++ build-services.yml | 78 +++++++++++++++++++++++++++++++++++++++++++++ common-services.yml | 52 ++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 build-services.mk create mode 100644 build-services.yml create mode 100644 common-services.yml diff --git a/build-services.mk b/build-services.mk new file mode 100644 index 000000000..8dab3db6a --- /dev/null +++ b/build-services.mk @@ -0,0 +1,47 @@ +# PHPs supported by composer build services +PHPS=7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 +SERVICES=go redisdb mysqldb $(addprefix php-,$(PHPS)) + +# Shell user - default to `root`, can be overriden to `root` +SHELL_USER=root + +start: + @test -z $$PULL || docker compose -f build-services.yml pull $(SERVICES) + docker compose -f build-services.yml up --remove-orphans -d $(SERVICES) + +stop: + docker compose -f build-services.yml stop + +exec: + @test -z $$PHP && { echo "Please provide PHP version with PHP="; exit 2; } || true + @test -z $$CMD && { echo "Please provide CMD to run with CMD="; exit 2; } || true + @docker compose -f build-services.yml exec php-${PHP} $(CMD) $(ARGS) + +.PHONY: shell +shell: + @test -z $$PHP && { echo "Please provide PHP version with PHP="; exit 2; } || \ + docker compose -f build-services.yml exec --user $(SHELL_USER) -it php-$${PHP} /bin/bash + +bin/integration_runner: + docker compose -f build-services.yml exec go make bin/integration_runner + +build-integration-runner: bin/integration_runner + + +build-agent: build-integration-runner + @for PHP in $(PHPS); do \ + echo "=====[php-$${PHP}]======"; \ + ver=`echo $$PHP | cut -d '-' -f 1`; \ + docker compose -f build-services.yml exec php-$${ver} make agent; \ + echo "Saving agent/modules/newrelic.so to ./newrelic-for-php-$${ver}.so"; \ + cp agent/modules/newrelic.so "./newrelic-for-php-$${ver}.so"; \ + docker compose -f build-services.yml exec php-$${ver} make agent-clean; \ + done + +LOGLEVEL=info +run-tests: + @for PHP in $(PHPS); do \ + echo "=====[php-$${PHP}]======"; \ + ver=`echo $$PHP | cut -d '-' -f 1`; \ + docker compose -f build-services.yml --env-file integration-tests.env exec php-$${ver} bin/integration_runner -agent ./newrelic-for-php-$${ver}.so -loglevel $(LOGLEVEL) $$TESTS; \ + done diff --git a/build-services.yml b/build-services.yml new file mode 100644 index 000000000..e4e7add04 --- /dev/null +++ b/build-services.yml @@ -0,0 +1,78 @@ +services: + go: + image: newrelic/nr-php-agent-builder:make-go-${LIBC:-gnu} + extends: + file: common-services.yml + service: go-base + + php-7.0: + extends: + file: common-services.yml + service: php-base + image: newrelic/nr-php-agent-builder:make-php-7.0-${LIBC:-gnu} + environment: + PHPS: "7.0" + + php-7.1: + extends: + file: common-services.yml + service: php-base + image: newrelic/nr-php-agent-builder:make-php-7.1-${LIBC:-gnu} + environment: + PHPS: "7.1" + + php-7.2: + extends: + file: common-services.yml + service: php-base + image: newrelic/nr-php-agent-builder:make-php-7.2-${LIBC:-gnu} + environment: + PHPS: "7.2" + + php-7.3: + extends: + file: common-services.yml + service: php-base + image: newrelic/nr-php-agent-builder:make-php-7.3-${LIBC:-gnu} + environment: + PHPS: "7.3" + + php-7.4: + extends: + file: common-services.yml + service: php-base + image: newrelic/nr-php-agent-builder:make-php-7.4-${LIBC:-gnu} + environment: + PHPS: "7.4" + + php-8.0: + extends: + file: common-services.yml + service: php-base + image: newrelic/nr-php-agent-builder:make-php-8.0-${LIBC:-gnu} + environment: + PHPS: "8.0" + + php-8.1: + extends: + file: common-services.yml + service: php-base + image: newrelic/nr-php-agent-builder:make-php-8.1-${LIBC:-gnu} + environment: + PHPS: "8.1" + + php-8.2: + extends: + file: common-services.yml + service: php-base + image: newrelic/nr-php-agent-builder:make-php-8.2-${LIBC:-gnu} + environment: + PHPS: "8.2" + + php-8.3: + extends: + file: common-services.yml + service: php-base + image: newrelic/nr-php-agent-builder:make-php-8.3-${LIBC:-gnu} + environment: + PHPS: "8.3" diff --git a/common-services.yml b/common-services.yml new file mode 100644 index 000000000..b0ef22b94 --- /dev/null +++ b/common-services.yml @@ -0,0 +1,52 @@ +version: '2.4' + +services: + redis: + image: redis + restart: always + environment: &redis-env + REDIS_HOST: redisdb + ports: + - "6379:6379" + container_name: redisdb + + mysql: + platform: linux/amd64 + image: mysql:5.6 + restart: always + environment: &mysql-env + MYSQL_ROOT_PASSWORD: admin + MYSQL_DATABASE: database + MYSQL_USER: admin + MYSQL_PASSWORD: admin + MYSQL_HOST: mysqldb + ports: + - "3306:3306" + healthcheck: + test: ["CMD", "mysql", "--user=admin", "--password=admin", "-e", "SELECT 1"] + interval: 10s + timeout: 10s + retries: 3 + start_period: 20s + container_name: mysqldb + + go-base: + # image: scratch + platform: ${PLATFORM:-} + entrypoint: tail + command: -f /dev/null + container_name: go + working_dir: ${PWD} + volumes: + - ${AGENT_CODE:-$PWD}:${PWD} + + php-base: + # image: scratch + platform: ${PLATFORM:-} + environment: + <<: [*mysql-env, *redis-env] + entrypoint: tail + command: -f /dev/null + working_dir: ${PWD} + volumes: + - ${AGENT_CODE:-$PWD}:${PWD}