Skip to content

Commit 507a55a

Browse files
piggitoandypost
authored andcommitted
Use new relic via docker-compose 2.4 features
https://docs.docker.com/compose/compose-file/#extension-fields
1 parent 2dc649e commit 507a55a

File tree

7 files changed

+50
-57
lines changed

7 files changed

+50
-57
lines changed

.gitlab-ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Variables to add in Gitalb UI : Settings > CI/CD
22
# - SONAR_HOST // Optional
33
# - SONAR_TOKEN // Optional
4+
# - NEW_RELIC_LICENSE_KEY // Optional
45

56
variables:
6-
GIT_DEPTH: "3"
7+
GIT_DEPTH: "10"
78
THEME_PATH: "" # Update to enable front jobs (web/themes/custom/XXX)
89
STORYBOOK_PATH: "" # Update to enable storybook job (themes/custom/XXX/dist/storybook/index.html)
9-
GIT_STRATEGY: clone # Workaround until git is updated in runner, see https://gitlab.com/gitlab-org/gitlab-foss/issues/60466
10+
GIT_STRATEGY: fetch
1011
REVIEW_DOMAIN: "XXX.XXX.com" # Mandatory, should equal to DNS of available runner server with docker + docker-compose + traefik
1112

1213
image: skilldlabs/php:73

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ endif
7474
$(call php-0, apk add --no-cache tzdata $(ADD_PHP_EXT))
7575
# Set up timezone
7676
$(call php-0, cp /usr/share/zoneinfo/Europe/Paris /etc/localtime)
77+
# Install newrelic PHP extension if NEW_RELIC_LICENSE_KEY defined
78+
make -s newrelic
7779
$(call php-0, kill -USR2 1)
7880
$(call php, composer global require -o --update-no-dev --no-suggest "hirak/prestissimo:^0.3")
7981

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ networks:
118118
* `make lint` - Runs frontend linters.
119119
* `make storybook` - Runs storybook in current theme.
120120
* `make blackfire` - Adds and enables blackfire.io php extension, needs [configuration](https://blackfire.io/docs/configuration/php) in docker-composer override.yml.
121-
* `make newrelic` - Adds and enables newrelic.com php extension, needs [configuration](https://docs.newrelic.com/docs/agents/php-agent/getting-started/introduction-new-relic-php#configuration) in docker-composer.override.yml.
121+
* `make newrelic` - Adds and enables newrelic.com php extension, needs [configuration](https://docs.newrelic.com/docs/agents/php-agent/getting-started/introduction-new-relic-php#configuration) `NEW_RELIC_LICENSE_KEY` environment variable defined with valid license key.
122122

123123
#### Additional goals
124124

docker/docker-compose.override.yml.default

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
version: "2.4"
22

3+
x-service-defaults:
4+
&service-defaults
5+
restart: always
6+
networks:
7+
- front
8+
9+
x-service-rewrelic:
10+
&service-newrelic
11+
newrelic:
12+
<<: *service-defaults
13+
image: newrelic/php-daemon
14+
container_name: "${COMPOSE_PROJECT_NAME}_newrelic"
15+
316
services:
17+
# <<: *service-newrelic
418

519
# Override base service.
620
php:
721
environment:
822
COMPOSER_MEMORY_LIMIT: "-1"
923
# BLACKFIRE_CLIENT_ID: x
1024
# BLACKFIRE_CLIENT_TOKEN: x
11-
# NEW_RELIC_LICENSE_KEY: x
1225
# NEW_RELIC_APPNAME: "${COMPOSE_PROJECT_NAME}"
1326
volumes:
1427
- "./90-mail.ini:/etc/php7/conf.d/90-mail.ini:z"
@@ -22,32 +35,25 @@ services:
2235
# Then download extension using "make blackfire"
2336

2437
# blackfire:
38+
# <<: *service-defaults
2539
# image: blackfire/blackfire
2640
# container_name: "${COMPOSE_PROJECT_NAME}_blackfire"
2741
# environment:
2842
# BLACKFIRE_SERVER_ID: x
2943
# BLACKFIRE_SERVER_TOKEN: x
3044
# BLACKFIRE_LOG_LEVEL: 1
31-
# networks:
32-
# - front
33-
34-
# newrelic:
35-
# image: newrelic/php-daemon
36-
# container_name: "${COMPOSE_PROJECT_NAME}_newrelic"
37-
# networks:
38-
# - front
3945

4046
# adminer:
47+
# <<: *service-defaults
4148
# image: adminer:standalone
4249
# container_name: "${COMPOSE_PROJECT_NAME}_adminer"
4350
# links:
4451
# - mysql:mysql
4552
# depends_on:
4653
# - mysql
47-
# networks:
48-
# - front
4954

5055
# mysql:
56+
# <<: *service-defaults
5157
# image: percona:5.7
5258
# container_name: "${COMPOSE_PROJECT_NAME}_mysql"
5359
# volumes:
@@ -57,11 +63,9 @@ services:
5763
# MYSQL_USER: d8
5864
# MYSQL_PASSWORD: d8
5965
# MYSQL_ROOT_PASSWORD: d8root
60-
# restart: always
61-
# networks:
62-
# - front
6366

6467
# postgresql:
68+
# <<: *service-defaults
6569
# image: postgres:12.2-alpine
6670
# container_name: "${COMPOSE_PROJECT_NAME}_pgsql"
6771
# volumes:
@@ -71,16 +75,11 @@ services:
7175
# POSTGRES_USER: d9
7276
# POSTGRES_PASSWORD: d9root
7377
# PGDATA: /var/lib/postgresql/data
74-
# restart: always
75-
# networks:
76-
# - front
7778

7879
mailhog:
80+
<<: *service-defaults
7981
image: skilldlabs/mailhog
8082
container_name: "${COMPOSE_PROJECT_NAME}_mail"
81-
restart: always
82-
networks:
83-
- front
8483
labels:
8584
- 'traefik.enable=true'
8685
# Treafik 1.x
@@ -127,10 +126,3 @@ services:
127126
# - 'traefik.http.routers.solr-${COMPOSE_PROJECT_NAME}.tls=true'
128127
# - 'traefik.http.services.solr-${COMPOSE_PROJECT_NAME}.loadbalancer.server.port=8983'
129128

130-
#networks:
131-
# front:
132-
# driver: bridge
133-
# ipam:
134-
# driver: default
135-
# config:
136-
# - subnet: "${IPRANGE}"

docker/docker-compose.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
version: "2.4"
22

3+
x-service-defaults:
4+
&service-defaults
5+
restart: always
6+
networks:
7+
- front
8+
39
services:
410

511
php:
12+
<<: *service-defaults
613
image: ${IMAGE_PHP}
714
container_name: "${COMPOSE_PROJECT_NAME}_php"
815
volumes:
916
- ../:/var/www/html:z
1017
- ../drush/.drushrc.php:/home/www-data/.drushrc.php:z
11-
restart: always
12-
networks:
13-
- front
1418
# environment:
1519
# REDIS_HOST: ${REDIS_HOST}
1620
# REDIS_PORT: ${REDIS_PORT}
@@ -21,17 +25,16 @@ services:
2125
# - redis:redis
2226

2327
nginx:
28+
<<: *service-defaults
2429
image: ${IMAGE_NGINX}
2530
container_name: "${COMPOSE_PROJECT_NAME}_web"
2631
depends_on:
2732
- php
2833
volumes_from:
2934
- php
30-
restart: always
31-
networks:
32-
- front
3335

3436
# solr:
37+
# <<: *service-defaults
3538
# image: ${IMAGE_SOLR}
3639
# container_name: "${COMPOSE_PROJECT_NAME}_solr"
3740
# volumes:
@@ -41,16 +44,12 @@ services:
4144
# - solr-precreate
4245
# - ${COMPOSE_PROJECT_NAME}
4346
# - /solr-conf
44-
# networks:
45-
# - front
4647

4748
# redis:
49+
# <<: *service-defaults
4850
# image: ${IMAGE_REDIS}
4951
# container_name: "${COMPOSE_PROJECT_NAME}_redis"
5052
# command: redis-server --maxmemory-policy allkeys-lru --requirepass ${REDIS_PASSWD}
51-
# restart: always
52-
# networks:
53-
# - front
5453

5554
networks:
5655
front:

scripts/makefile/newrelic.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@
66
PHP_INI_DIR=/etc/php7/conf.d
77

88
# get the latest version from https://download.newrelic.com/php_agent/archive/
9-
NEW_RELIC_AGENT_VERSION="${NEW_RELIC_AGENT_VERSION:-9.12.0.268}"
9+
NEW_RELIC_AGENT_VERSION="${NEW_RELIC_AGENT_VERSION:-9.13.0.270}"
1010
# change it to 'linux' if docker image is not based on Alpinelinux
1111
NEW_RELIC_LINUX=${NEW_RELIC_LINUX:-linux-musl}
1212

1313
set -e
1414

15-
env_vars='NEW_RELIC_APPNAME NEW_RELIC_LICENSE_KEY'
16-
17-
for var in $env_vars; do
18-
eval "val=\${$var}"
19-
if [ -z "${val}" -o "${val}" = 'x' ]; then
20-
echo "Configure ${var} in docker-compose.override.yml"
21-
echo "Visit https://newrelic.com 'Account settings' to get the key"; exit 1;
22-
fi
23-
done
15+
# Print help in case parameters are empty
16+
if [ -z "$1" ] || [ -z "$2" ]
17+
then
18+
echo "Visit https://newrelic.com 'Account settings' to get the license key";
19+
exit 1 # Exit script after printing help
20+
fi
21+
NEW_RELIC_LICENSE_KEY="$1"
22+
NEW_RELIC_APPNAME="$2"
2423

2524
curl -L https://download.newrelic.com/php_agent/archive/${NEW_RELIC_AGENT_VERSION}/newrelic-php5-${NEW_RELIC_AGENT_VERSION}-${NEW_RELIC_LINUX}.tar.gz | tar -C /tmp -zx \
2625
&& export NR_INSTALL_USE_CP_NOT_LN=1 \

scripts/makefile/tests.mk

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ else
199199
endif
200200

201201
newrelic:
202-
ifneq ("$(wildcard scripts/makefile/newrelic.sh)","")
203-
$(call php-0, /bin/sh ./scripts/makefile/newrelic.sh)
204-
$(call php-0, kill -USR2 1)
205-
@echo "NewRelic extension enabled"
202+
ifdef NEW_RELIC_LICENSE_KEY
203+
$(call php-0, /bin/sh ./scripts/makefile/newrelic.sh $(NEW_RELIC_LICENSE_KEY) '$(COMPOSE_PROJECT_NAME)')
204+
$(call php, sed -i -e 's/# <<: \*service-newrelic/ <<: \*service-newrelic/g' docker/docker-compose.override.yml)
205+
docker-compose up -d
206+
@echo "NewRelic PHP extension enabled"
206207
else
207-
@echo "scripts/makefile/newrelic.sh file does not exist"
208-
@exit 1
208+
@echo "NewRelic install skipped as NEW_RELIC_LICENSE_KEY is not set"
209209
endif

0 commit comments

Comments
 (0)