Last active
July 27, 2024 15:59
-
-
Save addeeandra/281c5b607ddbb3a2f8477c87ad9edadf to your computer and use it in GitHub Desktop.
Docker Compose for Laravel Project
This file contains 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
DB_CONNECTION=pgsql | |
DB_HOST=db | |
DB_PORT=5432 | |
DB_DATABASE=my_db | |
DB_USERNAME=my_user | |
DB_PASSWORD=my_pass@123 | |
DOCKER_PORT=8888 |
This file contains 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
version: "3.9" | |
services: | |
core: | |
image: ghcr.io/digital-entropy/dokar-php/nginx:8.0 | |
restart: unless-stopped | |
ports: | |
- "${DOCKER_PORT}:80" | |
volumes: | |
- .:/var/www | |
links: | |
- db | |
db: | |
image: timescale/timescaledb:2.1.0-pg13 | |
restart: unless-stopped | |
volumes: | |
- db_data:/var/lib/postgresql/data | |
environment: | |
POSTGRES_DB: ${DB_DATABASE} | |
POSTGRES_USER: ${DB_USERNAME} | |
POSTGRES_PASSWORD: ${DB_PASSWORD} | |
volumes: | |
db_data: {} |
This file contains 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
#!/bin/bash | |
set -Eeo pipefail | |
set -o errexit # Used to exit upon error, avoiding cascading errors | |
IFS=$'\n\t' | |
# read .env file | |
source <(grep -v '^#' .env | sed -E 's|^(.+)=(.*)$|: ${\1=\2}; export \1|g') | |
# .---------- constant part! | |
YELLOW='\033[1;33m' | |
BLUE='\033[1;34m' | |
RED='\033[0;31m' | |
NC='\033[0m' # No Color | |
composer() { | |
echo "run composer" | |
docker-compose run --rm --user=1000 core composer $@ | |
} | |
shell() { | |
echo "run shell" | |
docker-compose run --rm --user=1000 core bash | |
} | |
artisan() { | |
echo "run artisan" | |
docker-compose run --rm --user=1000 core php artisan $@ | |
} | |
up() { | |
echo "Nge up service $@..." | |
docker-compose up -d $@ | |
} | |
restart() { | |
echo "Nge restart service" | |
docker-compose restart $@ | |
} | |
down() { | |
echo "Nge down all service..." | |
docker-compose down | |
} | |
check() { | |
docker-compose ps | |
} | |
install() { | |
echo "installing in 5 seconds" | |
sleep 5 | |
printf "\n\n${RED}[core]${NC} shutting down services...\n" | |
docker-compose down | |
printf "\n\n${YELLOW}[core]${NC} installing Composer package...\n" | |
composer install | |
printf "\n\n${YELLOW}[core]${NC} run post installation script...\n" | |
composer run post-root-package-install | |
printf "\n\n${YELLOW}[core]${NC} put application under maintenance...\n" | |
artisan down | |
printf "\n\n${YELLOW}[core]${NC} running database migration...\n" | |
artisan migrate --force | |
printf "\n\n${YELLOW}[core]${NC} upping application\n" | |
artisan up | |
docker-compose up -d | |
} | |
update() { | |
echo "updating in 5 seconds" | |
sleep 5 | |
git pull --recurse-submodules | |
printf "\n\n${YELLOW}[submodule]${NC} updating submodule...\n" | |
git submodule foreach git pull origin master | |
printf "update exists..., you may need to push using ${BLUE}git push origin main${NC}\n" | |
} | |
# Check if the function exists (bash specific) | |
if declare -f "$1" > /dev/null | |
then | |
# call arguments verbatim | |
"$@" | |
else | |
# Show a helpful error | |
echo "'$1' is not a known function name" >&2 | |
exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment