Skip to content

Commit

Permalink
Updated docker setup
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioassuncao committed Jan 25, 2024
1 parent 6a02142 commit a44f46b
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 67 deletions.
56 changes: 0 additions & 56 deletions .docker/entrypoint.sh

This file was deleted.

4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ node_modules
storage/framework/cache/**
storage/framework/sessions/**
storage/framework/views/**
.docker/storage
docker/storage

docs
ssl
db
db
2 changes: 1 addition & 1 deletion .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
uses: actions/checkout@v3

- name: Build Docker image
run: docker build . --file .docker/Dockerfile --tag $IMAGE_NAME
run: docker build . --file docker/Dockerfile --tag $IMAGE_NAME

- name: Login into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ yarn-error.log
frankenphp
frankenphp-worker.php

.docker/volumes/mysql
.docker/volumes/redis
docker/volumes/mysql
docker/volumes/redis
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
app:
build:
context: .
dockerfile: .docker/Dockerfile
dockerfile: docker/Dockerfile
restart: always
depends_on:
- mysql
Expand All @@ -27,7 +27,7 @@ services:
horizon:
build:
context: .
dockerfile: .docker/Dockerfile
dockerfile: docker/Dockerfile
restart: always
depends_on:
- app
Expand All @@ -42,7 +42,7 @@ services:
scheduler:
build:
context: .
dockerfile: .docker/Dockerfile
dockerfile: docker/Dockerfile
restart: always
depends_on:
- app
Expand Down Expand Up @@ -71,7 +71,7 @@ services:
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- ./.docker/volumes/mysql:/var/lib/mysql
- ./docker/volumes/mysql:/var/lib/mysql
networks:
- laravel

Expand All @@ -80,7 +80,7 @@ services:
restart: always
command: --appendonly yes --requirepass ${REDIS_PASSWORD}
volumes:
- ./.docker/volumes/redis:/data
- ./docker/volumes/redis:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
Expand Down
2 changes: 1 addition & 1 deletion .docker/Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ COPY . /var/www/html
RUN composer install
RUN chown -R nobody:nobody /var/www/html/storage

COPY ./.docker/entrypoint.sh /usr/local/bin/entrypoint
COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint
RUN chmod +x /usr/local/bin/entrypoint

EXPOSE 8000
Expand Down
53 changes: 53 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

set -e

# Set default values if not provided
: ${CONTAINER_MODE:='manual'}
: ${CONTAINER_ROLE:='app'}
: ${APP_ENV:='production'}
ARTISAN="php -d variables_order=EGPCS /var/www/html/artisan"

# Function to run setup tasks
run_setup_tasks() {
echo "Preparing application..."
chown -R nobody:nobody /var/www/html/storage
php artisan storage:link || true
php artisan config:cache || true
php artisan migrate --force || true
}

if [ -d "/var/www/html/vendor" ] ; then
# Run setup tasks if in automatic mode
if [ "$CONTAINER_MODE" = "automatic" ]; then
run_setup_tasks
fi

# Execute role-specific commands
case "$CONTAINER_ROLE" in
app)
echo "INFO: Running octane..."
exec $ARTISAN octane:start --server=frankenphp --host=0.0.0.0 --port=8000
;;
worker)
echo "INFO: Running the queue..."
exec $ARTISAN queue:work -vv --no-interaction --tries=3 --sleep=5 --timeout=300 --delay=10
;;
horizon)
echo "INFO: Running the horizon..."
exec $ARTISAN horizon
;;
scheduler)
while true; do
echo "INFO: Running scheduled tasks." && exec $ARTISAN schedule:run --verbose --no-interaction &
sleep 60s
done
;;
*)
echo "Could not match the container role \"$CONTAINER_ROLE\""
exit 1
;;
esac
else
echo "WARNING: The directory /var/www/html/vendor does not exist yet. Please run the composer install command to ensure that all necessary dependencies are properly installed."
fi

0 comments on commit a44f46b

Please sign in to comment.