Skip to content

Commit c5ca083

Browse files
committed
Add PHP/Apache image to expose GLPI over http
1 parent 46e4947 commit c5ca083

File tree

3 files changed

+218
-0
lines changed

3 files changed

+218
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: "Github actions PHP images with Apache server"
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
paths:
8+
- ".github/workflows/githubactions-php-apache.yml"
9+
- "githubactions-php-apache/**"
10+
pull_request:
11+
paths:
12+
- ".github/workflows/githubactions-php-apache.yml"
13+
- "githubactions-php-apache/**"
14+
schedule:
15+
- cron: '0 0 * * 1'
16+
# Enable manual run
17+
workflow_dispatch:
18+
19+
jobs:
20+
build:
21+
runs-on: "ubuntu-latest"
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
include:
26+
- {base-image: "php:8.1-apache-bullseye", php-version: "8.1"}
27+
- {base-image: "php:8.2-apache-bullseye", php-version: "8.2"}
28+
- {base-image: "php:8.3-apache-bullseye", php-version: "8.3"}
29+
steps:
30+
- name: "Set variables"
31+
run: |
32+
OUTPUTS="type=image"
33+
if [[ "${{ github.ref }}" = 'refs/heads/main' && "${{ github.repository }}" = 'glpi-project/docker-images' ]]; then
34+
OUTPUTS="$OUTPUTS,push=true"
35+
fi
36+
echo "OUTPUTS=$OUTPUTS" >> $GITHUB_ENV
37+
- name: "Checkout"
38+
uses: "actions/checkout@v4"
39+
- name: "Set up Docker Buildx"
40+
uses: "docker/setup-buildx-action@v3"
41+
- name: "Login to DockerHub"
42+
uses: "docker/login-action@v3"
43+
with:
44+
username: "${{ secrets.DOCKER_HUB_USERNAME }}"
45+
password: "${{ secrets.DOCKER_HUB_TOKEN }}"
46+
- name: "Login to Github container registry"
47+
uses: "docker/login-action@v3"
48+
with:
49+
registry: "ghcr.io"
50+
username: "${{ secrets.GHCR_USERNAME }}"
51+
password: "${{ secrets.GHCR_ACCESS_TOKEN }}"
52+
- name: "Build and push"
53+
uses: "docker/build-push-action@v5"
54+
with:
55+
build-args: |
56+
BASE_IMAGE=${{ matrix.base-image }}
57+
cache-from: "type=gha"
58+
cache-to: "type=gha,mode=max"
59+
context: "githubactions-php-apache"
60+
outputs: "${{ env.OUTPUTS }}"
61+
pull: true
62+
tags: "ghcr.io/glpi-project/githubactions-php-apache:${{ matrix.php-version }}"

githubactions-php-apache/Dockerfile

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
ARG BASE_IMAGE=php:apache-bullseye
2+
3+
4+
#####
5+
# Fetch composer latest build
6+
#####
7+
FROM composer:latest AS composer
8+
9+
#####
10+
# Build main image
11+
#####
12+
FROM $BASE_IMAGE
13+
14+
LABEL \
15+
org.opencontainers.image.title="GLPI Github Actions PHP container" \
16+
org.opencontainers.image.description="This container is used to run GLPI test suite on Github Actions." \
17+
org.opencontainers.image.url="https://github.com/glpi-project/docker-images" \
18+
org.opencontainers.image.source="[email protected]:glpi-project/docker-images"
19+
20+
RUN \
21+
# Update package list.
22+
apt update \
23+
\
24+
# Install exif extension.
25+
&& docker-php-ext-install exif \
26+
\
27+
# Install GD PHP extension.
28+
&& apt install --assume-yes --no-install-recommends --quiet libfreetype6-dev libjpeg-dev libpng-dev libwebp-dev \
29+
&& docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
30+
&& docker-php-ext-install gd \
31+
\
32+
# Install intl PHP extension.
33+
&& apt install --assume-yes --no-install-recommends --quiet libicu-dev \
34+
&& docker-php-ext-install intl \
35+
\
36+
# Install ldap PHP extension.
37+
&& apt install --assume-yes --no-install-recommends --quiet libldap2-dev \
38+
&& docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ \
39+
&& docker-php-ext-install ldap \
40+
\
41+
# Install memcached PHP extension.
42+
&& apt install --assume-yes --no-install-recommends --quiet libmemcached-dev \
43+
&& pecl install memcached \
44+
&& docker-php-ext-enable memcached \
45+
\
46+
# Install mysqli PHP extension.
47+
&& docker-php-ext-install mysqli \
48+
\
49+
# Install pcntl PHP extension (required for composer-require-checker).
50+
&& docker-php-ext-install pcntl \
51+
\
52+
# Install redis PHP extension.
53+
&& pecl install redis \
54+
&& docker-php-ext-enable redis \
55+
\
56+
# Install Zip PHP extension.
57+
&& apt install --assume-yes --no-install-recommends --quiet libzip-dev \
58+
&& docker-php-ext-install zip \
59+
\
60+
# Install XMLRPC PHP extension.
61+
# Install from Github (extension should be available on PECL but is not)
62+
&& apt install --assume-yes --no-install-recommends --quiet libxml2-dev \
63+
&& mkdir -p /tmp/xmlrpc \
64+
&& (curl -LsfS https://github.com/php/pecl-networking-xmlrpc/archive/0f782ffe52cebd0a65356427b7ab72d48b72d20c/xmlrpc-0f782ff.tar.gz | tar xvz -C "/tmp/xmlrpc" --strip 1) \
65+
&& docker-php-ext-configure /tmp/xmlrpc --with-xmlrpc \
66+
&& docker-php-ext-install /tmp/xmlrpc \
67+
&& rm -rf /tmp/xmlrpc \
68+
\
69+
# Install APCU PHP extension.
70+
&& pecl install apcu \
71+
&& docker-php-ext-enable apcu \
72+
&& echo "apc.enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini \
73+
&& echo "apc.enable_cli=1" >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini \
74+
\
75+
# Update PHP configuration.
76+
&& echo "memory_limit = 512M" >> /usr/local/etc/php/conf.d/docker-php-memory.ini \
77+
\
78+
# Disable sodium PHP extension (Test should validate that polyfill works).
79+
&& rm /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini \
80+
\
81+
# Enable apache mods.
82+
&& a2enmod rewrite \
83+
\
84+
# Install nodejs and npm.
85+
&& apt install --assume-yes --no-install-recommends --quiet gnupg \
86+
&& mkdir -p /etc/apt/keyrings \
87+
&& curl --fail --silent --show-error --location https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor --output /etc/apt/keyrings/nodesource.gpg \
88+
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
89+
&& apt update \
90+
&& apt install --assume-yes --no-install-recommends --quiet nodejs \
91+
\
92+
# Install git and zip used by composer when fetching dependencies.
93+
&& apt install --assume-yes --no-install-recommends --quiet git unzip \
94+
\
95+
# Install gettext used for translation files.
96+
&& apt install --assume-yes --no-install-recommends --quiet gettext \
97+
\
98+
# Install Cypress dependencies
99+
&& apt install --assume-yes --no-install-recommends --quiet libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb \
100+
\
101+
# Install acl and sudo that will be used to give correct rights in the Gihub Actions runner context.
102+
# sudo may also be usefull to temporarly install upcoming required system components.
103+
&& apt install --assume-yes --no-install-recommends --quiet acl sudo \
104+
\
105+
# Clean sources list
106+
&& rm -rf /var/lib/apt/lists/*
107+
108+
# Copy composer binary
109+
COPY --from=composer /usr/bin/composer /usr/bin/composer
110+
111+
# Copy files to container
112+
COPY ./files/etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf
113+
114+
RUN \
115+
# Workaround to make apache use same UID/GID as usual host user.
116+
# It permit to prevent rights issues when executing tests from the `tests/run_tests.sh` script.
117+
groupmod --gid 1000 www-data \
118+
&& usermod --uid 1000 www-data \
119+
\
120+
# Allow executing commands as www-data with `sudo -l www-data`
121+
&& usermod --shell /bin/bash www-data \
122+
\
123+
# Create home volume, to be able to share home data data across jobs.
124+
&& mkdir --parents /home/www-data \
125+
&& chown www-data:www-data /home/www-data \
126+
&& usermod --home /home/www-data www-data \
127+
\
128+
# Create application volume.
129+
&& mkdir --parents /var/www/glpi \
130+
&& chown www-data:www-data /var/www/glpi
131+
132+
RUN \
133+
# Create a user with UID=1001 (the UID used by Github Actions runner) and add it to sudoers.
134+
# This is mandatory to bypass rights issues during checkout and to be able to then execute scripts as www-data user.
135+
useradd -m -d /home/github-actions-runner -g www-data -u 1001 github-actions-runner \
136+
&& (echo "github-actions-runner ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/glpi)
137+
138+
VOLUME /home/www-data
139+
VOLUME /var/www/glpi
140+
141+
USER www-data
142+
WORKDIR /var/www/glpi
143+
144+
# Define GLPI environment variables
145+
ENV \
146+
GLPI_ENVIRONMENT_TYPE=testing
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<VirtualHost *:80>
2+
DocumentRoot /var/www/glpi/public
3+
<Directory /var/www/glpi/public>
4+
Require all granted
5+
RewriteEngine On
6+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
7+
RewriteCond %{REQUEST_FILENAME} !-f
8+
RewriteRule ^(.*)$ index.php [QSA,L]
9+
</Directory>
10+
</VirtualHost>

0 commit comments

Comments
 (0)