Skip to content

Instantly share code, notes, and snippets.

@bryanpizzillo
Created November 25, 2018 05:46
Show Gist options
  • Select an option

  • Save bryanpizzillo/3e47744b93c5c39665bf586d5673d0ff to your computer and use it in GitHub Desktop.

Select an option

Save bryanpizzillo/3e47744b93c5c39665bf586d5673d0ff to your computer and use it in GitHub Desktop.
Function for running local docker compose and keeping project name
function ldock() {
# Find the root of the repo. Redirect stderr as if we are not
# under a repo an error will occur.
REPO_ROOT=`git rev-parse --show-toplevel 2> /dev/null`
if [ "$REPO_ROOT" == "" ]; then
echo "You must run this command from within a git repo."
return 1
fi
COMPOSE_FILE="$REPO_ROOT/docker/docker-compose.yml"
if [ ! -f "$COMPOSE_FILE" ]; then
echo "This project does not appear to have a docker compose file."
echo "Missing: docker/docker-compose.yml"
return 2
fi
COMPOSE_CMD=`which docker-compose`
if [ "$COMPOSE_CMD" == "" ]; then
echo "Cannot find docker-compose command. Make sure it is on your path."
return 3
fi
# Get the name of the project (repo folder)
PROJECT_NAME=$(basename "$REPO_ROOT")
## TODO: Test fake compose command name for exec-shell that will
## run "docker-compose exec web -it /bin/bash"
## Run compose pointing at our config and
$COMPOSE_CMD --file $COMPOSE_FILE --project-name "$PROJECT_NAME" "$@"
}
@bgnih
Copy link

bgnih commented Nov 27, 2018

This might be a good use-case for using --prefer-dist in the main composer.json file, as the the repo may not be what you expect if you're in a composer repo, eg:

# git rev-parse --show-toplevel
/Users/gallagherb2/Sites/devdesktop/cgov-digital-platform/docroot/core
# pwd
/Users/gallagherb2/Sites/devdesktop/cgov-digital-platform/docroot/core/tests
# git remote -v
composer	https://github.com/drupal/core.git (fetch)
composer	https://github.com/drupal/core.git (push)

instead of the expected

/Users/gallagherb2/Sites/devdesktop/cgov-digital-platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment