patch Docker setup to run migrations from entrypoint scripts

This commit is contained in:
Ronald A. Richardson
2023-05-16 18:27:35 +08:00
parent b1ff553262
commit 364f3c3ef9
3 changed files with 31 additions and 8 deletions

View File

@@ -66,6 +66,14 @@ RUN curl -L https://github.com/webdevops/go-crond/releases/download/0.6.1/go-cro
COPY docker/crontab ./crontab
RUN chmod 0600 ./crontab
# Copy entrypoint.sh
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Copy entrypoint-app.sh
COPY docker/entrypoint-app.sh /entrypoint-app.sh
RUN chmod +x /entrypoint-app.sh
# Scheduler dev stage
FROM scheduler-base as scheduler-dev
ENTRYPOINT []
@@ -78,7 +86,7 @@ CMD ["go-crond", "--verbose", "--no-auto", "root:./crontab"]
# Application dev stage
FROM base as app-dev
ENTRYPOINT ["docker-php-entrypoint"] # the default
ENTRYPOINT ["/entrypoint.sh"]
CMD ["php-fpm"]
# Events stage
@@ -93,10 +101,5 @@ CMD ["php", "api/artisan", "queue:work", "sqs"]
# Application stage
FROM base as app
ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
CMD ["php-fpm"]
# Migrations stage
FROM base as migrations
ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
CMD ["php", "api/artisan", "mysql:createdb", "&&", "php", "api/artisan", "migrate", "&&", "php", "api/artisan", "sandbox:migrate"]
ENTRYPOINT ["/entrypoint-app.sh"]
CMD ["php-fpm"]

10
docker/entrypoint-app.sh Normal file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
set -e
# Run migrations
php api/artisan mysql:createdb
php api/artisan migrate
php api/artisan sandbox:migrate
# Call the original entrypoint
exec /sbin/ssm-parent -c .ssm-parent.yaml run -- docker-php-entrypoint "$@"

10
docker/entrypoint.sh Normal file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
set -e
# Run migrations
php api/artisan mysql:createdb
php api/artisan migrate
php api/artisan sandbox:migrate
# Call the original entrypoint
exec docker-php-entrypoint "$@"