Skip to content

Commit

Permalink
refactor: launch ddev phpmyadmin by port (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
stasadev authored Jul 6, 2024
1 parent 8123f59 commit 4a9fd7c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 53 deletions.
55 changes: 3 additions & 52 deletions commands/host/phpmyadmin
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,11 @@
## Usage: phpmyadmin
## Example: "ddev phpmyadmin"

if [ "${DDEV_PROJECT_STATUS-running}" != "running" ] && [ -z "$no_recursion" ]; then
echo "Project ${DDEV_PROJECT} is not running, starting it"
ddev start
start_exit_code=$?
if [ $start_exit_code -ne 0 ]; then
exit $start_exit_code
fi
# run this script again, as the environment is updated after "ddev start"
no_recursion=true ddev "$(basename "$0")" "$@"
exit $?
fi

DDEV_PHPMYADMIN_PORT=8036
DDEV_PHPMYADMIN_HTTPS_PORT=8037

FULLURL=${DDEV_PRIMARY_URL}
HTTPS=""
if [ ${DDEV_PRIMARY_URL%://*} = "https" ]; then HTTPS=true; fi

if [[ ! -z "${GITPOD_INSTANCE_ID}" ]] || [[ "${CODESPACES}" == "true" ]]; then
FULLURL="${FULLURL/-${DDEV_HOST_WEBSERVER_PORT}/-${DDEV_PHPMYADMIN_PORT}}"
if [ ${DDEV_PRIMARY_URL%://*} = "https" ]; then
ddev launch $DDEV_PRIMARY_URL:$DDEV_PHPMYADMIN_HTTPS_PORT
else
if [ "${HTTPS}" = "" ]; then
FULLURL="${FULLURL%:[0-9]*}:${DDEV_PHPMYADMIN_PORT}"
else
FULLURL="${FULLURL%:[0-9]*}:${DDEV_PHPMYADMIN_HTTPS_PORT}"
fi
fi

if [ -n "${1:-}" ] ; then
if [[ ${1::1} != "/" ]] ; then
FULLURL="${FULLURL}/";
fi

FULLURL="${FULLURL}${1}";
fi

if [ "${DDEV_DEBUG:-}" = "true" ]; then
printf "FULLURL $FULLURL\n" && exit 0
ddev launch $DDEV_PRIMARY_URL:$DDEV_PHPMYADMIN_PORT
fi

case $OSTYPE in
linux-gnu)
if [[ ! -z "${GITPOD_INSTANCE_ID}" ]]; then
gp preview ${FULLURL}
else
xdg-open ${FULLURL}
fi
;;
"darwin"*)
open ${FULLURL}
;;
"win*"* | "msys"*)
start ${FULLURL}
;;
esac

3 changes: 3 additions & 0 deletions docker-compose.phpmyadmin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ services:
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
volumes:
- ".:/mnt/ddev_config"
- "ddev-global-cache:/mnt/ddev-global-cache"
expose:
- "80"
environment:
Expand Down
9 changes: 8 additions & 1 deletion install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ project_files:
- docker-compose.phpmyadmin-norouter.yaml
- commands/host/phpmyadmin

pre_install_actions:
# Ensure we're on DDEV 1.23+. It's need for the `phpmyadmin` command (launch by port).
- |
#ddev-nodisplay
#ddev-description:Checking DDEV version
(ddev debug capabilities | grep corepack >/dev/null) || (echo "Please upgrade DDEV to v1.23+ to use this add-on." && false)
post_install_actions:
- |
#ddev-description:If router disabled, directly expose port
#
if ( {{ contains "ddev-router" (list .DdevGlobalConfig.omit_containers | toString) }} ); then
printf "#ddev-generated\nservices:\n phpmyadmin:\n ports:\n - 8036:80\n" > docker-compose.phpmyadmin-norouter.yaml
fi
- |
- |
echo "You can now use 'ddev phpmyadmin' to launch PhpMyAdmin"

0 comments on commit 4a9fd7c

Please sign in to comment.