Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Blackfire CLI #188

Merged
merged 4 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## UNRELEASED [x.y.z](https://github.com/davidalger/warden/tree/x.y.z) (yyyy-mm-dd)
[All Commits](https://github.com/davidalger/warden/compare/0.6.0..develop)

**Enhancements:**

* Added `warden blackfire` command for easily running profiles via the CLI tool ([#188](https://github.com/davidalger/warden/pull/188) by @navarr)

## Version [0.6.0](https://github.com/davidalger/warden/tree/0.6.0) (2020-07-02)
[All Commits](https://github.com/davidalger/warden/compare/0.5.3..0.6.0)

Expand Down
16 changes: 16 additions & 0 deletions commands/blackfire.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
[[ ! ${WARDEN_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1

WARDEN_ENV_PATH="$(locateEnvPath)" || exit $?
loadEnvConfig "${WARDEN_ENV_PATH}" || exit $?

## set defaults for this command which can be overriden either using exports in the user
## profile or setting them in the .env configuration on a per-project basis
WARDEN_ENV_BLACKFIRE_COMMAND=${WARDEN_ENV_BLACKFIRE_COMMAND:-blackfire}
WARDEN_ENV_BLACKFIRE_CONTAINER=${WARDEN_ENV_BLACKFIRE_CONTAINER:-php-blackfire}

## allow return codes from sub-process to bubble up normally
trap '' ERR

"${WARDEN_DIR}/bin/warden" env exec "${WARDEN_ENV_BLACKFIRE_CONTAINER}" \
"${WARDEN_ENV_BLACKFIRE_COMMAND}" "${WARDEN_PARAMS[@]}" "$@"
11 changes: 11 additions & 0 deletions commands/blackfire.help
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
[[ ! ${WARDEN_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1

WARDEN_USAGE=$(cat <<EOF
\033[33mUsage:\033[0m
blackfire [args]

\033[33mOptions:\033[0m
-h, --help Display this help menu
EOF
)
6 changes: 6 additions & 0 deletions docs/configuration/blackfire.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ BLACKFIRE_SERVER_TOKEN=<server_token>
```

Note: You can obtain the IDs and Tokens used in the above from within your Blackfire account under Account Settings -> Credentials or from the credentials are of the environment you're pushing profile information into.

### CLI Tool

To use the Blackfire CLI Tool, you can run `warden blackfire [arguments]`.

For more information on the CLI tool, please see [Profiling CLI Commands](https://blackfire.io/docs/cookbooks/profiling-cli) in Blackfire's documentation.
2 changes: 2 additions & 0 deletions environments/includes/blackfire.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ services:
- SSH_AUTH_SOCK=/tmp/ssh-auth.sock
- NODE_VERSION=${NODE_VERSION:-10}
- COMPOSER_MEMORY_LIMIT=-1
- BLACKFIRE_CLIENT_ID=${BLACKFIRE_CLIENT_ID}
- BLACKFIRE_CLIENT_TOKEN=${BLACKFIRE_CLIENT_TOKEN}
volumes: *volumes
extra_hosts: *extra_hosts
depends_on:
Expand Down
6 changes: 6 additions & 0 deletions images/php-fpm/blackfire/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ RUN yum install -y pygpgme \
&& yum clean all \
&& rm -rf /var/cache/yum

# Install the Blackfire Client to provide access to the CLI tool
RUN mkdir -p /tmp/blackfire \
&& curl -L https://blackfire.io/api/v1/releases/client/linux_static/amd64 | tar zxp -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire /usr/bin/blackfire \
&& rm -rf /tmp/blackfire

COPY blackfire/etc/php.d/*.ini /etc/php.d/

USER www-data