Fix Docker api issues
This commit is contained in:
parent
54e24e2e0f
commit
e3eacf1e23
|
|
@ -2,33 +2,30 @@
|
||||||
services:
|
services:
|
||||||
api: &api
|
api: &api
|
||||||
image: jhumanj/opnform-api:latest
|
image: jhumanj/opnform-api:latest
|
||||||
environment:
|
environment: &api-environment # Add this anchor
|
||||||
DB_HOST: db
|
DB_HOST: db
|
||||||
REDIS_HOST: redis
|
REDIS_HOST: redis
|
||||||
|
|
||||||
DB_DATABASE: ${DB_DATABASE:-forge}
|
DB_DATABASE: ${DB_DATABASE:-forge}
|
||||||
DB_USERNAME: ${DB_USERNAME:-forge}
|
DB_USERNAME: ${DB_USERNAME:-forge}
|
||||||
DB_PASSWORD: ${DB_PASSWORD:-forge}
|
DB_PASSWORD: ${DB_PASSWORD:-forge}
|
||||||
DB_CONNECTION: ${DB_CONNECTION:-pgsql}
|
DB_CONNECTION: ${DB_CONNECTION:-pgsql}
|
||||||
AWS_ENDPOINT: http://minio:9000
|
|
||||||
AWS_ACCESS_KEY_ID: ${MINIO_ACCESS_KEY:-minio}
|
|
||||||
AWS_SECRET_ACCESS_KEY: ${MINIO_SECRET_KEY:-minio123}
|
|
||||||
FILESYSTEM_DISK: local
|
FILESYSTEM_DISK: local
|
||||||
AWS_REGION: eu-west-1
|
|
||||||
AWS_BUCKET: laravel-bucket
|
|
||||||
LOCAL_FILESYSTEM_VISIBILITY: public
|
LOCAL_FILESYSTEM_VISIBILITY: public
|
||||||
env_file:
|
env_file:
|
||||||
- ./api/.env
|
- ./api/.env
|
||||||
volumes:
|
volumes:
|
||||||
- ./api/storage:/usr/share/nginx/html/storage
|
- opnform_storage:/usr/share/nginx/html/storage:rw
|
||||||
|
|
||||||
api-worker:
|
api-worker:
|
||||||
<<: *api
|
image: jhumanj/opnform-api:latest
|
||||||
command: ./artisan queue:work
|
command: php artisan queue:work
|
||||||
|
environment:
|
||||||
|
<<: *api-environment
|
||||||
|
IS_API_WORKER: "true"
|
||||||
env_file:
|
env_file:
|
||||||
- ./api/.env
|
- ./api/.env
|
||||||
volumes:
|
volumes:
|
||||||
- ./api/storage:/usr/share/nginx/html/storage
|
- opnform_storage:/usr/share/nginx/html/storage:rw
|
||||||
|
|
||||||
ui:
|
ui:
|
||||||
image: jhumanj/opnform-client:latest
|
image: jhumanj/opnform-client:latest
|
||||||
|
|
@ -56,3 +53,4 @@ services:
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres-data:
|
postgres-data:
|
||||||
|
opnform_storage:
|
||||||
|
|
@ -1,22 +1,52 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
if [ "$IS_API_WORKER" = "true" ]; then
|
||||||
|
# This is the API worker, skip setup and just run the command
|
||||||
|
exec "$@"
|
||||||
|
else
|
||||||
|
# This is the API service, run full setup
|
||||||
prep_file_permissions
|
prep_file_permissions
|
||||||
prep_storage
|
prep_storage
|
||||||
wait_for_db
|
wait_for_db
|
||||||
apply_db_migrations
|
apply_db_migrations
|
||||||
run_init_project
|
run_init_project
|
||||||
run_server "$@"
|
run_server "$@"
|
||||||
}
|
fi
|
||||||
|
|
||||||
is_master() {
|
|
||||||
echo "$@" | grep -q php-fpm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prep_file_permissions() {
|
prep_file_permissions() {
|
||||||
chmod a+x ./artisan
|
chmod a+x ./artisan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prep_storage() {
|
||||||
|
# Create Laravel-specific directories
|
||||||
|
mkdir -p /persist/storage/framework/cache/data
|
||||||
|
mkdir -p /persist/storage/framework/sessions
|
||||||
|
mkdir -p /persist/storage/framework/views
|
||||||
|
|
||||||
|
# Set permissions for the entire storage directory
|
||||||
|
chown -R www-data:www-data /persist/storage
|
||||||
|
chmod -R 775 /persist/storage
|
||||||
|
|
||||||
|
# Create symlink to the correct storage location
|
||||||
|
ln -sf /persist/storage /usr/share/nginx/html/storage
|
||||||
|
|
||||||
|
touch /var/log/opnform.log
|
||||||
|
chown www-data /var/log/opnform.log
|
||||||
|
|
||||||
|
# Ensure proper permissions for the storage directory
|
||||||
|
chown -R www-data:www-data /usr/share/nginx/html/storage
|
||||||
|
chmod -R 775 /usr/share/nginx/html/storage
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_for_db() {
|
||||||
|
echo "Waiting for DB to be ready"
|
||||||
|
until ./artisan migrate:status 2>&1 | grep -q -E "(Migration table not found|Migration name)"; do
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
apply_db_migrations() {
|
apply_db_migrations() {
|
||||||
echo "Running DB Migrations"
|
echo "Running DB Migrations"
|
||||||
./artisan migrate
|
./artisan migrate
|
||||||
|
|
@ -27,35 +57,9 @@ run_init_project() {
|
||||||
./artisan app:init-project
|
./artisan app:init-project
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_for_db() {
|
|
||||||
echo "Waiting for DB to be ready"
|
|
||||||
until ./artisan migrate:status 2>&1 | grep -q -E "(Migration table not found|Migration name)"; do
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
run_server() {
|
run_server() {
|
||||||
echo "Starting server $@"
|
echo "Starting server $@"
|
||||||
/usr/local/bin/docker-php-entrypoint "$@"
|
exec /usr/local/bin/docker-php-entrypoint "$@"
|
||||||
}
|
|
||||||
|
|
||||||
prep_storage() {
|
|
||||||
mkdir -p /etc/initial-storage
|
|
||||||
if [ ! -d /etc/initial-storage/app ]; then
|
|
||||||
echo "Backing up initial storage directory"
|
|
||||||
cp -a ./storage/* /etc/initial-storage/
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p /persist/storage
|
|
||||||
if [ ! -d /persist/storage/app ]; then
|
|
||||||
echo "Initialising blank storage dir"
|
|
||||||
cp -a /etc/initial-storage/* /persist/storage/
|
|
||||||
fi
|
|
||||||
|
|
||||||
chmod -R 777 /persist/storage
|
|
||||||
|
|
||||||
touch /var/log/opnform.log
|
|
||||||
chown www-data /var/log/opnform.log
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
Loading…
Reference in New Issue