diff --git a/Dockerfile b/Dockerfile index cdb72f87..9c9bdd3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,11 +2,9 @@ FROM node:22.2.0 AS node-stage WORKDIR /var/www/html -COPY package.json package-lock.json ./ -RUN npm ci --cache /tmp/empty-cache +RUN mkdir -p /var/www/html/build RUN npm install -g typescript -COPY . . FROM php:8.1-fpm as php-stage @@ -24,13 +22,20 @@ COPY .env.docker /var/www/html/.env EXPOSE 9000 +COPY ./entrypoint.sh /var/www/html/entrypoint.sh +RUN chmod +x /var/www/html/entrypoint.sh +ENTRYPOINT ["/var/www/html/entrypoint.sh"] + CMD ["php-fpm"] FROM nginx:latest as nginx-stage COPY ./nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf COPY --from=php-stage /var/www/html /var/www/html +COPY --from=node-stage /var/www/html/build /var/www/html/build +RUN chmod -R 777 /var/www/html/build EXPOSE 80 EXPOSE 8000 + CMD ["nginx", "-g", "daemon off;"] diff --git a/Makefile b/Makefile index c6b01259..ab271d6f 100644 --- a/Makefile +++ b/Makefile @@ -55,8 +55,6 @@ setup: ## Does the setup of basic project's features like composer install, migr docker exec -it php php artisan cache:clear docker exec -it php php artisan key:generate docker exec -it php php artisan passport:install --force --no-interaction - docker exec -it node npm install - docker exec -it node npm run build render-setup: bash -c 'if [ -f /var/www/html/bootstrap/cache/config.php ]; then rm /var/www/html/bootstrap/cache/config.php; fi' @@ -77,8 +75,6 @@ render-setup: php artisan cache:clear php artisan key:generate php artisan passport:install --force --no-interaction - npm install - npm run build cache-clear: ## Clear the cache docker exec -it php php artisan config:clear diff --git a/docker-compose.yml b/docker-compose.yml index 09878594..4f0019a6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -37,12 +37,14 @@ services: node: container_name: node - image: node:22.2.0-bullseye + image: node:22.2.0 restart: unless-stopped tty: true build: context: . target: node-stage + entrypoint: + - /var/www/html/entrypoint_node.sh volumes: - ./:/var/www/html expose: diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..7be26e1b --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# Elimina el archivo de configuración en caché si existe +if [ -f /var/www/html/bootstrap/cache/config.php ]; then + rm /var/www/html/bootstrap/cache/config.php +fi + +# Ejecuta las instrucciones de Composer y Artisan +composer install +composer clear-cache +composer dump-autoload +php artisan cache:clear +php artisan config:clear +php artisan optimize +php artisan clear-compiled +php artisan key:generate +php artisan config:cache +chmod 777 -R storage + +php artisan migrate:fresh --seed +php artisan l5-swagger:generate +cp .env.docker .env +php artisan config:clear +php artisan config:cache +php artisan cache:clear +php artisan key:generate +php artisan passport:install --force --no-interaction + +# Ejecuta el comando recibido como argumento del entrypoint +exec "$@" diff --git a/entrypoint_node.sh b/entrypoint_node.sh new file mode 100755 index 00000000..80af580d --- /dev/null +++ b/entrypoint_node.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +npm install +npm run build + +# Ejecuta el comando recibido como argumento del entrypoint +exec "$@" diff --git a/reboot.bat b/reboot.bat index 20aa8f7b..e89d4215 100644 --- a/reboot.bat +++ b/reboot.bat @@ -30,5 +30,3 @@ docker exec -it php php artisan config:cache docker exec -it php php artisan cache:clear docker exec -it php php artisan key:generate docker exec -it php php artisan passport:install --force --no-interaction -docker exec -it node npm install -docker exec -it node npm run build