Merge pull request #3 from beeyev/small-refactor

This commit is contained in:
Alexander
2023-08-28 22:13:27 +02:00
committed by GitHub
11 changed files with 329 additions and 128 deletions
@@ -0,0 +1,27 @@
# Alexander Tebiev - https://github.com/beeyev
name: Prepare Docker env variables
description: 'Prepare env variables'
outputs:
DATE_YEAR_WEEKNUM:
description: "DATE_YEAR_WEEKNUM"
value: ${{ steps.prepare-env-variables.outputs.DATE_YEAR_WEEKNUM }}
BUILD_DATE:
description: "BUILD_DATE"
value: ${{ steps.prepare-env-variables.outputs.BUILD_DATE }}
BUILD_FINGERPRINT:
description: "BUILD_FINGERPRINT"
value: ${{ steps.prepare-env-variables.outputs.BUILD_FINGERPRINT }}
CURRENT_BRANCH_NAME:
description: "CURRENT_BRANCH_NAME"
value: ${{ steps.prepare-env-variables.outputs.CURRENT_BRANCH_NAME }}
runs:
using: "composite"
steps:
- id: prepare-env-variables
shell: bash
run: |
echo "DATE_YEAR_WEEKNUM=$(TZ=':UTC' date +'%Y-%U')" >> ${GITHUB_OUTPUT}
echo "BUILD_DATE=$(date -u +'%Y-%m-%d %H:%M:%S (%Z)')" >> ${GITHUB_OUTPUT}
echo "NOW_RFC_3339=$(date -u --rfc-3339=seconds | sed 's/ /T/')" >> ${GITHUB_OUTPUT}
echo "BUILD_FINGERPRINT=$(git rev-parse --short HEAD)" >> ${GITHUB_OUTPUT}
echo "CURRENT_BRANCH_NAME=$(git branch --show-current)" >> ${GITHUB_OUTPUT}
@@ -0,0 +1,60 @@
# Alexander Tebiev - https://github.com/beeyev
on:
workflow_call:
inputs:
DOCKER_REGISTRY_IMAGE:
required: true
type: string
DOCKERFILE_PATH:
required: true
type: string
BASE_IMAGE_VERSION:
required: true
type: string
jobs:
build-docker-image:
name: Build Docker Image
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- name: Checkout branch - ${{ github.head_ref || github.ref_name }}
uses: actions/checkout@v3
- name: Prepare Build Env Variables
uses: ./.github/actions/prepare-env-variables/
id: prepare-build-env-variables
- 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 image and push to registry - ${{ inputs.DOCKER_REGISTRY_IMAGE }}
uses: docker/build-push-action@v4
with:
platforms: linux/amd64
context: .
file: ${{ inputs.DOCKERFILE_PATH }}
cache-from: type=registry,ref=${{ inputs.DOCKER_REGISTRY_IMAGE }}
cache-to: type=inline
build-args: |
BASE_IMAGE_VERSION=${{ inputs.BASE_IMAGE_VERSION }}
BUILD_DATE=${{ steps.prepare-build-env-variables.outputs.BUILD_DATE }}
BUILD_FINGERPRINT=${{ steps.prepare-build-env-variables.outputs.BUILD_FINGERPRINT }}
BRANCH_NAME=${{ steps.prepare-build-env-variables.outputs.CURRENT_BRANCH_NAME }}
tags: ${{ inputs.DOCKER_REGISTRY_IMAGE }}
push: true
-90
View File
@@ -1,90 +0,0 @@
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 ]
schedule:
- cron: "23 1 2 * *"
# 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@v4
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 }}
IMAGE_TAG=${{ matrix.release_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 }}
@@ -0,0 +1,58 @@
# Alexander Tebiev - https://github.com/beeyev
name: Delete old workflow runs
on:
workflow_dispatch:
inputs:
days:
description: 'Number of days.'
required: true
default: 30
minimum_runs:
description: 'The minimum runs to keep for each workflow.'
required: true
default: 6
delete_workflow_pattern:
description: 'The name or filename of the workflow. if not set then it will target all workflows.'
required: false
delete_workflow_by_state_pattern:
description: 'Remove workflow by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually'
required: true
default: "All"
type: choice
options:
- "All"
- active
- deleted
- disabled_inactivity
- disabled_manually
delete_run_by_conclusion_pattern:
description: 'Remove workflow by conclusion: action_required, cancelled, failure, skipped, success'
required: true
default: "All"
type: choice
options:
- "All"
- action_required
- cancelled
- failure
- skipped
- success
dry_run:
description: 'Only log actions, do not perform any delete operations.'
required: false
jobs:
del_runs:
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: ${{ github.event.inputs.days }}
keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }}
delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }}
delete_run_by_conclusion_pattern: ${{ github.event.inputs.delete_run_by_conclusion_pattern }}
dry_run: ${{ github.event.inputs.dry_run }}
@@ -0,0 +1,50 @@
# Alexander Tebiev - https://github.com/beeyev
name: Build Production Docker Images
on:
push:
branches: [ master ]
schedule:
- cron: "23 1 2 * *"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
docker-image-deploy:
strategy:
fail-fast: false
matrix:
SOURCE_IMAGE_VERSION: [ '5.2-fpm-alpine' ]
TARGET_IMAGE_VERSION: [ '5.2' ]
uses: ./.github/workflows/callable-build-docker-image.yml
name: Build Production Docker Images / ${{ matrix.SOURCE_IMAGE_VERSION }}-${{ matrix.TARGET_IMAGE_VERSION }}
with:
BASE_IMAGE_VERSION: ${{ matrix.SOURCE_IMAGE_VERSION }}
DOCKER_REGISTRY_IMAGE: |
beeyev/phpmyadmin-lightweight:latest
beeyev/phpmyadmin-lightweight:${{ matrix.TARGET_IMAGE_VERSION }}
ghcr.io/beeyev/phpmyadmin-docker-lightweight:latest
ghcr.io/beeyev/phpmyadmin-docker-lightweight:${{ matrix.TARGET_IMAGE_VERSION }}
DOCKERFILE_PATH: ./docker/Dockerfile
secrets: inherit
update-docker-hub-repo-description:
name: Update Docker Hub repo description
runs-on: ubuntu-latest
needs: docker-image-deploy
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 }}
@@ -0,0 +1,56 @@
# Alexander Tebiev - https://github.com/beeyev
name: Build Test Docker Images
on:
pull_request:
types: [labeled]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
initialization:
name: Initialization
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: contains(github.event.label.name, 'make-test-build')
# if: |
# (github.event.action == 'labeled' && github.event.label.name == 'make-test-build') ||
# (github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'make-test-build'))
steps:
- name: Sticky Pull Request Comment
uses: marocchino/sticky-pull-request-comment@v2
with:
message: |
> [Building test docker images...](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
docker-image-deploy:
strategy:
fail-fast: false
matrix:
SOURCE_IMAGE_VERSION: [ '5.2-fpm-alpine' ]
TARGET_IMAGE_VERSION: [ 'test' ]
uses: ./.github/workflows/callable-build-docker-image.yml
name: Build Test Docker Images / ${{ matrix.baseDist }}-test
if: contains(github.event.label.name, 'make-test-build')
with:
BASE_IMAGE_VERSION: ${{ matrix.SOURCE_IMAGE_VERSION }}
DOCKER_REGISTRY_IMAGE: ghcr.io/beeyev/phpmyadmin-docker-lightweight:${{ matrix.TARGET_IMAGE_VERSION }}
DOCKERFILE_PATH: ./docker/Dockerfile
secrets: inherit
finalize:
name: Finalize
runs-on: ubuntu-latest
permissions:
pull-requests: write
needs: docker-image-deploy
steps:
- name: Remove `test-build` label
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: make-test-build
+41 -14
View File
@@ -1,27 +1,54 @@
THIS_FILE := $(abspath $(lastword $(MAKEFILE_LIST)))
CURRENT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# Alexander Tebiev - https://github.com/beeyev
up:
docker-compose up --build --no-deps --detach --remove-orphans
.EXPORT_ALL_VARIABLES:
.PHONY: *
.DEFAULT_GOAL := help
down:
docker-compose down --remove-orphans
ifeq (,$(shell command docker compose 2> /dev/null))
DOCKER_COMPOSE_COMMAND = docker-compose
else
DOCKER_COMPOSE_COMMAND = docker compose
endif
stop:
docker-compose stop
help: ## Show this help
@echo "Make Application Docker Images and Containers using Docker-Compose files in 'docker' Dir."
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m (default: help)\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-12s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
update:
docker-compose pull
up: ## Docker compose up
$(DOCKER_COMPOSE_COMMAND) up --build --no-deps --detach --remove-orphans
start:
make up
restart: down up
down: ## Docker compose down
$(DOCKER_COMPOSE_COMMAND) down --remove-orphans
stop: ## Docker compose stop
$(DOCKER_COMPOSE_COMMAND) stop
restart: ## Restart containers
make down
make up
$(info Restart completed)
state:
update: ## Update containers
$(DOCKER_COMPOSE_COMMAND) pull
make up
destroy: ## Destroy containers/volumes (keep sources app folders)
make stop
$(DOCKER_COMPOSE_COMMAND) down --rmi all --remove-orphans
rebuild: ## Rebuild docker container (destroy & upgrade)
make destroy
make up
state: ## Show current state
docker ps --format=table
logs: ## Show docker logs
docker-compose logs -f --tail=100 $(ARGS)
$(DOCKER_COMPOSE_COMMAND) logs -f --tail=100 $(ARGS)
phpmyadmin:
docker-compose exec phpmyadmin bash
$(DOCKER_COMPOSE_COMMAND) exec phpmyadmin bash
@printf "\n http://localhost:8080/ \n"
+4 -2
View File
@@ -1,8 +1,8 @@
version: "3"
# Alexander Tebiev - https://github.com/beeyev
services:
phpmyadmin:
image: beeyev/phpmyadmin-lightweight:latest
image: ghcr.io/beeyev/phpmyadmin-docker-lightweight:test
container_name: 'phpmyadmin'
restart: unless-stopped
tty: true
@@ -13,6 +13,8 @@ services:
- 'PMA_PASSWORD=TestRootPassword'
ports:
- '8080:80'
depends_on:
- mysql
networks:
- network1
+22 -19
View File
@@ -1,4 +1,6 @@
# 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
# syntax=docker/dockerfile:1
# Author: Alexander Tebiev - https://github.com/beeyev/phpmyadmin-docker-lightweight
# docker buildx build --build-arg=BASE_IMAGE_VERSION=5.2-fpm-alpine --cache-to=type=inline --pull --tag phpmyadmin-fpm-alpine-caddy --file ./docker/Dockerfile ./ && docker run -p 9090:80 -it --rm phpmyadmin-fpm-alpine-caddy
ARG BASE_IMAGE_VERSION
FROM phpmyadmin:${BASE_IMAGE_VERSION} as phpmyadmin
@@ -9,7 +11,10 @@ RUN set -eux \
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/
&& unzip -uoq /src/phpmyadmin-themes.zip -d /src/ \
&& mkdir /src/selected-themes/ \
&& cp -r /src/themes-master/blueberry/ /src/themes-master/boodark/ -t /src/selected-themes/
FROM phpmyadmin
@@ -19,8 +24,8 @@ LANG="en_US.UTF-8" \
LC_TIME="en_DK.UTF-8" \
TIME_STYLE="long-iso"
RUN set -eux \
&& apk add --quiet --no-cache \
RUN --mount=type=cache,sharing=locked,target=/var/cache/apk/ set -eux \
&& apk add --quiet --update --no-cache \
iputils \
# `fcgi` - Healthcheck | https://github.com/renatomefi/php-fpm-healthcheck
fcgi \
@@ -29,27 +34,26 @@ RUN set -eux \
# Caddy | https://caddyserver.com/
COPY --from=caddy:2-alpine /usr/bin/caddy /usr/local/bin/caddy
COPY ./docker/config/caddy/Caddyfile /etc/caddy/Caddyfile
ENV ACME_AGREE=true
RUN set -eux \
# && setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy \
&& caddy fmt --overwrite /etc/caddy/Caddyfile \
&& caddy validate --config /etc/caddy/Caddyfile \
&& caddy version
# Healthcheck | https://github.com/renatomefi/php-fpm-healthcheck
## Healthcheck | https://github.com/renatomefi/php-fpm-healthcheck
ADD --chmod=0705 --link https://raw.githubusercontent.com/renatomefi/php-fpm-healthcheck/master/php-fpm-healthcheck /usr/local/bin/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
# Cheching Caddy & php-fpm
HEALTHCHECK --interval=1m --timeout=1s --start-period=10s CMD (curl --fail http://localhost:9999/health && 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/
COPY --from=phpmyadmin-themes /src/selected-themes/ /var/www/html/themes/
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.authors="https://github.com/beeyev/" \
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" \
@@ -59,15 +63,15 @@ ARG TZ='UTC'
ENV TZ=$TZ
#These params meant to be set by CI
ARG IMAGE_TAG
ENV IMAGE_TAG=$IMAGE_TAG
RUN echo $IMAGE_TAG
ARG BUILD_DATE
ARG BUILD_DATE=undefined
ENV BUILD_DATE=$BUILD_DATE
RUN echo $BUILD_DATE
ARG BUILD_FINGERPRINT
ARG BUILD_FINGERPRINT=undefined
ENV BUILD_FINGERPRINT=$BUILD_FINGERPRINT
RUN echo $BUILD_FINGERPRINT
ARG BRANCH_NAME=undefined
ENV BRANCH_NAME=$BRANCH_NAME
RUN echo $BRANCH_NAME
RUN set -eux \
&& mv /docker-entrypoint.sh /phpmyadmin-docker-entrypoint.sh
@@ -75,4 +79,3 @@ RUN set -eux \
COPY --chmod=0755 ./docker/etc/docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
EXPOSE 80
+1 -1
View File
@@ -15,6 +15,6 @@
php_fastcgi 127.0.0.1:9000 {
trusted_proxies 0.0.0.0/0
}
file_server browse
file_server
encode zstd gzip
}
+10 -2
View File
@@ -1,4 +1,5 @@
#!/bin/sh
# Alexander Tebiev - https://github.com/beeyev
#String Colors
NC='\033[0;m' # Default Color
@@ -20,9 +21,16 @@ for f in /docker-entrypoint.init.d/*; do
esac
done
printf "\n${GRN}--->${NC} 🚀️ Welcome to ${GRN}beeyev phpMyAdmin v.${VERSION} lightweight${NC} container..."
printf "\n${GRN}--->${NC} 🚀 Starting ${GRN}beeyev phpMyAdmin v.${VERSION} 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"
printf "\n${GRN}--->${NC} Subscribe to the project updates: ${GRN}https://github.com/beeyev/phpmyadmin-docker-lightweight${NC}"
printf "\n\nCaddy version:\n"
caddy version
printf "\nPHP-FPM version:\n"
php-fpm --version
printf "\n"
caddy start --adapter caddyfile --config /etc/caddy/Caddyfile