Skip to content

Commit 1228bb1

Browse files
authored
Merge pull request #44 from moveis-simonetti/one-for-all
one for all
2 parents 3007c2c + fc1fda8 commit 1228bb1

File tree

11 files changed

+439
-35
lines changed

11 files changed

+439
-35
lines changed
Lines changed: 111 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,45 @@
1-
name: Publish Docker image
1+
name: Build & Publish
22

33
on:
4-
push:
5-
branches: ["master", "php*"]
4+
workflow_call:
5+
inputs:
6+
version:
7+
type: string
8+
required: true
9+
name:
10+
type: string
11+
required: true
12+
template:
13+
type: string
14+
required: false
15+
base:
16+
type: string
17+
required: true
18+
xdebug_version:
19+
type: string
20+
required: true
21+
redis_version:
22+
type: string
23+
required: true
24+
imap_type:
25+
type: string
26+
required: true
27+
imap_version:
28+
type: string
29+
required: true
30+
php_errors_enabled:
31+
type: boolean
32+
required: true
33+
variations:
34+
type: string
35+
required: true
36+
push:
37+
type: boolean
38+
default: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
639

740
jobs:
8-
push_to_registry:
9-
name: Push Docker image to Docker Hub
41+
build:
42+
name: Build Docker image
1043
runs-on: ubuntu-latest
1144

1245
permissions:
@@ -17,6 +50,33 @@ jobs:
1750
- name: Check out the repo
1851
uses: actions/checkout@v4
1952

53+
- name: install go-replace
54+
env:
55+
GOREPLACE_VERSION: 22.9.0
56+
run: |
57+
wget -O /usr/local/bin/go-replace \
58+
https://github.com/webdevops/go-replace/releases/download/$GOREPLACE_VERSION/go-replace.linux.amd64
59+
chmod +x /usr/local/bin/go-replace
60+
61+
- name: build Dockerfile
62+
env:
63+
DOCKER_BUILD_VERSION: ${{ inputs.version }}
64+
DOCKER_BUILD_BASE: ${{ inputs.base }}
65+
DOCKER_BUILD_XDEBUG_VERSION: ${{ inputs.xdebug_version }}
66+
DOCKER_BUILD_REDIS_VERSION: ${{ inputs.redis_version }}
67+
DOCKER_BUILD_IMAP_TYPE: ${{ inputs.imap_type }}
68+
DOCKER_BUILD_IMAP_VERSION: ${{ inputs.imap_version }}
69+
DOCKER_BUILD_PHP_ERRORS_ENABLED: ${{ inputs.php_errors_enabled && '1' || '0' }}
70+
run: |
71+
go-replace --mode=template ./${{ inputs.template }} -o ./Dockerfile
72+
73+
- name: add Dockerfile to summary
74+
run: |
75+
echo '### Dockerfile generated for ${{ inputs.name }}' >> $GITHUB_STEP_SUMMARY
76+
echo '```dockerfile' >> $GITHUB_STEP_SUMMARY
77+
cat Dockerfile >> $GITHUB_STEP_SUMMARY
78+
echo '```' >> $GITHUB_STEP_SUMMARY
79+
2080
- name: Log in to Docker Hub
2181
uses: docker/login-action@v3
2282
with:
@@ -28,22 +88,57 @@ jobs:
2888
uses: docker/metadata-action@v5
2989
with:
3090
images: lojassimonetti/php-apache-oci8-composer
91+
tags: |
92+
type=raw,value=${{ inputs.name }},enable=true
3193
32-
- name: Should push?
33-
id: shoudPush
34-
run: |
35-
if [[ ${{ github.event.ref }} = "refs/heads/master" ]]; then
36-
echo "match=true" >> $GITHUB_OUTPUT
37-
elif [[ ${{ github.event.ref }} =~ ^refs/heads/php[0-9]dot[0-9]$ ]]; then
38-
echo "match=true" >> $GITHUB_OUTPUT
39-
elif [[ ${{ github.event.ref }} =~ ^refs/heads/php[0-9]dot[0-9]-mongodb$ ]]; then
40-
echo "match=true" >> $GITHUB_OUTPUT
41-
fi
94+
- name: Build and push Docker image
95+
uses: docker/build-push-action@v5
96+
with:
97+
context: .
98+
push: ${{ inputs.push }}
99+
tags: ${{ steps.meta.outputs.tags }}
100+
labels: ${{ steps.meta.outputs.labels }}
101+
102+
build_variations:
103+
name: Build image variation
104+
runs-on: ubuntu-latest
105+
106+
needs:
107+
- build
108+
109+
strategy:
110+
fail-fast: false
111+
matrix:
112+
variation: ${{ fromJson(inputs.variations) }}
113+
114+
permissions:
115+
packages: write
116+
contents: read
117+
118+
steps:
119+
- name: Check out the repo
120+
uses: actions/checkout@v4
121+
122+
- name: Log in to Docker Hub
123+
uses: docker/login-action@v3
124+
with:
125+
username: ${{ secrets.DOCKER_USERNAME }}
126+
password: ${{ secrets.DOCKER_PASSWORD }}
127+
128+
- name: Extract metadata (tags, labels) for Docker
129+
id: meta
130+
uses: docker/metadata-action@v5
131+
with:
132+
images: lojassimonetti/php-apache-oci8-composer
133+
tags: |
134+
type=raw,value=${{ inputs.name }}-${{ matrix.variation }},enable=true
42135
43136
- name: Build and push Docker image
44137
uses: docker/build-push-action@v5
45138
with:
46139
context: .
47-
push: ${{ steps.shoudPush.outputs.match == 'true' }}
140+
build-args: IMAGE_BASE=lojassimonetti/php-apache-oci8-composer:${{ inputs.name }}
141+
file: ./Dockerfile.${{ matrix.variation }}
142+
push: ${{ inputs.push }}
48143
tags: ${{ steps.meta.outputs.tags }}
49144
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/setup-build.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish Docker image
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
setup:
8+
name: Setup Matrix Build
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
packages: write
13+
contents: read
14+
15+
outputs:
16+
versions: ${{ steps.read.outputs.versions }}
17+
18+
steps:
19+
- name: Check out the repo
20+
uses: actions/checkout@v5
21+
22+
- name: read configs
23+
id: read
24+
run: |
25+
echo "versions=$(cat config.json | jq . --compact-output)" >> "$GITHUB_OUTPUT"
26+
27+
docker_build_push:
28+
name: Build and Push
29+
needs:
30+
- setup
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
config: ${{ fromJson(needs.setup.outputs.versions) }}
36+
37+
uses: ./.github/workflows/docker-build.yaml
38+
secrets: inherit
39+
with:
40+
name: ${{ matrix.config.name }}
41+
base: ${{ matrix.config.base }}
42+
template: ${{ matrix.config.template || 'Dockerfile.tmpl' }}
43+
version: ${{ matrix.config.version }}
44+
xdebug_version: ${{ matrix.config.xdebug_version }}
45+
redis_version: ${{ matrix.config.redis_version }}
46+
imap_version: ${{ matrix.config.imap_version }}
47+
imap_type: ${{ matrix.config.imap_type }}
48+
php_errors_enabled: ${{ matrix.config.php_errors_enabled }}
49+
variations: ${{ toJson(matrix.config.variations) }}

Dockerfile.grpc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ARG IMAGE_BASE
2+
FROM ${IMAGE_BASE}
3+
4+
USER root
5+
6+
RUN echo "---> GRPC" && \
7+
pecl install grpc && \
8+
docker-php-ext-enable grpc
9+
10+
USER www-data:www-data

Dockerfile.mongodb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ARG IMAGE_BASE
2+
FROM ${IMAGE_BASE}
3+
4+
USER root
5+
6+
RUN echo "---> Mongo DB" && \
7+
pecl install mongodb && \
8+
docker-php-ext-enable mongodb
9+
10+
USER www-data:www-data

Dockerfile.mongodb-1.21.0

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ARG IMAGE_BASE
2+
FROM ${IMAGE_BASE}
3+
4+
USER root
5+
6+
RUN echo "---> Mongo DB" && \
7+
pecl install mongodb-1.21.0 && \
8+
docker-php-ext-enable mongodb
9+
10+
USER www-data:www-data

Dockerfile.pgsql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ARG IMAGE_BASE
2+
FROM ${IMAGE_BASE}
3+
4+
USER root
5+
6+
RUN echo "---> PGSQL" && \
7+
apt-get update && apt-get install -y --no-install-recommends libpq-dev && \
8+
docker-php-ext-install pdo_pgsql
9+
10+
USER www-data:www-data

Dockerfile.swoole.tmpl

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{{ $version := float64 (env "DOCKER_BUILD_VERSION") -}}
2+
FROM {{ env "DOCKER_BUILD_BASE" }}
3+
4+
ENV \
5+
NR_ENABLED=false \
6+
NR_APP_NAME="" \
7+
NR_LICENSE_KEY="" \
8+
NR_VERSION="" \
9+
PHP_OPCACHE_ENABLED=false \
10+
SESSION_HANDLER=false \
11+
SESSION_HANDLER_NAME="" \
12+
SESSION_HANDLER_PATH="" \
13+
XDEBUG_AUTOSTART=false \
14+
XDEBUG_CONNECT_BACK=true \
15+
XDEBUG_ENABLED=false \
16+
XDEBUG_IDEKEY="docker" \
17+
XDEBUG_VERSION="{{ if not (eq (env "DOCKER_BUILD_XDEBUG_VERSION") "") -}}
18+
-{{ env "DOCKER_BUILD_XDEBUG_VERSION" }}
19+
{{- end }}" \
20+
REDIS_VERSION="{{ if not (eq (env "DOCKER_BUILD_REDIS_VERSION") "") -}}
21+
-{{ env "DOCKER_BUILD_REDIS_VERSION" }}
22+
{{- end }}" \
23+
IMAP_VERSION="{{ if not (eq (env "DOCKER_BUILD_IMAP_VERSION") "") -}}
24+
-{{ env "DOCKER_BUILD_IMAP_VERSION" }}
25+
{{- end }}" \
26+
XDEBUG_REMOTE_PORT=9000 \
27+
PHP_EXTENSION_WDDX=1 \
28+
PHP_OPENSSL=1 \
29+
CONTAINER_STARTED_LOCK=/var/lock/container.starting
30+
31+
RUN apt-get update && apt-get install -y --no-install-recommends wget vim supervisor libfreetype6-dev libjpeg-dev libjpeg62-turbo-dev \
32+
libmcrypt-dev libpng-dev libssl-dev libaio1 git libcurl4-openssl-dev libxslt-dev \
33+
libldap2-dev libicu-dev libc-client-dev libkrb5-dev libsqlite3-dev libedit-dev \
34+
sudo zlib1g zlib1g-dev libzip4 libzip-dev zip unzip librabbitmq-dev{{ if gt $version 7.4 }} musl-dev{{end}} && \
35+
rm -rf /var/lib/apt/lists/*
36+
37+
RUN docker-php-ext-configure gd --with-jpeg \
38+
&& docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ \
39+
{{- if eq (env "DOCKER_BUILD_IMAP_TYPE") "php-ext" }}
40+
&& docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
41+
{{- end }}
42+
&& docker-php-ext-install -j$(nproc) bcmath gd pdo_mysql calendar exif gettext shmop soap sockets intl pcntl xsl ldap ftp{{ if eq (env "DOCKER_BUILD_IMAP_TYPE") "php-ext" }} imap{{end}}
43+
{{- if eq (env "DOCKER_BUILD_IMAP_TYPE") "pecl" }}
44+
45+
RUN echo "---> Adding IMAP" && \
46+
pecl install imap${IMAP_VERSION} && \
47+
docker-php-ext-enable imap
48+
{{ end }}
49+
50+
RUN echo "---> Adding Redis" && \
51+
pecl install redis${REDIS_VERSION} && \
52+
docker-php-ext-enable redis
53+
54+
RUN echo "---> Adding xDebug" && \
55+
pecl install "xdebug${XDEBUG_VERSION}"
56+
57+
RUN echo "---> Adding Zip" && \
58+
pecl install zip && \
59+
docker-php-ext-enable zip
60+
61+
RUN echo "---> Adding AMQp" && \
62+
apt-get update && apt-get install -y -f librabbitmq-dev libssh-dev \
63+
&& docker-php-source extract \
64+
&& mkdir /usr/src/php/ext/amqp \
65+
&& curl -L https://github.com/php-amqp/php-amqp/archive/master.tar.gz | tar -xzC /usr/src/php/ext/amqp --strip-components=1 \
66+
&& docker-php-ext-install amqp \
67+
&& docker-php-ext-enable amqp
68+
69+
RUN echo "---> Configure Opcache" && \
70+
docker-php-ext-install opcache && \
71+
echo "opcache.enable=0" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini && \
72+
echo "opcache.enable_cli=0" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
73+
74+
RUN echo "---> Swoole" && \
75+
pecl install swoole -D 'enable-http2="yes"' && \
76+
docker-php-ext-enable swoole
77+
78+
RUN echo "---> Adding Tini" && \
79+
wget -O /tini https://github.com/krallin/tini/releases/download/v0.18.0/tini-static && \
80+
chmod +x /tini
81+
82+
RUN echo "---> Adding NewRelic" && \
83+
apt-get update && apt-get install -y -q --no-install-recommends --no-install-suggests gnupg2 \
84+
&& echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | sudo tee /etc/apt/sources.list.d/newrelic.list \
85+
&& wget -O- https://download.newrelic.com/548C16BF.gpg | sudo apt-key add - \
86+
&& sudo apt-get update && apt-get install -y -q --no-install-recommends --no-install-suggests newrelic-php5 \
87+
&& NR_INSTALL_USE_CP_NOT_LN=1 NR_INSTALL_SILENT=1 newrelic-install install \
88+
&& chown www-data:www-data /usr/local/etc/php/conf.d/newrelic.ini && chmod a+rw /usr/local/etc/php/conf.d/newrelic.ini \
89+
&& apt-get remove -y gnupg2 && rm -rf /var/lib/apt/lists/* \
90+
&& echo "newrelic.distributed_tracing_enabled = false" | sudo tee -a /usr/local/etc/php/conf.d/newrelic.ini \
91+
&& echo "newrelic.application_logging.enabled = false" | sudo tee -a /usr/local/etc/php/conf.d/newrelic.ini \
92+
&& echo "newrelic.enabled = false" | sudo tee -a /usr/local/etc/php/conf.d/newrelic.ini
93+
94+
RUN echo "---> Config sudoers" && \
95+
echo "www-data ALL = ( ALL ) NOPASSWD: ALL" >> /etc/sudoers
96+
97+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
98+
RUN echo "---> Fix permissions" \
99+
&& mkdir /var/www/.composer && chown -R www-data:www-data /var/www/.composer
100+
101+
COPY configs/logs.conf /etc/apache2/conf-enabled/logs.conf
102+
{{- if eq (env "DOCKER_BUILD_PHP_ERRORS_ENABLED") "1" }}
103+
COPY configs/php-errors.ini /usr/local/etc/php/conf.d/php-errors.ini
104+
{{ end }}
105+
COPY ./bin /usr/bin/
106+
107+
RUN chmod a+x \
108+
/usr/bin/swoole-run \
109+
/usr/bin/xdebug-set-mode \
110+
/usr/bin/post-startup-hook
111+
112+
USER www-data
113+
114+
WORKDIR "/var/www/html"
115+
116+
EXPOSE 8080 9001
117+
118+
CMD ["/tini", "--", "/usr/bin/swoole-run"]

0 commit comments

Comments
 (0)