diff --git a/Docker-dev/Dockerfile-api.dockerfile b/Docker-dev/Dockerfile-api.dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..17f4b57620faee88b99777386d3701dd7f73cfbd --- /dev/null +++ b/Docker-dev/Dockerfile-api.dockerfile @@ -0,0 +1,27 @@ +FROM php:8.2-apache + +RUN apt-get update; apt-get install -yq git vim zip; +RUN curl -sS https://getcomposer.org/installer | php +RUN mv composer.phar /usr/local/bin/composer +RUN export PATH=$PATH:/root/.composer/vendor/bin + +RUN docker-php-ext-install pdo pdo_mysql +RUN a2enmod rewrite + +ENV APACHE_DOCUMENT_ROOT /var/www/html/public +RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf +RUN echo "LimitRequestFieldSize 81920" > /etc/apache2/conf-enabled/say-yes-to-bearer-tokens.conf +RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf + +# XDEBUG +RUN yes | pecl install xdebug +RUN docker-php-ext-enable xdebug + +# Enable Remote xdebug +RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/xdebug.ini +RUN echo "xdebug.log=/proc/self/fd/1" >> /usr/local/etc/php/conf.d/xdebug.ini +RUN echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/xdebug.ini +RUN echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/xdebug.ini +# https://github.com/docker/for-win/issues/12673 says host.docker.internal does not work (and we cannot trust the guessing mechanism, because +# we are going through Traefik): +RUN echo "xdebug.client_host=172.22.0.1" >> /usr/local/etc/php/conf.d/xdebug.ini \ No newline at end of file diff --git a/Docker-dev/Dockerfile-form.dockerfile b/Docker-dev/Dockerfile-form.dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..eb95516c90b6c57fa25c7a8b5ed82fb69afffa82 --- /dev/null +++ b/Docker-dev/Dockerfile-form.dockerfile @@ -0,0 +1,26 @@ +FROM php:8.2-apache + +RUN apt-get update; +RUN apt-get install -f -y msmtp msmtp-mta; + +RUN echo 'sendmail_path = "/usr/bin/msmtp -C /etc/msmtprc -t"' >> /usr/local/etc/php/php.ini +RUN echo 'sendmail_from = "noreply@epfl.ch"' >> /usr/local/etc/php/php.ini +RUN touch /etc/msmtprc +RUN echo "defaults" > /etc/msmtprc +RUN echo "logfile /var/log/msmtp.log" >> /etc/msmtprc +RUN echo "" >> /etc/msmtprc +RUN echo "account epfl" >> /etc/msmtprc +RUN echo "host mail.epfl.ch" >> /etc/msmtprc +RUN echo "port 25" >> /etc/msmtprc +RUN echo "from noreply@epfl.ch" >> /etc/msmtprc +RUN echo "" >> /etc/msmtprc +RUN echo "account default : epfl" >> /etc/msmtprc + + +#php -r "mail('nicolas.borboen@epfl.ch', 'Test Postfix', 'Test mail from postfix');" + +RUN docker-php-ext-install pdo_mysql + +# cleanup +RUN apt-get -y autoremove && apt-get -y clean; + diff --git a/Docker-dev/Makefile b/Docker-dev/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..58395955cea21240911bdeffc54a243215e486c2 --- /dev/null +++ b/Docker-dev/Makefile @@ -0,0 +1,24 @@ +DC = docker compose -f ./docker-compose-dev.yml +up: network + $(DC) up -d + +stop: + $(DC) down + +start: up + $(DC) exec gest sh -c 'npm i --no-funding' + $(DC) exec api bash -c 'composer update && composer install' + +build: + $(DC) build + +list: + $(DC) ps + +restart: stop up + +network: + if [ -z "$$(docker network ls -q -f name=canap_network)" ]; then \ + docker network create canap_network; \ + fi + diff --git a/Docker-dev/docker-compose-dev.yml b/Docker-dev/docker-compose-dev.yml new file mode 100644 index 0000000000000000000000000000000000000000..877767571fb3f9bc5e03ec8ead6f16e038200e63 --- /dev/null +++ b/Docker-dev/docker-compose-dev.yml @@ -0,0 +1,126 @@ +version: '3' + +networks: + canap_network: + external: true + +services: + # The DB of the application + db: + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: canap_db + MYSQL_DATABASE: canap_db + MYSQL_USER: canap_db + MYSQL_PASSWORD: canap_db + volumes: + - ../data/DB/init-sql:/docker-entrypoint-initdb.d + - ../data/DB/canap_db:/var/lib/mysql + ports: + - "127.0.0.1:9906:3306" + expose: + - 9906 + labels: + - "traefik.enable=false" + networks: + - canap_network + + # The form for the applicants + form: + build: + context: ./ + dockerfile: Dockerfile-form.dockerfile + depends_on: + - db + volumes: + - ../Formulaire:/var/www/html/ + environment: + ENVIRONMENT: docker + FILESERVERPATH: '/var/www/html/data/candidatures/' + SENDEMAILS: true + MAIL_FROM: 'noreply+formulaireApprentis@epfl.ch' + MAIL_CONTACT: 'leonardo.surdez@epfl.ch' + MAIL_REPLYTO: 'leonardo.surdez@epfl.ch' + DB_CONNECTION: mysql + DB_HOST: db + DB_PORT: 3306 + DB_DATABASE: canap_db + DB_USERNAME: canap_db + DB_PASSWORD: canap_db + + labels: + - traefik.enable=true + - traefik.http.routers.form.rule=Host(`localhost`) + - traefik.http.routers.form.tls=true + - traefik.http.services.form.loadbalancer.server.port=80 + networks: + - canap_network + + # The API for the management app + api: + build: + context: ./ + dockerfile: Dockerfile-api.dockerfile + volumes: + - ../API:/var/www/html/ + environment: + DB_CONNECTION: mysql + DB_HOST: db # todo + DB_PORT: 3306 # todo + DB_DATABASE: canap_db # todo + DB_USERNAME: canap_db # todo + DB_PASSWORD: canap_db # todo + TEQUILA_RETURN_URL: 'https://localhost/gest/#/?key=' + labels: + - traefik.enable=true + - traefik.http.routers.api.rule=Host(`localhost`) && PathPrefix(`/api`) + - traefik.http.routers.api.tls=true + - traefik.http.services.api.loadbalancer.server.port=80 + networks: + - canap_network + + # The management app + gest: + image: node:15-alpine + user: node + working_dir: /home/node/app + depends_on: + - api + + environment: + API_LOCATION: "https://localhost/api" + LOGIN_REDIRECT: "https://localhost/api/auth/login" + NODE_ENV: dev + volumes: + - ../Gestion:/home/node/app + - ../Formulaire/data/candidatures:/var/www/html/data/candidatures/ + entrypoint: /bin/sh + labels: + - traefik.enable=true + - traefik.http.routers.gest.rule=Host(`localhost`) && PathPrefix(`/gest`) + - traefik.http.routers.gest.tls=true + - traefik.http.services.gest.loadbalancer.server.port=8080 + command: + - "-c" + - env DEBUG=express:router npm run serve-docker + networks: + - canap_network + + traefik: + image: traefik:latest + ports: + - "80:80" + - "443:443" + - "8080:8080" + volumes: #monter le socket docker + - /var/run/docker.sock:/var/run/docker.sock + command: + - --api.insecure=true # active l'interface API de Traefik sans authentification + - --providers.docker=true + - --providers.docker.exposedbydefault=false + - --accesslog=true + - --log.level=DEBUG + - --entrypoints.web.address=:80 + - --entrypoints.websecure.address=:443 + networks: + - canap_network diff --git a/Docker/Dockerfile-api.dockerfile b/Docker/Dockerfile-api.dockerfile index e23edeb2f4c4afe8418a9c58a3794ac1c1712b6e..5242580526003fea1fe24a5fcbb662eca35ab36b 100644 --- a/Docker/Dockerfile-api.dockerfile +++ b/Docker/Dockerfile-api.dockerfile @@ -1,7 +1,8 @@ -#FROM php:7.3-stretch -FROM php:8.0-apache +FROM php:8.2-apache -RUN apt-get update; apt-get install -yq git vim zip; +WORKDIR /var/www/html/ + +RUN apt-get update; apt-get install -yq git vim zip libldap2-dev; RUN curl -sS https://getcomposer.org/installer | php RUN mv composer.phar /usr/local/bin/composer RUN export PATH=$PATH:/root/.composer/vendor/bin @@ -11,21 +12,14 @@ RUN a2enmod rewrite ENV APACHE_DOCUMENT_ROOT /var/www/html/public RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf -RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf - -# XDEBUG -RUN yes | pecl install xdebug -RUN docker-php-ext-enable xdebug - -# Enable Remote xdebug -RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/xdebug.ini -RUN echo "xdebug.default_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini -RUN echo "xdebug.client_port=9000" >> /usr/local/etc/php/conf.d/xdebug.ini -RUN echo "xdebug.discover_client_host=on" >> /usr/local/etc/php/conf.d/xdebug.ini - +RUN echo "LimitRequestFieldSize 81920" > /etc/apache2/conf-enabled/say-yes-to-bearer-tokens.conf +RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ + docker-php-ext-install ldap -# RUN chmod 777 -R /var/www/html/storage +# Copy the code into the container +COPY ./API /var/www/html/ +RUN composer update && composer install -# RUN apt-get install nodejs -y; apt-get install npm -y; -# RUN useradd -u 1000 containerUser -# RUN usermod -a -G root containerUser \ No newline at end of file +# Change permissions on copied files +RUN chown -R www-data:www-data /var/www/html/ +# USER www-data diff --git a/Docker/Dockerfile-form.dockerfile b/Docker/Dockerfile-form.dockerfile index 2b7c2703bdfd2eabf169a7ae40b91a1ccb8f107a..cbb82abdaa09768d7b4969c982383b4f7ef653ac 100644 --- a/Docker/Dockerfile-form.dockerfile +++ b/Docker/Dockerfile-form.dockerfile @@ -1,4 +1,4 @@ -FROM php:8.0-apache +FROM php:8.2-apache RUN apt-get update; RUN apt-get install -f -y msmtp msmtp-mta; @@ -16,12 +16,15 @@ RUN echo "from noreply@epfl.ch" >> /etc/msmtprc RUN echo "" >> /etc/msmtprc RUN echo "account default : epfl" >> /etc/msmtprc - #php -r "mail('nicolas.borboen@epfl.ch', 'Test Postfix', 'Test mail from postfix');" - RUN docker-php-ext-install pdo_mysql # cleanup RUN apt-get -y autoremove && apt-get -y clean; +# Copy the config into the container +COPY ./Docker/canap_apache.conf /etc/apache2/conf-enabled + +# Copy the code into the container +COPY ./form /var/www/html/ diff --git a/Docker/Dockerfile-gest.dockerfile b/Docker/Dockerfile-gest.dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d9cb600f1836682196ae6f37b002566711ec1746 --- /dev/null +++ b/Docker/Dockerfile-gest.dockerfile @@ -0,0 +1,10 @@ +FROM node:15-alpine as build +WORKDIR /home/node/app +COPY ./gest /home/node/app +RUN npm install -y && npm run build + +FROM httpd:latest +WORKDIR /root/ +COPY --from=build /home/node/app/dist /usr/local/apache2/htdocs/gest +COPY Docker/docker-entrypoint-gest.sh /docker-entrypoint.sh +CMD /docker-entrypoint.sh \ No newline at end of file diff --git a/Docker/canap_apache.conf b/Docker/canap_apache.conf new file mode 100644 index 0000000000000000000000000000000000000000..32c24849d16b1c0321c6ec282d829d0ba11a2eed --- /dev/null +++ b/Docker/canap_apache.conf @@ -0,0 +1,4 @@ +PassEnv DB_HOST DB_NAME DB_USER DB_PASSWORD +PassEnv SENDEMAILS MAIL_FROM MAIL_CONTACT MAIL_REPLYTO +PassEnv ENVIRONMENT +PassEnv FILESERVERPATH \ No newline at end of file diff --git a/Docker/docker-compose-dev.yml b/Docker/docker-compose-dev.yml deleted file mode 100644 index 3b9569472453a69f24974023ccf2a7f1299c81c4..0000000000000000000000000000000000000000 --- a/Docker/docker-compose-dev.yml +++ /dev/null @@ -1,71 +0,0 @@ -version: '3' - -services: - - # The DB of the application - db: - image: mysql:5.7 - container_name: canap_db - environment: - MYSQL_ROOT_PASSWORD: canap_db - MYSQL_DATABASE: canap_db - MYSQL_USER: canap_db - MYSQL_PASSWORD: canap_db - #command: mysqld --general-log=1 --general-log-file=/var/log/mysql/general-log.log - volumes: - - ../data/DB/init-sql:/docker-entrypoint-initdb.d - - ../data/DB/canap_db:/var/lib/mysql - ports: - - "9906:3306" - expose: - - 9906 - - # The form for the applicants - form: - build: - context: ./ - dockerfile: Dockerfile-form.dockerfile - container_name: canap_form - depends_on: - - db - volumes: - - ../Formulaire:/var/www/html/ - - ../data/candidatures:/var/www/html/data/candidatures/ - ports: - - "8180:80" - - # The API for the management app - api: - build: - context: ./ - dockerfile: Dockerfile-api.dockerfile - container_name: canap_api - volumes: - - ../API:/var/www/html/ - ports: - - "8181:80" - - # The management app - gest: - image: node:15-alpine - container_name: canap_gest - user: node - working_dir: /home/node/app - depends_on: - - api - environment: - - NODE_ENV=development #production - volumes: - - ../Gestion:/home/node/app - ports: - - "8080:8080" - entrypoint: /bin/sh - command: - - "-c" - - npm i && npm run serve-docker - -# networks: -# default: -# external: -# name: canap_network - diff --git a/Docker/docker-compose-form.yml b/Docker/docker-compose-form.yml deleted file mode 100644 index 9c383c32a1ae3db919729137cfd1451c8233190c..0000000000000000000000000000000000000000 --- a/Docker/docker-compose-form.yml +++ /dev/null @@ -1,35 +0,0 @@ -version: '3' - -services: - db: - image: mysql:5.7 - container_name: canap_db - environment: - MYSQL_ROOT_PASSWORD: canap_db - MYSQL_DATABASE: canap_db - MYSQL_USER: canap_db - MYSQL_PASSWORD: canap_db - volumes: - - ./DB/SQL:/docker-entrypoint-initdb.d - - ./DB/data:/var/lib/mysql - ports: - - "9906:3306" - expose: - - 9906 - form: - build: - context: ./ - dockerfile: Dockerfile-form.dockerfile - container_name: canap_form - depends_on: - - db - volumes: - - .:/var/www/html/ - ports: - - "8180:80" - -networks: - default: - external: - name: canap_network - diff --git a/Docker/docker-compose-gest.yml b/Docker/docker-compose-gest.yml deleted file mode 100644 index 2e9cde9d193924fce17b5cfaffafefc5cb531ff9..0000000000000000000000000000000000000000 --- a/Docker/docker-compose-gest.yml +++ /dev/null @@ -1,35 +0,0 @@ -version: '3' - -services: - api: - build: - context: ./ - dockerfile: Dockerfile-api.dockerfile - container_name: canap_api - volumes: - - ./API:/var/www/html/ - ports: - - "8181:80" - - gest: - image: node:15-alpine - container_name: canap_gest - user: node - working_dir: /home/node/app - depends_on: - - api - environment: - - NODE_ENV=development #production - volumes: - - ./Site:/home/node/app - ports: - - "8080:8080" - entrypoint: /bin/sh - command: - - "-c" - - npm i && npm run serve-docker - -networks: - default: - external: - name: canap_network \ No newline at end of file diff --git a/Docker/docker-entrypoint-gest.sh b/Docker/docker-entrypoint-gest.sh new file mode 100755 index 0000000000000000000000000000000000000000..7b0223bd223e5216d0a1a6c4290fb36898c61668 --- /dev/null +++ b/Docker/docker-entrypoint-gest.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e -x + +# Substitute 12-factored env vars now (we couldn't do that at compile time +# because we don't know the values until runtime). +# sed -i -e "s|_REPLACE_ME_LATER__API_LOCATION|$API_LOCATION|" \ +# -e "s|_REPLACE_ME_LATER__LOGIN_REDIRECT|$LOGIN_REDIRECT|" \ +# /usr/local/apache2/htdocs/gest/js/app.*.js + +exec /usr/local/bin/httpd-foreground