Skip to content

Commit bb7a06b

Browse files
committed
feat: one branch to rule them all
1 parent fca35b9 commit bb7a06b

File tree

10 files changed

+314
-156
lines changed

10 files changed

+314
-156
lines changed
Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
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_erros_enabled:
31+
type: boolean
32+
required: true
33+
variations:
34+
type: string
35+
required: true
636

737
jobs:
8-
push_to_registry:
9-
name: Push Docker image to Docker Hub
38+
build:
39+
name: Build Docker image
1040
runs-on: ubuntu-latest
1141

1242
permissions:
@@ -17,6 +47,29 @@ jobs:
1747
- name: Check out the repo
1848
uses: actions/checkout@v4
1949

50+
- name: install go-replace
51+
env:
52+
GOREPLACE_VERSION: 22.9.0
53+
run: |
54+
wget -O /usr/local/bin/go-replace \
55+
https://github.com/webdevops/go-replace/releases/download/$GOREPLACE_VERSION/go-replace.linux.amd64
56+
chmod +x /usr/local/bin/go-replace
57+
58+
- name: build Dockerfile
59+
env:
60+
DOCKER_BUILD_VERSION: ${{ inputs.version }}
61+
DOCKER_BUILD_BASE: ${{ inputs.base }}
62+
DOCKER_BUILD_XDEBUG_VERSION: ${{ inputs.xdebug_version }}
63+
DOCKER_BUILD_REDIS_VERSION: ${{ inputs.redis_version }}
64+
DOCKER_BUILD_IMAP_TYPE: ${{ inputs.imap_type }}
65+
DOCKER_BUILD_IMAP_VERSION: ${{ inputs.imap_version }}
66+
DOCKER_BUILD_PHP_ERRORS_ENABLED: ${{ inputs.php_erros_enabled && '1' || '0' }}
67+
run: |
68+
go-replace --mode=template ./${{ inputs.template }} -o ./Dockerfile
69+
70+
- name: dump Dockerfile
71+
run: cat Dockerfile
72+
2073
- name: Log in to Docker Hub
2174
uses: docker/login-action@v3
2275
with:
@@ -29,40 +82,34 @@ jobs:
2982
with:
3083
images: lojassimonetti/php-apache-oci8-composer
3184
tags: |
32-
type=ref,event=branch,enable=true
33-
type=ref,event=tag,enable=true
85+
type=raw,value=${{ inputs.name }},enable=true
3486
3587
- name: Should push?
36-
id: shoudPush
88+
id: shouldPush
3789
run: |
3890
if [[ ${{ github.event.ref }} = "refs/heads/master" ]]; then
3991
echo "match=true" >> $GITHUB_OUTPUT
40-
elif [[ ${{ github.event.ref }} =~ ^refs/heads/php[0-9]dot[0-9]$ ]]; then
41-
echo "match=true" >> $GITHUB_OUTPUT
42-
elif [[ ${{ github.event.ref }} =~ ^refs/heads/php[0-9]dot[0-9]-mongodb$ ]]; then
43-
echo "match=true" >> $GITHUB_OUTPUT
4492
fi
4593
4694
- name: Build and push Docker image
4795
uses: docker/build-push-action@v5
4896
with:
4997
context: .
50-
push: ${{ steps.shoudPush.outputs.match == 'true' }}
98+
push: ${{ steps.shouldPush.outputs.match == 'true' }}
5199
tags: ${{ steps.meta.outputs.tags }}
52100
labels: ${{ steps.meta.outputs.labels }}
53101

54-
push_children:
55-
name: Push children Docker image to Docker Hub
102+
build_variations:
103+
name: Build Docker image variation
56104
runs-on: ubuntu-latest
57105

58106
needs:
59-
- push_to_registry
107+
- build
60108

61109
strategy:
62110
fail-fast: false
63111
matrix:
64-
variation:
65-
- pgsql
112+
variation: ${{ fromJson(inputs.variations) }}
66113

67114
permissions:
68115
packages: write
@@ -84,23 +131,21 @@ jobs:
84131
with:
85132
images: lojassimonetti/php-apache-oci8-composer
86133
tags: |
87-
type=ref,event=branch,enable=true,suffix=-${{ matrix.variation }}
88-
type=ref,event=tag,enable=true,suffix=-${{ matrix.variation }}
134+
type=raw,value=${{ inputs.name }}-${{ matrix.variation }},enable=true
89135
90136
- name: Should push?
91-
id: shoudPush
137+
id: shouldPush
92138
run: |
93-
if [[ ${{ github.event.ref }} =~ ^refs/heads/php[0-9]dot[0-9]$ ]]; then
94-
echo "match=true" >> $GITHUB_OUTPUT
95-
elif [[ ${{ github.event.ref }} = "refs/heads/master" ]]; then
139+
if [[ ${{ github.event.ref }} = "refs/heads/master" ]]; then
96140
echo "match=true" >> $GITHUB_OUTPUT
97141
fi
98142
99143
- name: Build and push Docker image
100144
uses: docker/build-push-action@v5
101145
with:
102146
context: .
147+
build-args: IMAGE_BASE=lojassimonetti/php-apache-oci8-composer:${{ inputs.name }}
103148
file: ./Dockerfile.${{ matrix.variation }}
104-
push: ${{ steps.shoudPush.outputs.match == 'true' }}
149+
push: ${{ steps.shouldPush.outputs.match == 'true' }}
105150
tags: ${{ steps.meta.outputs.tags }}
106151
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_erros_enabled: ${{ matrix.config.php_erros_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: 7 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,10 @@
1-
# Container Base
2-
FROM php:7.4-apache
1+
ARG IMAGE_BASE
2+
FROM ${IMAGE_BASE}
33

4-
ENV http_proxy=${HTTP_PROXY}
5-
ENV https_proxy=${HTTP_PROXY}
6-
ENV NR_ENABLED=false
7-
ENV NR_DISTRIBUTED_TRACING_ENABLED=false
8-
ENV NR_APPLICATION_LOGGING_ENABLED=false
9-
ENV NR_IGNORE_DEFAULT_EXCEPTION=false
10-
ENV NR_IGNORED_EXECEPTIONS=""
11-
ENV NR_APP_NAME=""
12-
ENV NR_LICENSE_KEY=""
13-
ENV NR_VERSION=""
14-
ENV PHP_BUILD_DATE="20190902"
15-
ENV PHP_OPCACHE_ENABLED=false
16-
ENV SESSION_HANDLER=false
17-
ENV SESSION_HANDLER_NAME=""
18-
ENV SESSION_HANDLER_PATH=""
19-
ENV XDEBUG_AUTOSTART=false
20-
ENV XDEBUG_CONNECT_BACK=true
21-
ENV XDEBUG_ENABLED=false
22-
ENV XDEBUG_IDEKEY="docker"
23-
ENV XDEBUG_VERSION="-3.1.6"
24-
ENV XDEBUG_REMOTE_PORT=9000
25-
ENV PHP_EXTENSION_WDDX=1
26-
ENV PHP_OPENSSL=1
4+
USER root
275

28-
ENV CONTAINER_STARTED_LOCK=/var/lock/container.starting
6+
RUN echo "---> PGSQL" && \
7+
apt-get update && apt-get install -y --no-install-recommends libpq-dev && \
8+
docker-php-ext-install pdo_pgsql
299

30-
RUN apt-get update && apt-get install -y --no-install-recommends wget vim supervisor libfreetype6-dev libjpeg-dev libjpeg62-turbo-dev \
31-
libmcrypt-dev libpng-dev libssl-dev libaio1 git libcurl4-openssl-dev libxslt-dev \
32-
libldap2-dev libicu-dev libc-client-dev libkrb5-dev libsqlite3-dev libedit-dev libpq-dev \
33-
sudo zlib1g zlib1g-dev libzip4 libzip-dev zip unzip librabbitmq-dev && \
34-
rm -rf /var/lib/apt/lists/*
35-
36-
RUN a2enmod rewrite unique_id headers
37-
38-
RUN docker-php-ext-configure gd --with-jpeg \
39-
&& docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ \
40-
&& docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
41-
&& docker-php-ext-install -j$(nproc) bcmath gd pdo_mysql pdo_pgsql calendar exif gettext shmop soap sockets intl pcntl xsl ldap imap
42-
43-
RUN echo "---> Adding Redis" && \
44-
pecl install redis && \
45-
docker-php-ext-enable redis
46-
47-
RUN echo "---> Adding xDebug" && \
48-
pecl install "xdebug${XDEBUG_VERSION}"
49-
50-
RUN echo "---> Adding Zip" && \
51-
pecl install zip && \
52-
docker-php-ext-enable zip
53-
54-
RUN echo "---> Adding AMQP" && \
55-
pecl install amqp && \
56-
docker-php-ext-enable amqp
57-
58-
RUN echo "---> Configure Opcache" && \
59-
docker-php-ext-install opcache && \
60-
echo "opcache.enable=0" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini && \
61-
echo "opcache.enable_cli=0" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
62-
63-
RUN apt-get update && apt-get install -y -q --no-install-recommends --no-install-suggests gnupg2 \
64-
&& echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | sudo tee /etc/apt/sources.list.d/newrelic.list \
65-
&& wget -O- https://download.newrelic.com/548C16BF.gpg | sudo apt-key add - \
66-
&& sudo apt-get update && apt-get install -y -q --no-install-recommends --no-install-suggests newrelic-php5 \
67-
&& NR_INSTALL_USE_CP_NOT_LN=1 NR_INSTALL_SILENT=1 newrelic-install install \
68-
&& chown www-data:www-data /usr/local/etc/php/conf.d/newrelic.ini && chmod a+rw /usr/local/etc/php/conf.d/newrelic.ini \
69-
&& apt-get remove -y gnupg2 && rm -rf /var/lib/apt/lists/* \
70-
&& echo "newrelic.distributed_tracing_enabled = false" | sudo tee -a /usr/local/etc/php/conf.d/newrelic.ini \
71-
&& echo "newrelic.application_logging.enabled = false" | sudo tee -a /usr/local/etc/php/conf.d/newrelic.ini \
72-
&& echo "newrelic.enabled = false" | sudo tee -a /usr/local/etc/php/conf.d/newrelic.ini
73-
74-
RUN echo "---> Adding Tini" && \
75-
wget -O /tini https://github.com/krallin/tini/releases/download/v0.18.0/tini-static && \
76-
chmod +x /tini
77-
78-
RUN echo "---> Config sudoers" && \
79-
echo "www-data ALL = ( ALL ) NOPASSWD: ALL" >> /etc/sudoers
80-
81-
RUN echo "---> Fix Logs permissions" && \
82-
chown -R www-data:www-data /var/log/apache2
83-
84-
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer && \
85-
mkdir /var/www/.composer && chown -R www-data:www-data /var/www/.composer
86-
87-
COPY configs/ports.conf /etc/apache2/ports.conf
88-
COPY configs/headers.conf /etc/apache2/conf-enabled/headers.conf
89-
COPY configs/logs.conf /etc/apache2/conf-enabled/logs.conf
90-
COPY apache-run.sh /usr/bin/apache-run
91-
COPY ./bin /usr/bin/
92-
93-
RUN chmod a+x \
94-
/usr/bin/apache-run \
95-
/usr/bin/post-startup-hook
96-
97-
USER www-data
98-
99-
WORKDIR "/var/www/html"
100-
101-
EXPOSE 8080 9001
102-
103-
CMD ["/tini", "--", "/usr/bin/apache-run"]
10+
USER www-data:www-data

0 commit comments

Comments
 (0)