From cd8fbe4400ade272557e67854f18b07387989aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20H=C3=A4ber?= Date: Mon, 5 Jun 2023 17:43:16 +0200 Subject: [PATCH] feat(FIAP-197): use alpine and update composer --- composer.json | 10 +++--- docker/.env | 3 ++ docker/Dockerfile | 47 -------------------------- docker/docker-compose.dev.yml | 25 ++++++++++++++ docker/docker-compose.yml | 12 ------- docker/php/Dockerfile | 37 ++++++++++++++++++++ docker/php/files/bin/php-ext-disable | 12 +++++++ docker/php/files/bin/php-ext-enable | 20 +++++++++++ docker/php/files/user-home/.bashrc | 7 ++++ docker/php/files/user-home/.ssh/config | 4 +++ test.php | 23 ------------- 11 files changed, 113 insertions(+), 87 deletions(-) create mode 100644 docker/.env delete mode 100644 docker/Dockerfile create mode 100644 docker/docker-compose.dev.yml delete mode 100644 docker/docker-compose.yml create mode 100644 docker/php/Dockerfile create mode 100755 docker/php/files/bin/php-ext-disable create mode 100755 docker/php/files/bin/php-ext-enable create mode 100644 docker/php/files/user-home/.bashrc create mode 100644 docker/php/files/user-home/.ssh/config delete mode 100644 test.php diff --git a/composer.json b/composer.json index db81c040..1896ff58 100644 --- a/composer.json +++ b/composer.json @@ -14,19 +14,19 @@ "email": "peter.pl7@gmail.com" } ], + "repositories": [ + {"type": "vcs", "no-api": true, "url": "git@github.com:jobcloud/zendpdf.git"} + ], "require": { "ext-mbstring": "*", - "jobcloud/zendpdf": "^1.0.0" + "jobcloud/zendpdf": "^2.0.3" }, "require-dev": { "imagine/imagine": ">=0.2.0,<0.6.0", - "phpunit/phpunit": "^9.6.7" + "phpunit/phpunit": "^8.5.33" }, "prefer-stable": true, "minimum-stability": "dev", - "repositories": [ - {"type": "vcs", "no-api": true, "url": "git@github.com:jobcloud/ZendPdf.git"} - ], "suggest": { "imagine/imagine": "If you want to use image generating (required version: >=v0.2.6)" }, diff --git a/docker/.env b/docker/.env new file mode 100644 index 00000000..7f5ec0f1 --- /dev/null +++ b/docker/.env @@ -0,0 +1,3 @@ +COMPOSE_PROJECT_NAME=jobcloud-phppdf +XDEBUG_REMOTE_HOST=localhost +#XDEBUG_REMOTE_HOST=docker.for.mac.localhost diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index cd6a5e30..00000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,47 +0,0 @@ -FROM php:8.1-fpm - -# Set Environment Variables -ENV DEBIAN_FRONTEND noninteractive - -# -#-------------------------------------------------------------------------- -# Software's Installation -#-------------------------------------------------------------------------- -# -# Installing tools and PHP extentions using "apt", "docker-php", "pecl", -# - -# Install "curl", "libmemcached-dev", "libpq-dev", "libjpeg-dev", -# "libpng-dev", "libfreetype6-dev", "libssl-dev", "libmcrypt-dev", -RUN set -eux; \ - apt-get update; \ - apt-get upgrade -y; \ - apt-get install -y --no-install-recommends \ - git \ - curl \ - libmemcached-dev \ - libz-dev \ - libpq-dev \ - libjpeg-dev \ - libpng-dev \ - libfreetype6-dev \ - libssl-dev \ - libwebp-dev \ - libxpm-dev \ - libmcrypt-dev \ - libonig-dev; \ - rm -rf /var/lib/apt/lists/* - -RUN set -eux; \ - # Install the PHP gd library - docker-php-ext-configure gd \ - --prefix=/usr \ - --with-jpeg \ - --with-webp \ - --with-xpm \ - --with-freetype; \ - docker-php-ext-install gd; \ - php -r 'var_dump(gd_info());' - -# install composer -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml new file mode 100644 index 00000000..8446521f --- /dev/null +++ b/docker/docker-compose.dev.yml @@ -0,0 +1,25 @@ +version: '3.9' +services: + php: + container_name: jobcloud-phppdf-php + hostname: jobcloud-phppdf-php + build: + dockerfile: php/Dockerfile + context: ./ + args: + USER_ID: ${USER_ID} + ports: + - '8080:80' + tty: true + volumes: + - ../:/var/www/html + - ~/.bash_aliases:/home/www-data/.bash_aliases:rw + - ~/.bash_history:/home/www-data/.bash_history:rw + secrets: + - ssh_host_key + environment: + XDEBUG_CONFIG: remote_host=${XDEBUG_REMOTE_HOST} + PHP_IDE_CONFIG: serverName=php +secrets: + ssh_host_key: + file: ~/.ssh/id_rsa \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml deleted file mode 100644 index dc2ecdc8..00000000 --- a/docker/docker-compose.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: '3.9' - -services: - php: - container_name: php-pdf - build: - dockerfile: ./Dockerfile - context: ./ - ports: - - '8080:80' - volumes: - - ../:/var/www/html diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 00000000..1a1eb88d --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,37 @@ +FROM php:8.1-alpine3.18 + +ARG USER_ID + +# PHP: Copy configuration files & remove dist files +RUN mkdir /phpIni +COPY php/files/bin/ /usr/local/bin/ + +# SYS: Install required packages +RUN apk --no-cache upgrade && \ + apk --no-cache add bash git sudo openssh autoconf gcc g++ make gettext sudo shadow + +RUN if [ -n "$USER_ID" ] && [ "$USER_ID" -lt 60001 ]; then \ + usermod -u ${USER_ID} -o www-data; \ + fi + +# USER: set /bin/bash and allow www-data to become root +RUN usermod -s /bin/bash www-data && \ + echo 'www-data ALL=(ALL) NOPASSWD: ALL' > '/etc/sudoers.d/www-data' + +# USER: copy home +COPY --chown=www-data:www-data php/files/user-home /home/www-data + +# USER: add ssh key and fix permission of the ssh directory +RUN ln -s /run/secrets/ssh_host_key /home/www-data/.ssh/id_rsa && \ + chmod 700 /home/www-data/.ssh && \ + chmod 400 /home/www-data/.ssh/config + +# PHP: Install php extensions +RUN pecl channel-update pecl.php.net + +# COMPOSER: install binary +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer + +USER www-data + +WORKDIR /var/www/html diff --git a/docker/php/files/bin/php-ext-disable b/docker/php/files/bin/php-ext-disable new file mode 100755 index 00000000..1f6f68f8 --- /dev/null +++ b/docker/php/files/bin/php-ext-disable @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ $# -eq 0 ] + then + echo "Please pass a php module name" + exit +fi + +for phpmod in "$@" +do + rm -f /usr/local/etc/php/conf.d/*$phpmod*.ini +done diff --git a/docker/php/files/bin/php-ext-enable b/docker/php/files/bin/php-ext-enable new file mode 100755 index 00000000..43e06b92 --- /dev/null +++ b/docker/php/files/bin/php-ext-enable @@ -0,0 +1,20 @@ +#!/bin/bash + +if [[ ${#} -eq 0 ]] ; then + echo -e "\\nPHP module name required!\\n" + exit 1 +fi + +for phpmod in "${@}" ; do + + files=($(find /phpIni -type f -iname "*${phpmod}*.ini" -exec ls -1 '{}' +)) + + for i in "${files[@]}" ; do + ln -s "${i}" /usr/local/etc/php/conf.d + done + + if [[ ${#files[@]} -eq 0 ]] ; then + docker-php-ext-enable "${phpmod}" + fi + +done diff --git a/docker/php/files/user-home/.bashrc b/docker/php/files/user-home/.bashrc new file mode 100644 index 00000000..8c1d66f2 --- /dev/null +++ b/docker/php/files/user-home/.bashrc @@ -0,0 +1,7 @@ +alias cls='printf "\033c"' + +export PS1='\[\e[1;32m\]\h\[\e[0m\] \[\e[1;37m\]\w\[\e[0m\] \[\e[1;32m\]\u\[\e[0m\] \[\e[1;37m\]\$\[\e[0m\] ' + +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi diff --git a/docker/php/files/user-home/.ssh/config b/docker/php/files/user-home/.ssh/config new file mode 100644 index 00000000..2113240a --- /dev/null +++ b/docker/php/files/user-home/.ssh/config @@ -0,0 +1,4 @@ +Host * + StrictHostKeyChecking no + UserKnownHostsFile /dev/null + IdentityFile /run/secrets/ssh_host_key diff --git a/test.php b/test.php deleted file mode 100644 index e9dbddb7..00000000 --- a/test.php +++ /dev/null @@ -1,23 +0,0 @@ -getData());