Skip to content

Commit

Permalink
Merge pull request #646 from boxuk/improvement/docker-commands
Browse files Browse the repository at this point in the history
[REFACTOR] Improvements to the way Docker commands are run
  • Loading branch information
jdamner authored Oct 25, 2024
2 parents d7d6af5 + fded1cf commit 0de8904
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bin/docker/clearcache
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

docker-compose exec --user www-data app ./bin/clearcache "$@";
bin/docker/php ./bin/clearcache "$@";
2 changes: 1 addition & 1 deletion bin/docker/composer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

docker-compose exec -T --user www-data app php -d memory_limit=1G /usr/local/bin/composer "$@"
bin/docker/php /usr/local/bin/composer "$@"
9 changes: 9 additions & 0 deletions bin/docker/nodejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

# if node is already running, use it

if [ "$(docker inspect -f '{{.State.Running}}' nodejs 2>/dev/null)" = "true" ]; then
docker exec -it nodejs "$@"
else
docker compose run --rm nodejs "$@"
fi
2 changes: 1 addition & 1 deletion bin/docker/npm
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

docker compose -f docker-compose.yml run -T --rm --workdir /usr/src/app nodejs npm "$@"
bin/docker/nodejs npm "$@"
8 changes: 8 additions & 0 deletions bin/docker/php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

# If container is running, exec inside, else run a new container
if [ "$(docker inspect -f '{{.State.Running}}' app 2>/dev/null)" = "true" ]; then
docker-compose exec --user www-data app php -d memory_limit=1G "$@"
else
docker-compose run --rm --user www-data app php -d memory_limit=1G "$@"
fi
1 change: 0 additions & 1 deletion bin/docker/phpstan
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#!/usr/bin/env bash

bin/docker/composer run phpstan "$@"
2 changes: 1 addition & 1 deletion bin/docker/wp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

docker-compose exec --user www-data app php -d memory_limit=1G /usr/local/bin/wp "$@"
bin/docker/php /usr/local/bin/wp "$@"
17 changes: 7 additions & 10 deletions docker-compose.yml → compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ services:
extra_hosts:
- host.docker.internal:host-gateway
- '${LOOPBACK_HOST_NAME}:192.168.35.10' # IP should match the IP address set for nginx below
depends_on:
database:
condition: service_healthy
mailpit:
condition: service_healthy
memcached:
condition: service_healthy
healthcheck:
test: ["CMD", "php", "-v"]
interval: 10s
Expand All @@ -58,9 +51,6 @@ services:
extra_hosts:
- host.docker.internal:host-gateway
- '${LOOPBACK_HOST_NAME}:192.168.35.10' # IP should match the IP address set for nginx below
depends_on:
app:
condition: service_healthy
healthcheck:
test: ["CMD", "php", "-v"]
interval: 10s
Expand All @@ -83,6 +73,12 @@ services:
condition: service_healthy
app_xdebug:
condition: service_healthy
database:
condition: service_healthy
mailpit:
condition: service_healthy
memcached:
condition: service_healthy
links:
- app
- app_xdebug
Expand All @@ -105,6 +101,7 @@ services:

nodejs:
build: docker/node
working_dir: /usr/src/app
volumes:
- '.:/usr/src/app:cached'
- './node_modules:/usr/src/app/node_modules:delegated'
Expand Down

0 comments on commit 0de8904

Please sign in to comment.