From a18226c63b077bf0aa6d377bb8e839431d129638 Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Tue, 6 Apr 2021 16:16:44 +0200 Subject: [PATCH] Add a standalone docker image for gitlab CI testing Otherwise this depends on the core bundle image and we don't want that image to become public API. --- .gitlab-ci.yml | 2 +- .gitlab-ci/Dockerfile | 81 ++++++++++++++++++++++++++++++++ .gitlab-ci/README.md | 4 ++ .gitlab-ci/build.sh | 9 ++++ .gitlab-ci/php-ini-overrides.ini | 1 + 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 .gitlab-ci/Dockerfile create mode 100644 .gitlab-ci/README.md create mode 100755 .gitlab-ci/build.sh create mode 100644 .gitlab-ci/php-ini-overrides.ini diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9477420..5de5176 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: registry.gitlab.tugraz.at/dbp/middleware/dbp-api/api-core-bundle/main:v1 +image: registry.gitlab.tugraz.at/dbp/middleware/dbp-api/api-server-template/main:v1 before_script: - 'git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.tugraz.at/".insteadOf "git@gitlab.tugraz.at:"' diff --git a/.gitlab-ci/Dockerfile b/.gitlab-ci/Dockerfile new file mode 100644 index 0000000..83bd83a --- /dev/null +++ b/.gitlab-ci/Dockerfile @@ -0,0 +1,81 @@ +FROM debian:buster + +ENV LANG C.UTF-8 +ENV DEBIAN_FRONTEND noninteractive + +# Basics +RUN apt-get update && apt-get install -y \ + composer \ + php-zip \ + rsync \ + sudo \ + wget \ + curl \ + lsb-release \ + && rm -rf /var/lib/apt/lists/* + +# PHP Repo +RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg +RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list + +# PHP 7.3 +RUN apt-get update && apt-get install -y \ + php7.3 \ + php7.3-curl \ + php7.3-soap \ + php7.3-xml \ + php7.3-ldap \ + php7.3-zip \ + php7.3-gmp \ + php7.3-xdebug \ + php7.3-mbstring \ + && rm -rf /var/lib/apt/lists/* +COPY ./php-ini-overrides.ini /etc/php/7.3/cli/conf.d/ + +# PHP 7.4 +RUN apt-get update && apt-get install -y \ + php7.4 \ + php7.4-curl \ + php7.4-soap \ + php7.4-xml \ + php7.4-ldap \ + php7.4-zip \ + php7.4-gmp \ + php7.4-xdebug \ + php7.4-mbstring \ + && rm -rf /var/lib/apt/lists/* +COPY ./php-ini-overrides.ini /etc/php/7.4/cli/conf.d/ + +# PHP 8.0 +# FIXME: php8.0-xdebug not installed because it leads to segfaults +# https://gitlab.tugraz.at/dbp/middleware/api/-/issues/65#note_21039 +RUN apt-get update && apt-get install -y \ + php8.0 \ + php8.0-curl \ + php8.0-soap \ + php8.0-xml \ + php8.0-ldap \ + php8.0-zip \ + php8.0-gmp \ + php8.0-mbstring \ + && rm -rf /var/lib/apt/lists/* +COPY ./php-ini-overrides.ini /etc/php/8.0/cli/conf.d/ + +# Default to PHP 7.3 +RUN sudo update-alternatives --set php /usr/bin/php7.3 +RUN sudo update-alternatives --set phar /usr/bin/phar7.3 +RUN sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.3 + +# Add a normal user and enable sudo +RUN useradd -u 1000 -ms /bin/bash user +RUN echo 'user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +USER user + +# Install a newer composer +RUN mkdir -p /home/user/.local/bin +WORKDIR /home/user/.local/bin +RUN wget https://raw.githubusercontent.com/composer/getcomposer.org/bfd95e2a4383ee9cf7c058c2df29d7acb5f86d77/web/installer -O - -q | php -- +RUN mv composer.phar composer +ENV PATH "/home/user/.local/bin:$PATH" + +WORKDIR /home/user \ No newline at end of file diff --git a/.gitlab-ci/README.md b/.gitlab-ci/README.md new file mode 100644 index 0000000..3465c9b --- /dev/null +++ b/.gitlab-ci/README.md @@ -0,0 +1,4 @@ +* In case of an incompatible change increase the tag version number in build.sh +* ./build.sh +* (first time) sudo docker login registry.gitlab.tugraz.at +* sudo docker push registry.gitlab.tugraz.at/dbp/middleware/dbp-api/api-server-template/main:v1 \ No newline at end of file diff --git a/.gitlab-ci/build.sh b/.gitlab-ci/build.sh new file mode 100755 index 0000000..52192df --- /dev/null +++ b/.gitlab-ci/build.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e +TAG="registry.gitlab.tugraz.at/dbp/middleware/dbp-api/api-server-template/main:v1" +sudo docker build --tag "${TAG}" --file "Dockerfile" . +sudo docker run --rm --security-opt label=disable \ + --volume "$(pwd)/..:/home/user/app" --workdir "/home/user/app" \ + --tty --interactive "${TAG}" bash +echo "Now run: sudo docker push '$TAG'" diff --git a/.gitlab-ci/php-ini-overrides.ini b/.gitlab-ci/php-ini-overrides.ini new file mode 100644 index 0000000..83a1116 --- /dev/null +++ b/.gitlab-ci/php-ini-overrides.ini @@ -0,0 +1 @@ +zend.assertions = 1 \ No newline at end of file -- GitLab