Skip to content

Commit

Permalink
Merge branch 'master' into shell-run-as-root
Browse files Browse the repository at this point in the history
  • Loading branch information
roborourke authored Dec 20, 2019
2 parents 20e760b + b33b667 commit 024590a
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 26 deletions.
11 changes: 7 additions & 4 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ x-php: &php
condition: service_started
mailhog:
condition: service_started
image: humanmade/altis-local-server-php:3.0.0
image: humanmade/altis-local-server-php:3.1.0
links:
- "db:db-read-replica"
- "s3:s3.localhost"
Expand All @@ -22,6 +22,7 @@ x-php: &php
volumes:
- "${VOLUME}:/usr/src/app:delegated"
- "${PWD}/php.ini:/usr/local/etc/php/conf.d/altis.ini"
- socket:/var/run/php-fpm
environment:
HOST_PATH: ${VOLUME}
DB_HOST: db
Expand Down Expand Up @@ -83,18 +84,19 @@ services:
- '6379'
php:
<<: *php
image: ${PHP_IMAGE:-humanmade/altis-local-server-php:3.0.0}
image: ${PHP_IMAGE:-humanmade/altis-local-server-php:3.1.0}
ports:
- '9000'
nginx:
image: humanmade/altis-local-server-nginx:1.0.0
image: humanmade/altis-local-server-nginx:3.1.0
networks:
- proxy
- default
depends_on:
- php
volumes:
- "${VOLUME}:/usr/src/app:delegated"
- socket:/var/run/php-fpm
ports:
- "8080"
labels:
Expand Down Expand Up @@ -160,7 +162,7 @@ services:
- "traefik.docker.network=proxy"
- "traefik.frontend.rule=HostRegexp:s3-${COMPOSE_PROJECT_NAME:-default}.altis.dev;AddPrefix:/s3-${COMPOSE_PROJECT_NAME:-default}"
tachyon:
image: humanmade/tachyon:1.3.0
image: humanmade/tachyon:2.2.1
ports:
- "8080"
networks:
Expand Down Expand Up @@ -236,3 +238,4 @@ volumes:
es-data:
tmp:
s3:
socket:
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Navigate your shell to your project's directory. You should already have install

## Starting the Local Server

To start the Local Server, simply run `composer local-server start`. The first time you this will download all the necessary Docker images.
To start the Local Server, simply run `composer server`. The first time you this will download all the necessary Docker images.

Once the initial install and download has completed, you should see the output:

Expand Down Expand Up @@ -45,4 +45,4 @@ The subdomain used for the project can be configured via the `modules.local-serv

## Stopping the Local Server

To stop the Local Server containers, simply run `composer local-server stop`.
To stop the Local Server containers, simply run `composer server stop`.
Binary file added docs/assets/kibana-dev-tools.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/kibana-discover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/kibana-index-patterns.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions docs/cli.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# Running CLI Commands

You can run any command on the web server container using the `composer local-server exec` command. You need to prepend the command with the options delimiter `--`.
You can run any command on the web server container using the `composer server exec` command. You need to prepend the command with the options delimiter `--`.

For example to run a composer installed binary like `phpcs` run:

```sh
composer local-server exec -- vendor/bin/phpcs
composer server exec -- vendor/bin/phpcs
```

Or to show all environment variables:

```sh
composer local-server exec -- printenv
composer server exec -- printenv
```

## WP CLI

Local Server provides special support for [WP CLI](https://wp-cli.org/) commands via the `composer local-server cli --` command. Prepend all your commends with `composer local-server cli --` and drop the proceeding `wp`. For example, to list all posts:
Local Server provides special support for [WP CLI](https://wp-cli.org/) commands via the `composer server cli --` command. Prepend all your commends with `composer server cli --` and drop the proceeding `wp`. For example, to list all posts:

```sh
composer local-server cli -- post list
composer server cli -- post list
```

To install a new language file and activate it:

```sh
composer local-server cli -- language core install fr_FR
composer server cli -- language core install fr_FR
```

CLI commands via Local Server also support piping, for example import a database SQL file:

```sh
composer local-server cli -- db import - < ~/Downloads/database.sql
composer server cli -- db import - < ~/Downloads/database.sql
```
50 changes: 50 additions & 0 deletions docs/elasticsearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ElasticSearch

ElasticSearch is an integral component of Altis, enabling enhanced search and relevancy as well as powering the analytics data query layer.

## Kibana

Local Server provides [Kibana](https://www.elastic.co/products/kibana) out of the box, a powerful tool for viewing indexes, creating and debugging queries and more.

Kibana is available at [`/kibana/`](internal://site/kibana/).

### Adding Index Patterns

Before you can get started querying in Kibana you'll need to [add some index patterns at `/kibana/app/kibana#/management/kibana/index/`](internal://site/kibana/app/kibana#/management/kibana/index/).

![Kibana Index Patterns UI](./assets/kibana-index-patterns.png)

Enter an index pattern into the field (available indexes are shown below) using wildcards if you wish to work across multiple indexes at a time. You will then be prompted to choose a date field to use for time series filters, make your selection, for example `post_date`, and save your index pattern to start analysing your data.

You can add additional index patterns from the Kibana Management page in future.

**Note**: When adding an index pattern for the `analytics` index choose "I don't want to use the Time Filter" from the dropdown on the next screen. Analytics event timestamps are stored in milliseconds and Kibana's time filter does not currently work with this by default.

### Developing & Debugging Queries

Use the [Dev Tools tab at `/kibana/app/kibana#/dev_tools/console`](internal://site/kibana/app/kibana#/dev_tools/console) to enter and run queries. This provides useful features including autocomplete based on your data and linting.

![Kibana Dev Tools panel](./assets/kibana-dev-tools.png)

### Viewing & Understanding Data

The easiest way to view your data is in the [Discover tab at `/kibana/app/kibana#/discover`](internal://site/kibana/app/kibana#/discover). Here you can create basic queries, select and sort by columns as well drill down into the indexed data to see it's structure and data types.

![Kibana Discover panel](./assets/kibana-discover.png)


## Accessing ElasticSearch Directly

The ElasticSearch hostname is not directly exposed however you can find the dynamic port and IP to connect to by running `composer server status | grep elasticsearch`.

You should see output similar to this:

<pre><code>
project_elasticsearch_1 /elastic-entrypoint.sh ela ... Up (healthy) <strong>0.0.0.0:32871</strong>->9200/tcp, 9300/tcp
</code></pre>

Copy the mapped IP and port (highlighted in bold above) and use it to query ElasticSearch directly:

```
curl -XGET http://0.0.0.0:32871
```
4 changes: 2 additions & 2 deletions docs/email-debugging.md → docs/email.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Email Debugging
# Email

Local server comes with [Mailhog](https://github.com/mailhog/Mailhog) pre-configured. This is an app that catches all outgoing email and provides a UI to view and debug those emails.

The app is available at [`https://<project>.altis.dev/mailhog/`](internal://site/mailhog/).
The app is available at [`/mailhog/`](internal://site/mailhog/).
8 changes: 6 additions & 2 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Getting the Local Server status

To get details on the running Local Server status and containers, run `composer local-server status`. You should see output similar to:
To get details on the running Local Server status and containers, run `composer server status`. You should see output similar to:

```sh
Name Command State Ports
Expand All @@ -18,7 +18,7 @@ my-site_tachyon_1 node server.js --debug Up 0.0.0.0:8081
my-site_xray_1 /usr/bin/xray -b 0.0.0.0:2000 Up 0.0.0.0:32817->2000/tcp, 2000/udp
```

All containers should have a status of "Up". If they do not, you can inspect the logs for each service by running `composer local-server logs <service>`, for example, if `site_db_1` shows a status other than "Up", run `composer local-server logs db`.
All containers should have a status of "Up". If they do not, you can inspect the logs for each service by running `composer server logs <service>`, for example, if `site_db_1` shows a status other than "Up", run `composer server logs db`.

## Services keep stopping

Expand All @@ -27,3 +27,7 @@ By default docker machine sets a default memory limit of 2GB for all of your con
In the docker GUI go to the "Preferences" pane, then the "Advanced" tab and move the memory slider up.

![Docker Advanced Settings](./assets/docker-gui-advanced.png)

## Windows 10 Home Edition

Docker Desktop for Windows uses Windows-native Hyper-V virtualization and networking, which is not available in the Windows 10 Home edition. If you are using Windows 10 Home Edition you will need to use the [Local Chassis](docs://local-chassis) environment.
6 changes: 3 additions & 3 deletions docs/php-debugging.md → docs/using-xdebug.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Debugging PHP
# Using XDebug

Bugs are an inevitability of writing code and so Local Server provides an easy way to enable [XDebug](https://xdebug.org/) when you need it.

Expand All @@ -9,7 +9,7 @@ XDebug is _not enabled by default_ because it slows PHP down considerably. This
When you need to run your debug client you can append the option `--xdebug` to the start command:

```
composer local-server start --xdebug
composer server --xdebug
```

**Note**: you do not need to stop the server first to run the above command.
Expand All @@ -19,7 +19,7 @@ composer local-server start --xdebug
You can start the server again without the `--xdebug` option at any time to deactivate XDebug:

```
composer local-server start
composer server
```

## Connecting to XDebug
Expand Down
2 changes: 1 addition & 1 deletion docs/viewing-logs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Viewing Logs

Often you'll want to access logs from the services that Local Server provides. For example, PHP Errors Logs, Nginx Access Logs, or MySQL Logs. To do so, run the `composer local-server logs <service>` command. `<service>` can be any of `php`, `nginx`, `db`, `elasticsearch`, `s3`, `xray`, `cavalcade` or `redis`. This command will tail the logs (live update). To exit the log view, press `Ctrl+C`.
Often you'll want to access logs from the services that Local Server provides. For example, PHP Errors Logs, Nginx Access Logs, or MySQL Logs. To do so, run the `composer server logs <service>` command. `<service>` can be any of `php`, `nginx`, `db`, `elasticsearch`, `s3`, `xray`, `cavalcade` or `redis`. This command will tail the logs (live update). To exit the log view, press `Ctrl+C`.
16 changes: 11 additions & 5 deletions inc/composer/class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@

class Command extends BaseCommand {
protected function configure() {
$this->setName( 'local-server' )
->setDescription( 'Local server.' )
$this
->setName( 'server' )
->setDescription( 'Altis Local Server' )
->setDefinition( [
new InputArgument( 'subcommand', null, 'start, stop, restart, cli, shell, status. logs.' ),
new InputArgument( 'subcommand', null, 'start, stop, restart, cli, exec. shell, status. logs.' ),
new InputArgument( 'options', InputArgument::IS_ARRAY ),
] )
->setAliases( [ 'local-server' ] )
->setHelp(
<<<EOT
Run the local development server.
To start the local development server:
Default command - start the local development server:
start [--xdebug] passing --xdebug starts the server with xdebug enabled
Stop the local development server:
stop
Expand Down Expand Up @@ -72,6 +74,9 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
return $this->logs( $input, $output );
} elseif ( $subcommand === 'shell' ) {
return $this->shell( $input, $output );
} elseif ( $subcommand === null ) {
// Default to start command.
return $this->start( $input, $output );
}

$output->writeln( '<error>' . $subcommand . ' command not found.</>' );
Expand All @@ -97,10 +102,11 @@ protected function start( InputInterface $input, OutputInterface $output ) {
'VOLUME' => getcwd(),
'COMPOSE_PROJECT_NAME' => $this->get_project_subdomain(),
'PATH' => getenv( 'PATH' ),
'ES_MEM_LIMIT' => getenv( 'ES_MEM_LIMIT' ) ?: '1g',
];

if ( $input->getOption( 'xdebug' ) ) {
$env['PHP_IMAGE'] = 'humanmade/altis-local-server-php:3.0.0-dev';
$env['PHP_IMAGE'] = 'humanmade/altis-local-server-php:3.1.0-dev';
$env['PHP_XDEBUG_ENABLED'] = true;
}

Expand Down

0 comments on commit 024590a

Please sign in to comment.