Skip to content

Commit

Permalink
Custom host and in-container commands, fixes #1372, fixes #1551 (#1702)
Browse files Browse the repository at this point in the history
* Also adds  `ddev mysql` and an example for `ddev mysqlworkbench`
  • Loading branch information
rfay committed Jul 18, 2019
1 parent 27b8fc1 commit 478da82
Show file tree
Hide file tree
Showing 486 changed files with 79,943 additions and 11,883 deletions.
60 changes: 30 additions & 30 deletions .circleci/config.yml
Expand Up @@ -11,12 +11,12 @@ jobs:
- run: sudo mkdir /home/linuxbrew && sudo chown $(id -u) /home/linuxbrew
- restore_cache:
keys:
- homebrew-linux-v4
- homebrew-linux-v5
- run:
command: ./.circleci/linux_circle_vm_setup.sh
name: NORMAL Circle VM setup - tools, docker, golang
- save_cache:
key: homebrew-linux-v4
key: homebrew-linux-v5
paths:
- /home/linuxbrew

Expand All @@ -42,13 +42,13 @@ jobs:
- run: sudo mkdir /home/linuxbrew && sudo chown $(id -u) /home/linuxbrew
- restore_cache:
keys:
- homebrew-linux-v4
- homebrew-linux-v5
# Run the built-in ddev tests with the executables just built.
- run:
command: ./.circleci/linux_circle_vm_setup.sh
name: Circle VM setup - tools, docker, golang
- save_cache:
key: homebrew-linux-v4
key: homebrew-linux-v5
paths:
- /home/linuxbrew

Expand All @@ -73,14 +73,14 @@ jobs:
at: ~/
- restore_cache:
keys:
- homebrew-macos-v4
- homebrew-macos-v5
# Run the built-in ddev tests with the executables just built.
- run:
command: ./.circleci/macos_circle_vm_setup.sh
name: macOS Circle VM setup - tools, docker, golang
# Now build using the regular ddev-only technique - this results in a fully clean set of executables.
- save_cache:
key: homebrew-macos-v4
key: homebrew-macos-v5
paths:
- /usr/local/Homebrew
- run:
Expand All @@ -103,7 +103,7 @@ jobs:
at: ~/
- restore_cache:
keys:
- homebrew-macos-v4
- homebrew-macos-v5
# Run the built-in ddev tests with the executables just built.
- run:
command: ./.circleci/macos_circle_vm_setup.sh
Expand All @@ -116,7 +116,7 @@ jobs:
- store_test_results:
path: /tmp/testresults
- save_cache:
key: homebrew-macos-v4
key: homebrew-macos-v5
paths:
- /usr/local/Homebrew

Expand All @@ -134,7 +134,7 @@ jobs:
at: ~/
- restore_cache:
keys:
- homebrew-macos-v4
- homebrew-macos-v5
# Run the built-in ddev tests with the executables just built.
- run:
command: ./.circleci/macos_circle_vm_setup.sh
Expand All @@ -147,7 +147,7 @@ jobs:
- store_test_results:
path: /tmp/testresults
- save_cache:
key: homebrew-macos-v4
key: homebrew-macos-v5
paths:
- /usr/local/Homebrew

Expand All @@ -164,13 +164,13 @@ jobs:
at: ~/
- restore_cache:
keys:
- homebrew-macos-v4
- homebrew-macos-v5
# Run the built-in ddev tests with the executables just built.
- run:
command: ./.circleci/macos_circle_vm_setup.sh
name: macOS Circle VM setup - tools, docker, golang
- save_cache:
key: homebrew-macos-v4
key: homebrew-macos-v5
paths:
- /usr/local/Homebrew
# Now build using the regular ddev-only technique - this results in a fully clean set of executables.
Expand All @@ -194,14 +194,14 @@ jobs:
- run: sudo mkdir /home/linuxbrew && sudo chown $(id -u) /home/linuxbrew
- restore_cache:
keys:
- homebrew-linux-v4
- homebrew-linux-v5
- attach_workspace:
at: ~/
- run:
command: ./.circleci/linux_circle_vm_setup.sh
name: Circle VM setup - tools, docker, golang
- save_cache:
key: homebrew-linux-v4
key: homebrew-linux-v5
paths:
- /home/linuxbrew

Expand All @@ -227,14 +227,14 @@ jobs:
- run: sudo mkdir /home/linuxbrew && sudo chown $(id -u) /home/linuxbrew
- restore_cache:
keys:
- homebrew-linux-v4
- homebrew-linux-v5
- attach_workspace:
at: ~/
- run:
command: ./.circleci/linux_circle_vm_setup.sh
name: Circle VM setup - tools, docker, golang
- save_cache:
key: homebrew-linux-v4
key: homebrew-linux-v5
paths:
- /home/linuxbrew
- run:
Expand All @@ -257,14 +257,14 @@ jobs:
- run: sudo mkdir /home/linuxbrew && sudo chown $(id -u) /home/linuxbrew
- restore_cache:
keys:
- homebrew-linux-v4
- homebrew-linux-v5
- attach_workspace:
at: ~/
- run:
command: ./.circleci/linux_circle_vm_setup.sh
name: Circle VM setup - tools, docker, golang
- save_cache:
key: homebrew-linux-v4
key: homebrew-linux-v5
paths:
- /home/linuxbrew
# Now build using the regular ddev-only technique - this results in a fully clean set of executables.
Expand All @@ -287,12 +287,12 @@ jobs:
- run: sudo mkdir /home/linuxbrew && sudo chown $(id -u) /home/linuxbrew
- restore_cache:
keys:
- homebrew-linux-v4
- homebrew-linux-v5
- run:
command: ./.circleci/linux_circle_vm_setup.sh
name: Circle VM setup - tools, docker, golang
- save_cache:
key: homebrew-linux-v4
key: homebrew-linux-v5
paths:
- /home/linuxbrew
- run:
Expand All @@ -308,12 +308,12 @@ jobs:
- run: sudo mkdir /home/linuxbrew && sudo chown $(id -u) /home/linuxbrew
- restore_cache:
keys:
- homebrew-linux-v4
- homebrew-linux-v5
- run:
command: ./.circleci/linux_circle_vm_setup.sh
name: Circle VM setup - tools, docker, golang
- save_cache:
key: homebrew-linux-v4
key: homebrew-linux-v5
paths:
- /home/linuxbrew
- run:
Expand All @@ -337,12 +337,12 @@ jobs:
- checkout
- restore_cache:
keys:
- homebrew-macos-v4
- homebrew-macos-v5
- run:
command: ./.circleci/macos_circle_vm_setup.sh
name: macOS Circle VM setup - tools, docker, golang
- save_cache:
key: homebrew-macos-v4
key: homebrew-macos-v5
paths:
- /usr/local/Homebrew
- run:
Expand All @@ -367,15 +367,15 @@ jobs:
- run: sudo mkdir /home/linuxbrew && sudo chown $(id -u) /home/linuxbrew
- restore_cache:
keys:
- homebrew-linux-v4
- homebrew-linux-v5
- attach_workspace:
at: ~/
- run:
command: ./.circleci/generate_artifacts.sh $ARTIFACTS
name: tar/zip up artifacts and make hashes
no_output_timeout: "40m"
- save_cache:
key: homebrew-linux-v4
key: homebrew-linux-v5
paths:
- /home/linuxbrew
- store_artifacts:
Expand All @@ -395,12 +395,12 @@ jobs:
- run: sudo mkdir /home/linuxbrew && sudo chown $(id -u) /home/linuxbrew
- restore_cache:
keys:
- homebrew-linux-v4
- homebrew-linux-v5
- run:
command: ./.circleci/linux_circle_vm_setup.sh
name: TAG BUILD Circle VM setup - tools, docker, golang
- save_cache:
key: homebrew-linux-v4
key: homebrew-linux-v5
paths:
- /home/linuxbrew

Expand Down Expand Up @@ -437,12 +437,12 @@ jobs:
- run: sudo mkdir /home/linuxbrew && sudo chown $(id -u) /home/linuxbrew
- restore_cache:
keys:
- homebrew-linux-v4
- homebrew-linux-v5
- run:
command: ./.circleci/linux_circle_vm_setup.sh
name: RELEASE BUILD Circle VM setup - tools, docker, golang
- save_cache:
key: homebrew-linux-v4
key: homebrew-linux-v5
paths:
- /home/linuxbrew

Expand Down
15 changes: 15 additions & 0 deletions Makefile
Expand Up @@ -4,6 +4,10 @@
# linux build and linuxbrew is installed.
export PATH := $(EXTRA_PATH):$(PATH)

# Not updating build-tools to get this, but this should be removed
# when build-tools is updated.
BUILD_IMAGE := drud/golang-build-container:v1.12.7

GOMETALINTER_ARGS := --vendored-linters --disable-all --enable=gofmt --enable=vet --enable vetshadow --enable=golint --enable=errcheck --enable=staticcheck --enable=ineffassign --enable=varcheck --enable=deadcode --deadline=4m
GOLANGCI_LINT_ARGS ?= --out-format=line-number --disable-all --enable=gofmt --enable=govet --enable=golint --enable=errcheck --enable=staticcheck --enable=ineffassign --enable=varcheck --enable=deadcode

Expand Down Expand Up @@ -102,6 +106,16 @@ setup:
@mkdir -p $(GOTMP)/{src,pkg/mod/cache,.cache}
@mkdir -p $(TESTTMP)

# packr2 target currently builds packr2 caches in the cmd/ddev/cmd directory only
# using the golang-build-container's packr2 command
packr2:
docker run -t --rm -u $(shell id -u):$(shell id -g) \
-v "$(S)$(PWD):/workdir$(DOCKERMOUNTFLAG)" \
-v "$(S)$(PWD)/$(GOTMP)/bin:$(S)/go/bin" \
-e GOCACHE="//workdir/$(GOTMP)/.cache" \
-w //workdir/cmd/ddev/cmd \
$(BUILD_IMAGE) packr2

# Required static analysis targets used in circleci - these cause fail if they don't work
staticrequired: setup golangci-lint

Expand Down Expand Up @@ -141,3 +155,4 @@ $(GOTMP)/bin/windows_amd64/nssm.exe $(GOTMP)/bin/windows_amd64/winnfsd_license.t
curl --fail -sSL -o /tmp/nssm.zip https://nssm.cc/ci/nssm-$(NSSM_VERSION).zip
unzip -oj /tmp/nssm.zip nssm-$(NSSM_VERSION)/win64/nssm.exe -d $(GOTMP)/bin/windows_amd64
curl --fail -sSL -o $(GOTMP)/bin/windows_amd64/winnfsd_license.txt https://www.gnu.org/licenses/gpl.txt

16 changes: 16 additions & 0 deletions cmd/ddev/cmd/assets/commands/db/README.txt
@@ -0,0 +1,16 @@
Scripts in this directory will be executed inside the db
container. A number of environment variables are supplied to the scripts, including:

DDEV_APPROOT: file system location of the project on the host)
DDEV_HOST_DB_PORT: Localhost port of the database server
DDEV_HOST_WEBSERVER_PORT: Localhost port of the webserver
DDEV_HOST_HTTPS_PORT: Localhost port for https on webserver
DDEV_DOCROOT: Relative path from approot to docroot
DDEV_HOSTNAME: Comma-separated list of FQDN hostnames
DDEV_PHP_VERSION
DDEV_WEBSERVER_TYPE: nginx-fpm, apache-fpm, apache-cgi
DDEV_PROJECT_TYPE: drupal8, typo3, backdrop, wordpress, etc.
DDEV_ROUTER_HTTP_PORT: Router port for http
DDEV_ROUTER_HTTPS_PORT: Router port for https

More environment variables may be available, see https://github.com/drud/ddev/blob/52c7915dee41d4846f9f619520b726994c0372c5/pkg/ddevapp/ddevapp.go#L1006-L1030
9 changes: 9 additions & 0 deletions cmd/ddev/cmd/assets/commands/db/mysql
@@ -0,0 +1,9 @@
#!/bin/bash

## #ddev-generated
## Description: run mysql client in web container
## Usage: mysql [flags] [args]
## Example: "ddev mysql" or "ddev mysql -uroot -proot -hdb" or "echo 'SHOW TABLES;' | ddev mysql"
## `ddev mysql mysql -uroot -proot` gets you to the 'mysql' database with root privileges

mysql -udb -pdb -hdb $@
18 changes: 18 additions & 0 deletions cmd/ddev/cmd/assets/commands/host/README.txt
@@ -0,0 +1,18 @@
Scripts in this directory will be executed on the host
but they can take easily take action on containers by using
`ddev exec`. A number of environment variables are supplied to the scripts
including:

DDEV_APPROOT: file system location of the project on the host)
DDEV_HOST_DB_PORT: Localhost port of the database server
DDEV_HOST_WEBSERVER_PORT: Localhost port of the webserver
DDEV_HOST_HTTPS_PORT: Localhost port for https on webserver
DDEV_DOCROOT: Relative path from approot to docroot
DDEV_HOSTNAME: Comma-separated list of FQDN hostnames
DDEV_PHP_VERSION
DDEV_WEBSERVER_TYPE: nginx-fpm, apache-fpm, apache-cgi
DDEV_PROJECT_TYPE: drupal8, typo3, backdrop, wordpress, etc.
DDEV_ROUTER_HTTP_PORT: Router port for http
DDEV_ROUTER_HTTPS_PORT: Router port for https

More environment variables may be available, see https://github.com/drud/ddev/blob/52c7915dee41d4846f9f619520b726994c0372c5/pkg/ddevapp/ddevapp.go#L1006-L1030
31 changes: 31 additions & 0 deletions cmd/ddev/cmd/assets/commands/host/mysqlworkbench.example
@@ -0,0 +1,31 @@
#!/bin/bash

## Description: Run MySQLWorkbench against current db
## Usage: mysqlworkbench
## Example: "ddev mysqlworkbench"

# Note that this examle uses $DDEV_HOST_DB_PORT to get the port for the connection
# Mysql Workbench can be obtained from https://dev.mysql.com/downloads/workbench/

query="root:root@127.0.0.1:${DDEV_HOST_DB_PORT}"

case $OSTYPE in
linux-gnu)
# You may need "apt-get install libproj-dev gnome-keyring" if it complains about those
mysql-workbench --query "$query" &
echo "Attempted to launch mysql-workbench"
;;

"darwin"*)
"/Applications/MySQLWorkbench.app/Contents/MacOS/MySQLWorkbench" --query "$query" &
echo "Attempted to launch MySQLWorkbench.app"
;;

"win*"* | "msys"*)
# 'C:\Program Files\MySQL\MySQL Workbench 8.0 CE\mysqlworkbench.exe'
# You may need to add it to your system %PATH% or change the path here
# On docker toolbox you'll need to change the query to use the toolbox IP address,
# likely 192.168.99.100
'C:\Program Files\MySQL\MySQL Workbench 8.0 CE\mysqlworkbench.exe' --query "$query"
#;;
esac
8 changes: 8 additions & 0 deletions cmd/ddev/cmd/assets/commands/host/phpstorm.example
@@ -0,0 +1,8 @@
#!/bin/bash

## Description: Open PHPStorm with the current project
## Usage: phpstorm
## Example: "ddev phpstorm"

# Example is macOS-specific, but easy to adapt to any OS
open -a PHPStorm.app ${DDEV_APPROOT}
10 changes: 10 additions & 0 deletions cmd/ddev/cmd/assets/commands/host/solrtail.example
@@ -0,0 +1,10 @@
#!/bin/bash

## Description: Tail the main solr log
## Usage: solrtail
## Example: ddev solrtail

# This can't work unless you have a solr service,
# See https://ddev.readthedocs.io/en/latest/users/extend/additional-services/#apache-solr

ddev exec -s solr tail -40lf /opt/solr/server/logs/solr.log
24 changes: 24 additions & 0 deletions cmd/ddev/cmd/assets/commands/solr/README.txt
@@ -0,0 +1,24 @@
Scripts in this directory will be executed inside the solr
container (if it exists, of course). This is just an example,
but any named service can have a directory with commands.

Note that /mnt/ddev_config must be mounted into the 3rd-party service
with a stanza like this in the docker-compose.solr.yaml:

volumes:
- type: "bind"
source: "."
target: "/mnt/ddev_config"


A number of environment variables are supplied to the scripts, including:

DDEV_DOCROOT: Relative path from approot to docroot
DDEV_HOSTNAME: Comma-separated list of FQDN hostnames
DDEV_PHP_VERSION
DDEV_WEBSERVER_TYPE: nginx-fpm, apache-fpm, apache-cgi
DDEV_PROJECT_TYPE: drupal8, typo3, backdrop, wordpress, etc.
DDEV_ROUTER_HTTP_PORT: Router port for http
DDEV_ROUTER_HTTPS_PORT: Router port for https

More environment variables may be available, see https://github.com/drud/ddev/blob/52c7915dee41d4846f9f619520b726994c0372c5/pkg/ddevapp/ddevapp.go#L1006-L1030

0 comments on commit 478da82

Please sign in to comment.