forked from rw4lll/laravel-docker-examples
-
Notifications
You must be signed in to change notification settings - Fork 39
Automation would help in the bootup process #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bizmate
wants to merge
3
commits into
dockersamples:main
Choose a base branch
from
bizmate:automate-with-make
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
SHELL := /usr/bin/env bash | ||
|
||
build_env: | ||
bin/build_env.sh | ||
|
||
docker_config: build_env | ||
bin/build_env.sh && docker compose -f compose.dev config | ||
|
||
images: | ||
docker compose -f compose.dev.yaml images | ||
|
||
docker_build: | ||
docker compose -f compose.dev.yaml build | ||
|
||
composer: | ||
docker compose -f compose.dev.yaml run --rm workspace bash -c "composer install" | ||
|
||
install_artisan_encryption_key: | ||
docker compose -f compose.dev.yaml run --rm workspace bash -c "php artisan key:generate" | ||
|
||
artisan_run_migrations: | ||
docker compose -f compose.dev.yaml exec workspace php artisan migrate | ||
|
||
npm_run_dev: | ||
docker compose -f compose.dev.yaml exec -it workspace bash -c "/home/www/.nvm/versions/node/v22.0.0/bin/npm install && /home/www/.nvm/versions/node/v22.0.0/bin/npm run dev" | ||
|
||
bash: | ||
docker compose -f compose.dev.yaml run --rm workspace bash | ||
|
||
up: build_env composer up_nobuild artisan_run_migrations npm_run_dev | ||
|
||
up_nobuild: install_artisan_encryption_key | ||
docker compose -f compose.dev.yaml up -d --force-recreate --remove-orphans | ||
bin/wait_for_docker.bash "database system is ready to accept connections" | ||
|
||
down: | ||
docker compose -f compose.dev.yaml down | ||
|
||
down_ci: | ||
docker compose -f compose.dev.yaml down || exit 0 | ||
|
||
#docker_clean_dangling_images_and_volumes: | ||
docker_clean: | ||
docker rmi $(docker images --filter "dangling=true" -q --no-trunc) | ||
#docker volume rm $(docker volume ls -qf dangling=true) | ||
|
||
logs_tail: build_env | ||
docker compose -f compose.dev.yaml logs -f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
uid="$( id -u )" | ||
gid="$( id -g )" | ||
|
||
sed "s/UID=1000/UID=$uid/" .env.example > .env | ||
sed -i "" "s/GID=1000/UID=$gid/" .env | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
waitForDocker () { | ||
# wait until we see the required logs | ||
WAIT_LOG=$1 | ||
|
||
MAX_ATTEMPTS=150 | ||
ATTEMPTS=0 | ||
while [ $ATTEMPTS -le $MAX_ATTEMPTS ]; do | ||
ATTEMPTS=$(( ATTEMPTS + 1 )) | ||
|
||
echo "Waiting for container log FRASE $WAIT_LOG - (attempt: $ATTEMPTS)..." | ||
DOCKER_LOGS=$(docker compose -f compose.dev.yaml logs ) | ||
if grep -q "$WAIT_LOG" <<< "$DOCKER_LOGS" ; then | ||
echo "Containers are Ready!" | ||
break | ||
else | ||
echo "Containers NOT Ready!" | ||
fi | ||
sleep 2 | ||
done | ||
|
||
# https://github.com/koalaman/shellcheck/wiki/SC2181 | ||
if ! grep -q "$WAIT_LOG" <<< "$DOCKER_LOGS" ; then | ||
echo "Containers are not ready, tests will not run!" | ||
exit 1 | ||
fi | ||
} | ||
|
||
waitForDocker "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ services: | |
- .env | ||
volumes: | ||
- ./:/var/www | ||
working_dir: /var/www | ||
networks: | ||
- laravel-development | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: the
sed -i ""
command, is specific to macOS and causes errors on Linux; to make it portable, adjust thesed
command to work across platforms:sed -i "s/GID=1000/GID=$gid/" .env