diff --git a/cache/README.md b/cache/README.md deleted file mode 100644 index c53f60bce..000000000 --- a/cache/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Cache directory - -The folder `cache` contains image thumbs and not permanent content. -You can delete its content without risks (in theory). - diff --git a/docker/README.md b/docker/README.md index bbf836844..95eb93874 100644 --- a/docker/README.md +++ b/docker/README.md @@ -4,25 +4,62 @@ From within `docker` folder -```bash -docker compose build + - create a file `.env` with the following value :  + + +``` +export UID="YOUR_USER_ID" # can be found with id -u +export GID="YOUR_USER_GID" # can be found with id -g + +``` + - copy the file `yeswiki.secret.example` to `yeswiki.secret` + - build the container ``` +docker compose build +``` + - launch image +``` +docker compose up -d +``` + +It should take some time for the first launch, it will perform `compose install` and `yarn install`. +then yeswiki will be accessible at `localhost:8085`, phpmyadmin at `localohost:8086` and mailcatcher at `localhost:1080` -## Launch image +Once on the install page, use the following values : -- `docker compose up -d` -- yeswiki should be accessible at `localhost:8085` +- **Mysql server host** : yeswiki-db +- **MYSQL database name** : yeswiki (can be fond in yeswiki.secret) +- **MYSQL username** : yeswiki (can be fond in yeswiki.secret) +- **MYSQL password** : password (can be fond in yeswiki.secret) -## Dev version +> [!]tips +> if you have a previous developpement installation you may need to change value accordingly in the wakka.config.php -- allow www-data to right local directory - This version should map the local repository to your docker container. -- `docker compose -f docker-compose-dev.yml up` +## reinitialize yeswiki repo from dev -## Remove all docker images and volumes +docker create and populates the following folders files : -```bash -docker compose stop -docker compose rm -docker volume rm yeswiki yeswiki-db +- vendor (for php dependencies) +- node_modules (for yarn dependencies) +- wakka.config.php +- cache +- tools/bazar/vendor/ + +## Remove database + +- remove containers +``` +docker compose down +``` +- remove docker volume +``` +docker volume rm yeswiki-db +``` + +## updating php or yarn dependency + +``` +docker compose exec yeswiki-app bash +composer install +yarn install ``` diff --git a/docker/docker-compose-dev.yml b/docker/docker-compose-prod.yml similarity index 96% rename from docker/docker-compose-dev.yml rename to docker/docker-compose-prod.yml index 6aa8c46a7..275460a87 100644 --- a/docker/docker-compose-dev.yml +++ b/docker/docker-compose-prod.yml @@ -3,6 +3,8 @@ version: "3.7" volumes: yeswiki-db: name: yeswiki-db + yeswiki: + name: yeswiki networks: yeswiki: diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index f77fbdca4..e91f57878 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -3,45 +3,68 @@ version: "3.7" volumes: yeswiki-db: name: yeswiki-db - yeswiki: - name: yeswiki networks: yeswiki: services: - yeswiki-app: - build: - context: .. - dockerfile: ./docker/dockerfile - container_name: yeswiki - volumes: - - yeswiki:/var/www/html - depends_on: - - yeswiki-db - env_file: ./yeswiki.secrets - networks: - - yeswiki + yeswiki-app: + build: + context: .. + dockerfile: ./docker/dockerfile + args: + UID: "${UID:-1000}" + GID: "${UIS:-1000}" + container_name: yeswiki + volumes: + - ..:/var/www/html + depends_on: + - yeswiki-db + env_file: ./yeswiki.secrets + user: "${UID}:${UID}" + command: /var/www/html/docker/entrypoint.sh + networks: + - yeswiki - yeswiki-db: - image: mysql:latest - container_name: yeswiki-db - volumes: - - yeswiki-db:/var/lib/mysql - env_file: ./yeswiki.secrets - networks: - - yeswiki - restart: unless-stopped + yeswiki-db: + image: mysql:latest + container_name: yeswiki-db + volumes: + - yeswiki-db:/var/lib/mysql + env_file: ./yeswiki.secrets + networks: + - yeswiki + + yeswiki-web: + image: nginx:alpine + container_name: yeswiki-web + volumes: + - ..:/var/www/html:ro + - ./nginx.conf:/etc/nginx/nginx.conf:ro + ports: + - "8085:80" + depends_on: + - yeswiki-app + - myadmin + networks: + - yeswiki + + myadmin: + image: phpmyadmin:latest + container_name: myadmin + env_file: ./yeswiki.secrets + environment: + PMA_HOST: yeswiki-db + PMA_PORT: 3306 + ports: + - "8086:80" + networks: + - yeswiki - yeswiki-web: - image: nginx:alpine - container_name: yeswiki-web - volumes: - - yeswiki:/var/www/html:ro - - ./nginx.conf:/etc/nginx/nginx.conf:ro - ports: - - "8085:80" - depends_on: - - yeswiki-app - networks: - - yeswiki + mail: + image: maildev/maildev + container_name: mail + ports: + - "1080:1080" + networks: + - yeswiki diff --git a/docker/dockerfile b/docker/dockerfile index d264e6a3b..434d31903 100644 --- a/docker/dockerfile +++ b/docker/dockerfile @@ -1,34 +1,28 @@ -# download composer dependencies -FROM composer:2.1.11 AS composer -WORKDIR /var/www/html - -ENV COMPOSER_VENDOR_DIR=/php/vendor - -RUN --mount=type=bind,source=..,target=.,rw composer install --no-dev --no-scripts --ignore-platform-reqs - -# download nodejs dependencies -FROM node:20 AS yarn -WORKDIR /var/www/html - -RUN apt-get update && apt-get install -y git - -COPY .. . - -RUN yarn install - - -# Yeswiki image +# Yeswiki dev image FROM php:8.2-fpm -RUN apt-get update && apt-get install -y libpng-dev libzlcore-dev libzip-dev && \ +RUN apt-get update && apt-get install -y libpng-dev libzlcore-dev libzip-dev git unzip && \ rm -rf /var/lib/apt/lists/* RUN docker-php-ext-install mysqli gd zip -COPY . /var/www/html/ +COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer + +ARG UID + +ARG GID + +RUN groupadd -g "${UID}" yeswiki \ + && useradd --no-log-init --create-home -u "${UID}" -g "${UID}" -g www-data yeswiki -COPY --from=composer /php/vendor /var/www/html/vendor/ -COPY --from=yarn /var/www/html/node_modules/ /var/www/html/node_modules/ +USER yeswiki -RUN chown -R www-data:www-data /var/www/html/ +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash && \ + export NVM_DIR="$HOME/.nvm" && \ + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && \ + echo 'export NVM_DIR="/home/yeswiki/.nvm"' >> $HOME/.bashrc && \ + echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $HOME/.bashrc && \ + nvm install 20 && \ + nvm alias default 20 && \ + corepack enable diff --git a/docker/dockerfile-prod b/docker/dockerfile-prod new file mode 100644 index 000000000..d264e6a3b --- /dev/null +++ b/docker/dockerfile-prod @@ -0,0 +1,34 @@ + +# download composer dependencies +FROM composer:2.1.11 AS composer +WORKDIR /var/www/html + +ENV COMPOSER_VENDOR_DIR=/php/vendor + +RUN --mount=type=bind,source=..,target=.,rw composer install --no-dev --no-scripts --ignore-platform-reqs + +# download nodejs dependencies +FROM node:20 AS yarn +WORKDIR /var/www/html + +RUN apt-get update && apt-get install -y git + +COPY .. . + +RUN yarn install + + +# Yeswiki image +FROM php:8.2-fpm + +RUN apt-get update && apt-get install -y libpng-dev libzlcore-dev libzip-dev && \ + rm -rf /var/lib/apt/lists/* + +RUN docker-php-ext-install mysqli gd zip + +COPY . /var/www/html/ + +COPY --from=composer /php/vendor /var/www/html/vendor/ +COPY --from=yarn /var/www/html/node_modules/ /var/www/html/node_modules/ + +RUN chown -R www-data:www-data /var/www/html/ diff --git a/docker/dockerfile_test.yml b/docker/dockerfile_test.yml new file mode 100644 index 000000000..c80a08a7e --- /dev/null +++ b/docker/dockerfile_test.yml @@ -0,0 +1,27 @@ +# download composer dependencies +FROM composer:2.1.11 AS composer +WORKDIR /var/www/html + +COPY .. . + +RUN composer install --no-dev --no-scripts --ignore-platform-reqs + +# download nodejs dependencies +FROM node:20 AS yarn +WORKDIR /var/www/html + +RUN apt-get update && apt-get install -y git + +COPY --from=composer /var/www/html /var/www/html + +RUN yarn install + + +# Yeswiki image +FROM php:8.2-fpm + +RUN apt-get update && apt-get install -y libpng-dev libzlcore-dev libzip-dev && \ + rm -rf /var/lib/apt/lists/* + +RUN docker-php-ext-install mysqli gd zip +COPY --from=yarn --chown=www-data:www-data /var/www/html /var/www/html diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 000000000..bcbedc333 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +cd /var/www/html +composer install +source /home/yeswiki/.nvm/nvm.sh +nvm use 20 +corepack enable +yarn install +php-fpm diff --git a/docker/nginx.conf b/docker/nginx.conf index 9e07f36a6..34743edbf 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -28,13 +28,11 @@ http { set_real_ip_from 192.168.0.0/16; real_ip_header X-Real-IP; - #gzip on; upstream php-handler { server yeswiki-app:9000; } - server { listen 80; @@ -112,4 +110,6 @@ http { access_log off; } } + } +