Skip to content

Commit

Permalink
Initial base
Browse files Browse the repository at this point in the history
  • Loading branch information
xZero707 committed Jan 22, 2023
1 parent 81f70ae commit 191da9c
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
updates:

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
assignees:
- "xZero707"

# Maintain Docker image dependencies
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
assignees:
- "xZero707"
38 changes: 38 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build docker WordPress UNIT base image

on:
push:
branches: master

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: checkout code
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
config-inline: |
[worker.oci]
max-parallelism = 16
-
name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
uses: docker/[email protected]
with:
files: build/docker-bake.hcl
push: true
set: |
*.cache-from=type=gha,scope=wordpress-base
*.cache-to=type=gha,scope=wordpress-base,mode=max
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
91 changes: 91 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
ARG WP_IMG_BASE_VERSION=6.1.1
ARG PHP_VERSION=8.1
ARG UNIT_VERSION=1.29.0



################################################
# Tag official WordPress image resources #
################################################
FROM wordpress:${WP_IMG_BASE_VERSION}-php${PHP_VERSION}-fpm-alpine AS wordpress



################################################
# Build rootfs #
################################################
FROM scratch AS rootfs

# Install attr utility
COPY --from=nlss/attr ["/usr/local/bin/attr", "/usr/local/bin/"]

# Add crond service
COPY --from=nlss/base-alpine:3.17 ["/etc/services.d/cron/", "/etc/services.d/cron/"]

# WordPress specific php configuration
COPY --from=wordpress ["/usr/local/etc/php/conf.d/opcache-recommended.ini", "/usr/local/etc/php/conf.d/error-logging.ini", "/usr/local/etc/php/conf.d/"]

# Overlay
COPY ["./rootfs/", "/"]



################################################
# Final stage #
################################################
ARG PHP_VERSION
ARG UNIT_VERSION
FROM --platform=${TARGETPLATFORM} nlss/unit-php:${UNIT_VERSION}-PHP${PHP_VERSION}

RUN set -eux \
&& apk add --update --no-cache bash less mysql-client tzdata imagemagick ghostscript \
&& apk add --no-cache --virtual .build-deps \
${PHPIZE_DEPS:?} \
freetype-dev \
icu-dev \
imagemagick-dev \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
libzip-dev \
&& docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
--with-webp \
&& docker-php-ext-install -j "$(nproc)" \
bcmath \
exif \
gd \
intl \
mysqli \
zip \
&& pecl install imagick-3.6.0 \
&& docker-php-ext-enable imagick \
&& rm -r /tmp/pear \
&& extDir="$(php -i | grep "^extension_dir" | awk -F'=>' '{print $2}' | xargs)" \
&& runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive "${extDir}" \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)" \
&& apk add --no-network --virtual .wordpress-phpexts-rundeps ${runDeps} \
&& apk del --no-network .build-deps \
&& php --version || exit 1 \
&& mkdir -p /var/www/html/wp-content/{languages,themes,plugins,uploads} \
&& chown -R www-data:www-data /var/www/html/wp-content

COPY --from=rootfs ["/", "/"]

RUN echo "*/5 * * * * /usr/local/bin/wp cron event run --due-now" >> /etc/crontabs/www-data

ENV S6_KEEP_ENV=1
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2
ENV CRON_ENABLED=true

ARG WP_IMG_BASE_VERSION
ENV WP_IMG_BASE_VERSION=${WP_IMG_BASE_VERSION}

LABEL maintainer="Aleksandar Puharic <[email protected]>"
ENTRYPOINT ["/init"]
EXPOSE 80/TCP
24 changes: 24 additions & 0 deletions build/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
group "default" {
targets = ["1_0_0"]
}

target "build-dockerfile" {
dockerfile = "Dockerfile"
}

target "build-platforms" {
platforms = ["linux/amd64", "linux/armhf", "linux/aarch64"]
}

target "build-common" {
pull = true
}

target "1_0_0" {
inherits = ["build-dockerfile", "build-platforms", "build-common"]
tags = ["docker.io/nlss/wordpress-unit-base:latest", "docker.io/nlss/wordpress-unit-base:1.0.0"]
args = {
WP_IMG_BASE_VERSION = "6.1.1"
PHP_VERSION = "8.1"
}
}
4 changes: 4 additions & 0 deletions rootfs/etc/cont-init.d/99-webuser-permissions
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/with-contenv sh
set -e

/usr/local/bin/attr /var/www true www-data:www-data 0770 2771
44 changes: 44 additions & 0 deletions rootfs/etc/unit/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"listeners": {
"*:80": {
"pass": "routes"
}

},
"routes": [
{
"match": {
"uri": [
"*.php",
"*.php/*",
"/wp-admin/"
]
},
"action": {
"pass": "applications/wordpress/direct"
}
},
{
"action": {
"share": "/var/www/html$uri",
"fallback": {
"pass": "applications/wordpress/index"
}
}
}
],
"applications": {
"wordpress": {
"type": "php",
"targets": {
"direct": {
"root": "/var/www/html/"
},
"index": {
"root": "/var/www/html/",
"script": "index.php"
}
}
}
}
}
Empty file added rootfs/usr/src/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions rootfs/var/www/html/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

echo 'Hello World!';

0 comments on commit 191da9c

Please sign in to comment.