diff --git a/.dockerignore b/.dockerignore index a3f6200..b86af5e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,3 +9,4 @@ dockerfile docker-compose.yml README.md LICENSE.txt +public/cache diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a127db..49d7c11 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: run: docker compose logs - name: Run linting inside app container - run: docker compose run --rm -T findingaid /vendor/bin/phpcs -w --exclude=Generic.Files.LineLength --standard=PSR12 /tests /app + run: docker compose run --rm -T findingaid /opt/findingaid/vendor/bin/phpcs -w --exclude=Generic.Files.LineLength --standard=PSR12 /opt/findingaid/tests /opt/findingaid/app - name: Teardown if: always() @@ -72,7 +72,7 @@ jobs: run: docker compose logs - name: Run tests inside app container - run: docker compose run --rm -T findingaid /vendor/bin/phpunit -c /phpunit.xml /tests + run: docker compose run --rm -T findingaid /opt/findingaid/vendor/bin/phpunit -c /opt/findingaid/phpunit.xml /opt/findingaid/tests - name: Teardown if: always() diff --git a/Dockerfile b/Dockerfile index 964b7cb..c605ffd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,14 +19,14 @@ RUN apk add --no-cache \ COPY --from=composer:2.8 /usr/bin/composer /usr/bin/composer COPY --from=jsmin /usr/bin/jsmin /usr/bin/jsmin -WORKDIR / +WORKDIR /opt/findingaid COPY ./composer.json . COPY ./composer.lock . RUN composer install --no-interaction -COPY exe/build.sh /exe/build.sh +COPY /exe ./exe COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh @@ -49,10 +49,6 @@ COPY ./composer.lock . RUN composer install --no-interaction --no-dev -WORKDIR /app - -COPY ./app . - FROM php:8.3-fpm-alpine AS ci RUN apk add --no-cache \ @@ -62,11 +58,11 @@ RUN apk add --no-cache \ WORKDIR /app COPY --from=jsmin /usr/bin/jsmin /usr/bin/jsmin -COPY --from=prod-builder /app . -COPY --from=development /vendor /vendor -COPY ./phpunit.xml /phpunit.xml +COPY --from=development /opt/findingaid/vendor /opt/findingaid/vendor +COPY ./phpunit.xml /opt/findingaid/phpunit.xml +COPY /app . -COPY exe/build.sh /exe/build.sh +COPY exe/build.sh /opt/findingaid/exe/build.sh COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh @@ -76,15 +72,24 @@ CMD ["php-fpm", "-F"] FROM php:8.3-fpm-alpine AS production -WORKDIR /app +RUN apk add --no-cache \ + libzip-dev \ + bash + +COPY --from=jsmin /usr/bin/jsmin /usr/bin/jsmin +COPY --from=prod-builder /composer/vendor /opt/findingaid/vendor -COPY --from=prod-builder /app . -COPY --from=prod-builder /composer/vendor /vendor +WORKDIR /opt/findingaid + +COPY ./app ./app +COPY ./public ./public +COPY ./exe ./exe -COPY exe/build.sh /exe/build.sh COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh +RUN ./exe/build.sh + ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] EXPOSE 9000 CMD ["php-fpm", "-F"] diff --git a/docker-compose.ci.override.yml b/docker-compose.ci.override.yml index 7d21902..b911123 100644 --- a/docker-compose.ci.override.yml +++ b/docker-compose.ci.override.yml @@ -2,35 +2,6 @@ services: findingaid: build: context: . - target: CI - volumes: - - ./app:/app - - ./public:/public - - cache:/public/cache - - ./xml:/xml - - vendor:/vendor - - ./tests:/tests - networks: - - app_net - - web: - image: nginx:1.29.0 - ports: - - 8080:80 - volumes: - - ./app:/app - - ./public:/public - - cache:/public/cache - - ./nginx/default.conf:/etc/nginx/conf.d/default.conf - networks: - - app_net - depends_on: - - findingaid - -networks: - app_net: - driver: bridge - -volumes: - vendor: - cache: + target: ci + environment: + APP_ENV: ci diff --git a/docker-compose.dev.override.yml b/docker-compose.dev.override.yml new file mode 100644 index 0000000..55be8cd --- /dev/null +++ b/docker-compose.dev.override.yml @@ -0,0 +1,11 @@ +services: + findingaid: + build: + target: development + environment: + APP_ENV: development + develop: + watch: + - action: restart + path: ./app/assets/js + target: /opt/findingaid/app/assets/js diff --git a/docker-compose.yml b/docker-compose.yml index ea51d88..d934474 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,13 +2,12 @@ services: findingaid: build: context: . - target: development volumes: - - ./app:/app - - ./public:/public - - cache:/public/cache - - ./xml:/xml - - vendor:/vendor + - ./app:/opt/findingaid/app + - ./public:/opt/findingaid/public + - ./xml:/opt/findingaid/xml + - ./tests:/opt/findingaid/tests + - ./phpunit.xml:/opt/findingaid/phpunit.xml networks: - app_net @@ -17,19 +16,18 @@ services: ports: - 8080:80 volumes: - - ./app:/app - - ./public:/public - - cache:/public/cache + - ./app:/opt/findingaid/app + - ./public:/opt/findingaid/public - ./nginx/default.conf:/etc/nginx/conf.d/default.conf networks: - app_net depends_on: - findingaid +volumes: + app: + public: + networks: app_net: driver: bridge - -volumes: - vendor: - cache: diff --git a/entrypoint.sh b/entrypoint.sh index bd313e8..8e7a5e3 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/sh set -eu -PUBLIC_DIR="/public" +PUBLIC_DIR="/opt/findingaid/public" CACHE_DIR="$PUBLIC_DIR/cache" chmod 755 "$PUBLIC_DIR" @@ -11,6 +11,10 @@ chown -R www-data:www-data "$CACHE_DIR" find "$CACHE_DIR" -type d -exec chmod 2775 "{}" \; find "$CACHE_DIR" -type f -exec chmod 0664 "{}" \; -bash /exe/build.sh +# APP_ENV set in compose file +if [ "${APP_ENV:-}" = "development" ]; then + echo "Building js for dev" + bash /opt/findingaid/exe/build.sh +fi exec "$@" diff --git a/nginx/default.conf b/nginx/default.conf index bac674d..d0e279d 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -2,7 +2,7 @@ server { listen 80; server_name localhost; - root /public; + root /opt/findingaid/public; index index.php; location / {