Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 9e7316a

Browse files
authored
Add Circle CI config (#1)
1 parent 12ea81d commit 9e7316a

8 files changed

Lines changed: 236 additions & 2 deletions

File tree

Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2018 OpenCensus Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
ARG BASE_IMAGE
16+
FROM $BASE_IMAGE
17+
18+
RUN mkdir -p /build && \
19+
apt-get update -y && \
20+
apt-get install -y -q --no-install-recommends \
21+
build-essential \
22+
g++ \
23+
gcc \
24+
libc-dev \
25+
make \
26+
autoconf \
27+
git \
28+
unzip
29+
30+
COPY . /build/
31+
32+
WORKDIR /build/
33+
34+
RUN EXPECTED_SIGNATURE=$(curl -f https://composer.github.io/installer.sig) && \
35+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
36+
ACTUAL_SIGNATURE=$(php -r "echo (hash_file('SHA384', 'composer-setup.php'));") && \
37+
test $EXPECTED_SIGNATURE = $ACTUAL_SIGNATURE && \
38+
php composer-setup.php && \
39+
php -r "unlink('composer-setup.php');"
40+
41+
RUN php composer.phar install && \
42+
vendor/bin/phpcs --standard=./phpcs-ruleset.xml && \
43+
vendor/bin/phpunit
44+
45+
RUN pecl install opencensus-alpha && \
46+
php -dextension=opencensus.so vendor/bin/phpunit

circle.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
machine:
2+
timezone: America/Los_Angeles
3+
environment:
4+
GCLOUD_DIR: ${HOME}/gcloud
5+
PATH: ${GCLOUD_DIR}/google-cloud-sdk/bin:${PATH}
6+
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
7+
CLOUDSDK_ACTIVE_CONFIG_NAME: opencensus-php
8+
TEST_BUILD_DIR: ${HOME}
9+
PHP_DOCKER_GOOGLE_CREDENTIALS: ${HOME}/credentials.json
10+
GOOGLE_PROJECT_ID: php-stackdriver
11+
TAG: circle-${CIRCLE_BUILD_NUM}
12+
13+
dependencies:
14+
override:
15+
- scripts/install_test_dependencies.sh
16+
17+
test:
18+
override:
19+
- scripts/run_test_suite.sh

cloudbuild.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This cloudbuild.yaml is used to test the php extension against multiple versions of php
2+
steps:
3+
- name: gcr.io/cloud-builders/docker
4+
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.1', '.']
5+
waitFor: ['-']
6+
id: php71-nts
7+
- name: gcr.io/cloud-builders/docker
8+
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.1-zts', '.']
9+
waitFor: ['-']
10+
id: php71-zts
11+
- name: gcr.io/cloud-builders/docker
12+
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.0', '.']
13+
waitFor: ['-']
14+
id: php70-nts
15+
- name: gcr.io/cloud-builders/docker
16+
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.0-zts', '.']
17+
waitFor: ['-']
18+
id: php70-zts
19+
- name: gcr.io/cloud-builders/docker
20+
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.2', '.']
21+
waitFor: ['-']
22+
id: php72-nts
23+
- name: gcr.io/cloud-builders/docker
24+
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.2-zts', '.']
25+
waitFor: ['-']
26+
id: php72-zts
27+
- name: gcr.io/cloud-builders/docker
28+
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/php-stackdriver/php71-32bit', '.']
29+
waitFor: ['-']
30+
id: php71-32bit
31+
- name: gcr.io/cloud-builders/docker
32+
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/php-stackdriver/php70-32bit', '.']
33+
waitFor: ['-']
34+
id: php70-32bit
35+
- name: gcr.io/cloud-builders/docker
36+
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/php-stackdriver/php71-debug', '.']
37+
waitFor: ['-']
38+
id: php71-debug

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"opencensus/opencensus": "^0.2"
88
},
99
"require-dev": {
10-
"phpunit/phpunit": "^7.0",
11-
"squizlabs/php_codesniffer": "2.*",
10+
"phpunit/phpunit": "^6.0",
11+
"squizlabs/php_codesniffer": "2.*"
1212
},
1313
"license": "Apache-2.0",
1414
"authors": [

phpcs-ruleset.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Google-Cloud-PHP-PSR2">
3+
<rule ref="PSR2" />
4+
<file>src</file>
5+
</ruleset>

scripts/dump_credentials.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright 2018 OpenCensus Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* Dumps the contents of the environment variable GOOGLE_CREDENTIALS_BASE64 to
20+
* a file.
21+
*
22+
* To setup Travis to run on your fork, read TRAVIS.md.
23+
*/
24+
if (getenv('GOOGLE_CREDENTIALS_BASE64') === false) {
25+
exit(0);
26+
}
27+
file_put_contents(
28+
getenv('PHP_DOCKER_GOOGLE_CREDENTIALS'),
29+
base64_decode(getenv('GOOGLE_CREDENTIALS_BASE64'))
30+
);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2018 OpenCensus Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# A script for installing necessary software on CI systems.
17+
18+
set -ex
19+
20+
if [ "${INSTALL_GCLOUD}" == "true" ]; then
21+
# Install gcloud
22+
if [ ! -d ${HOME}/gcloud/google-cloud-sdk ]; then
23+
mkdir -p ${HOME}/gcloud &&
24+
wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz --directory-prefix=${HOME}/gcloud &&
25+
cd "${HOME}/gcloud" &&
26+
tar xzf google-cloud-sdk.tar.gz &&
27+
./google-cloud-sdk/install.sh --usage-reporting false --path-update false --command-completion false &&
28+
cd "${TEST_BUILD_DIR}";
29+
fi
30+
fi
31+
32+
if [ -z "${CLOUDSDK_ACTIVE_CONFIG_NAME}" ]; then
33+
echo "You need to set CLOUDSDK_ACTIVE_CONFIG_NAME envvar."
34+
exit 1
35+
fi
36+
37+
if [ -z "${GOOGLE_PROJECT_ID}" ]; then
38+
echo "You need to set GOOGLE_PROJECT_ID envvar."
39+
exit 1
40+
fi
41+
42+
if [ -z "${CLOUDSDK_VERBOSITY}" ]; then
43+
CLOUDSDK_VERBOSITY='none'
44+
fi
45+
46+
# gcloud configurations
47+
gcloud config configurations create ${CLOUDSDK_ACTIVE_CONFIG_NAME} || /bin/true # ignore failure
48+
gcloud config set project ${GOOGLE_PROJECT_ID}
49+
gcloud config set app/promote_by_default false
50+
gcloud config set verbosity ${CLOUDSDK_VERBOSITY}
51+
52+
# Dump the credentials from the environment variable.
53+
php scripts/dump_credentials.php
54+
55+
# Set the timeout
56+
gcloud config set container/build_timeout 3600
57+
58+
if [ ! -f "${PHP_DOCKER_GOOGLE_CREDENTIALS}" ]; then
59+
echo 'Please set PHP_DOCKER_GOOGLE_CREDENTIALS envvar.'
60+
exit 1
61+
fi
62+
63+
# Use the service account for gcloud operations.
64+
gcloud auth activate-service-account \
65+
--key-file "${PHP_DOCKER_GOOGLE_CREDENTIALS}"
66+
67+
if [ "${CIRCLECI}" == "true" ]; then
68+
# Need sudo on circleci:
69+
# https://discuss.circleci.com/t/gcloud-components-update-version-restriction/3725
70+
# They also overrides the PATH to use
71+
# /opt/google-cloud-sdk/bin/gcloud so we can not easily use our
72+
# own gcloud
73+
sudo /opt/google-cloud-sdk/bin/gcloud -q components update beta
74+
else
75+
gcloud -q components update beta
76+
fi

scripts/run_test_suite.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2018 OpenCensus Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# A script for installing necessary software on CI systems.
17+
18+
set -ex
19+
20+
gcloud container builds submit --config=cloudbuild.yaml .

0 commit comments

Comments
 (0)