From 5c7fc6fc60e7a39820fbcc881fd091951afa3509 Mon Sep 17 00:00:00 2001 From: Tebiev Date: Sun, 4 Dec 2022 18:04:23 +0100 Subject: [PATCH] First commit --- .editorconfig | 35 +++++++ .gitattributes | 1 + .github/dependabot.yml | 19 ++++ .github/workflows/main.yml | 99 +++++++++++++++++++ .gitignore | 2 + LICENSE | 21 ++++ Makefile | 27 +++++ README.md | 1 + docker-compose.yml | 32 ++++++ docker/Dockerfile | 75 ++++++++++++++ docker/config/caddy/Caddyfile | 20 ++++ .../config/php-fpm.d/zzz-php-fpm_custom.conf | 9 ++ docker/etc/docker-entrypoint.sh | 29 ++++++ 13 files changed, 370 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/main.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100644 docker/Dockerfile create mode 100644 docker/config/caddy/Caddyfile create mode 100644 docker/config/php-fpm.d/zzz-php-fpm_custom.conf create mode 100644 docker/etc/docker-entrypoint.sh diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2dc9c99 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,35 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 + +[*.{neon,neon.dist}] +indent_style = tab +indent_size = 4 + +[*.{md,txt}] +indent_style = space +indent_size = 4 +trim_trailing_whitespace = false + +[{Makefile,Caddyfile,*.Caddyfile}] +indent_style = tab +tab_width = 4 + +[{Dockerfile,Dockerfile.template.erb,Dockerfile-alpine}] +indent_style = space +indent_size = 4 + +[*.env] +insert_final_newline = false +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..ba51855 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "docker" + directory: "/docker/" + schedule: + interval: "weekly" + + # Enable version updates for Actions + - package-ecosystem: "github-actions" + # Look for `.github/workflows` in the `root` directory + directory: "/" + # Check for updates once a week + schedule: + interval: "weekly" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..6b2fd22 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,99 @@ +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ master ] + pull_request: + branches: [ master ] + + schedule: + - cron: "0 0 * * 6" + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + + build-gearman: + name: Build, test and publish - ${{ matrix.release_image_version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + base_image_version: [ '5.2-fpm-alpine', 'fpm-alpine' ] + include: + - base_image_version: '5.2-fpm-alpine' + release_image_version: '5.2' + - base_image_version: 'fpm-alpine' + release_image_version: 'latest' + + steps: + - + name: Prepare env variables + run: | + echo "BUILD_DATE=$(TZ=':UTC' date +'%Y-%m-%d %H:%M:%S (%Z)')" >> ${GITHUB_ENV} + echo "BUILD_FINGERPRINT=${GITHUB_SHA::7}" >> ${GITHUB_ENV} + + - + name: Check out code + uses: actions/checkout@v3 + + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - + name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - + name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GH_TOKEN }} + + - + name: Build images and push to registry + uses: docker/build-push-action@v3 + with: + platforms: linux/amd64 + cache-from: type=gha, scope=${{ github.workflow }}-${{ matrix.version }} + cache-to: type=gha, scope=${{ github.workflow }}-${{ matrix.version }}, mode=max + context: . + file: ./docker/Dockerfile + build-args: | + BUILD_DATE=${{ env.BUILD_DATE }} + BUILD_FINGERPRINT=${{ env.BUILD_FINGERPRINT }} + BASE_IMAGE_VERSION=${{ matrix.base_image_version }} + tags: | + beeyev/phpmyadmin-lightweight:${{ matrix.release_image_version }} + ghcr.io/beeyev/phpmyadmin-docker-lightweight:${{ matrix.release_image_version }} + pull: true + push: true + + + Update-Docker-Hub-repo-description: + name: Update Docker Hub repo description + runs-on: ubuntu-latest + + steps: + - + name: Check out code + uses: actions/checkout@v3 + + - + name: Update Docker Hub repo description + uses: peter-evans/dockerhub-description@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + repository: beeyev/phpmyadmin-lightweight + #short-description: ${{ github.event.repository.description }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..166ac86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.vscode +/.idea diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..aec1ee6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Alexander Tebiev / tebiev@mail.com / https://github.com/beeyev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e7a61bf --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +THIS_FILE := $(abspath $(lastword $(MAKEFILE_LIST))) +CURRENT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) + +up: + docker-compose up --build --no-deps --detach --remove-orphans + +down: + docker-compose down --remove-orphans + +stop: + docker-compose stop + +update: + docker-compose pull + make up + +restart: down up + $(info Restart completed) + +state: + docker ps --format=table + +logs: ## Show docker logs + docker-compose logs -f --tail=100 $(ARGS) + +phpmyadmin: + docker-compose exec phpmyadmin bash diff --git a/README.md b/README.md new file mode 100644 index 0000000..05d4b0a --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# phpMyAdmin lightweight diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..17f8523 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: "3" + +services: + phpmyadmin: + image: beeyev/phpmyadmin-lightweight:latest + container_name: 'phpmyadmin' + restart: unless-stopped + tty: true + environment: + - 'TZ=CET' + - 'PMA_HOST=mysql' + - 'PMA_USER=root' + - 'PMA_PASSWORD=TestRootPassword' + ports: + - '8080:80' + networks: + - network1 + + mysql: + image: bitnami/mysql:8.0 + container_name: 'mysql' + restart: unless-stopped + tty: true + environment: + - 'TZ=CET' + - 'MYSQL_ROOT_PASSWORD=TestRootPassword' + networks: + - network1 + +networks: + network1: + driver: bridge diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..3c5d2ec --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,75 @@ +# docker build -t phpmyadmin-fpm-alpine-caddy --build-arg BUILDKIT_INLINE_CACHE=1 -f ./docker/Dockerfile . && docker run --rm -it -p 8080:80 phpmyadmin-fpm-alpine-caddy +FROM alpine:3 as phpmyadmin-themes +WORKDIR /src/ +RUN set -eux \ + && apk add --quiet --no-cache \ + curl \ + unzip \ + && curl -fsSL https://github.com/phpmyadmin/themes/archive/refs/heads/master.zip --output /src/phpmyadmin-themes.zip \ + && unzip -uoq /src/phpmyadmin-themes.zip -d /src/ + +FROM phpmyadmin/phpmyadmin:${BASE_IMAGE_VERSION} + +ENV TERM="xterm-256color" \ +LANGUAGE="en_US.UTF-8" \ +LANG="en_US.UTF-8" \ +LC_TIME="en_DK.UTF-8" \ +TIME_STYLE="long-iso" + +RUN set -eux \ + && apk add --quiet --no-cache \ + iputils \ + # `fcgi` - Healthcheck | https://github.com/renatomefi/php-fpm-healthcheck + fcgi \ + tini + +# Caddy | https://caddyserver.com/ +COPY --from=caddy:2-alpine /usr/bin/caddy /usr/local/bin/caddy +COPY ./docker/config/caddy/Caddyfile /etc/caddy/Caddyfile +RUN set -eux \ +# && setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy \ + && caddy fmt --overwrite /etc/caddy/Caddyfile \ + && caddy version + +# Healthcheck | https://github.com/renatomefi/php-fpm-healthcheck +RUN set -eux \ + && curl -fsSL https://raw.githubusercontent.com/renatomefi/php-fpm-healthcheck/master/php-fpm-healthcheck --output /usr/local/bin/php-fpm-healthcheck \ + && chmod +x /usr/local/bin/php-fpm-healthcheck \ + && echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf +HEALTHCHECK --interval=1m --timeout=1s --start-period=10s CMD (curl --fail http://localhost/LICENSE && php-fpm-healthcheck) || exit 1 + +COPY ./docker/config/php-fpm.d/zzz-php-fpm_custom.conf /usr/local/etc/php-fpm.d/zzz-php-fpm_custom.conf + +# Install themes +COPY --from=phpmyadmin-themes /src/themes-master/blueberry/ /var/www/html/themes/blueberry/ +COPY --from=phpmyadmin-themes /src/themes-master/boodark/ /var/www/html/themes/boodark/ + +RUN set -eux \ + && rm -R themes/metro/ themes/bootstrap/ themes/original/ + +LABEL org.opencontainers.image.title="phpMyAdmin Docker image" \ + org.opencontainers.image.description="Run phpMyAdmin with Alpine, PHP FPM and Caddy" \ + org.opencontainers.image.authors="https://github.com/beeyev/phpmyadmin-docker-lightweight" \ + org.opencontainers.image.vendor="phpMyAdmin" \ + org.opencontainers.image.documentation="https://github.com/beeyev/phpmyadmin-docker-lightweight" \ + org.opencontainers.image.url="https://github.com/beeyev/phpmyadmin-docker-lightweight" \ + org.opencontainers.image.source="https://github.com/beeyev/phpmyadmin-docker-lightweight" + +ARG TZ='UTC' +ENV TZ=$TZ + +#These params meant to be set by CI +ARG BUILD_DATE +ENV BUILD_DATE=$BUILD_DATE +RUN echo $BUILD_DATE +ARG BUILD_FINGERPRINT +ENV BUILD_FINGERPRINT=$BUILD_FINGERPRINT +RUN echo $BUILD_FINGERPRINT + +RUN set -eux \ + && mv /docker-entrypoint.sh /phpmyadmin-docker-entrypoint.sh + +COPY --chmod=0755 ./docker/etc/docker-entrypoint.sh /docker-entrypoint.sh +ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"] +EXPOSE 80 + diff --git a/docker/config/caddy/Caddyfile b/docker/config/caddy/Caddyfile new file mode 100644 index 0000000..afa9b5b --- /dev/null +++ b/docker/config/caddy/Caddyfile @@ -0,0 +1,20 @@ +(proxyheaders) { + trusted_proxies 0.0.0.0/0 +} + +{ + auto_https off + admin off + log { + level WARN + } +} + +:80 { + root * /var/www/html/ + php_fastcgi 127.0.0.1:9000 { + trusted_proxies 0.0.0.0/0 + } + file_server browse + encode zstd gzip +} diff --git a/docker/config/php-fpm.d/zzz-php-fpm_custom.conf b/docker/config/php-fpm.d/zzz-php-fpm_custom.conf new file mode 100644 index 0000000..b47796c --- /dev/null +++ b/docker/config/php-fpm.d/zzz-php-fpm_custom.conf @@ -0,0 +1,9 @@ +[global] +; global config goes here + +[www] +; www config goes here +; Uncomment the line below if you want to store logs in a file instead of sending them into `stderr` +; php_admin_value[error_log] = /var/log/php/php-fpm-errors.log + +access.log = /dev/null diff --git a/docker/etc/docker-entrypoint.sh b/docker/etc/docker-entrypoint.sh new file mode 100644 index 0000000..02fc192 --- /dev/null +++ b/docker/etc/docker-entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +#String Colors +NC='\033[0;m' # Default Color +GRN='\033[32;1m' +RED='\033[31;1m' +BLK='\033[30;1m' + +# Set the number of cpu cores +export NUM_CPUS=`nproc` + +# Run custom script before the main docker process gets started +for f in /docker-entrypoint.init.d/*; do + case "$f" in + *.sh) # this should match the set of files we check for below + echo "⚙ Executing entrypoint.init file: ${f}" + . $f + break + ;; + esac +done + +printf "\n${GRN}--->${NC} 🚀️️ Welcome to ${GRN}beeyev phpMyAdmin lightweight${NC} container..." +printf "\n${GRN}--->${NC} Docker image build date: ${GRN}${BUILD_DATE}${NC}, fingerprint: ${GRN}${BUILD_FINGERPRINT}${NC}" +printf "\n${GRN}--->${NC} Subscribe to project updates: ${GRN}https://github.com/beeyev/phpmyadmin-docker-lightweight${NC}\n\n" + +caddy start --adapter caddyfile --config /etc/caddy/Caddyfile + +exec /phpmyadmin-docker-entrypoint.sh php-fpm