From 50cdecc7c204665efe7fa2051018c1ee3f0b033f Mon Sep 17 00:00:00 2001 From: lotyp Date: Wed, 17 May 2023 14:04:47 +0300 Subject: [PATCH] feat: reusable workflows --- .ansible-lint | 12 +++ .github/labeler.yml | 14 +++ .github/workflows/apply-labels.yml | 23 +++++ .github/workflows/auto-merge-release.yaml | 26 +++++ .github/workflows/build-latest.yml | 43 ++++++++ .github/workflows/build-release.yml | 50 ++++++++++ .github/workflows/ci.yml | 114 ---------------------- .github/workflows/create-release.yml | 23 +++++ .github/workflows/release-please.yml | 39 -------- .github/workflows/shellcheck.yml | 23 ++--- .github/workflows/upload-assets.yml | 32 ++++++ .pre-commit-config.yaml | 34 ++++++- .yamllint | 77 +++++++-------- LICENSE => LICENSE.md | 0 Makefile | 86 ++++++++++------ README.md | 63 +++++++----- renovate.json | 8 ++ src/Dockerfiles/dev/Dockerfile.j2 | 30 +++--- src/group_vars/dev.yml | 6 -- src/inventory.yml | 22 +++++ src/{generate.yml => playbook.yml} | 0 21 files changed, 438 insertions(+), 287 deletions(-) create mode 100644 .ansible-lint create mode 100644 .github/labeler.yml create mode 100644 .github/workflows/apply-labels.yml create mode 100644 .github/workflows/auto-merge-release.yaml create mode 100644 .github/workflows/build-latest.yml create mode 100644 .github/workflows/build-release.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/create-release.yml delete mode 100644 .github/workflows/release-please.yml create mode 100644 .github/workflows/upload-assets.yml rename LICENSE => LICENSE.md (100%) create mode 100644 renovate.json rename src/{generate.yml => playbook.yml} (100%) diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..e2f880a --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,12 @@ +--- + +# https://ansible-lint.readthedocs.io/en/latest/configuring/ + +skip_list: + - experimental + +exclude_paths: + - ./contrib + - ./.venv + +... diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000..af814de --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,14 @@ +--- + +# this file is for the labeler workflow job +# Documentation https://github.com/marketplace/actions/labeler + +"type: documentation": + - assets/**/* + - .github/* + - ./*.md + +"type: maintenance": + - .github/workflows/* + +... diff --git a/.github/workflows/apply-labels.yml b/.github/workflows/apply-labels.yml new file mode 100644 index 0000000..c9b1196 --- /dev/null +++ b/.github/workflows/apply-labels.yml @@ -0,0 +1,23 @@ +--- + +# This workflow will triage pull requests and apply a label based on the +# paths that are modified in the pull request. +# +# To use this workflow, you will need to set up a .github/labeler.yml +# file with configuration. For more information, see: +# https://github.com/actions/labeler/blob/master/README.md + +on: # yamllint disable-line rule:truthy + pull_request: + +name: ๐Ÿท๏ธ Add labels + +jobs: + label: + uses: wayofdev/gh-actions/.github/workflows/apply-labels.yml@master + with: + os: ubuntu-latest + secrets: + token: ${{ secrets.GITHUB_TOKEN }} + +... diff --git a/.github/workflows/auto-merge-release.yaml b/.github/workflows/auto-merge-release.yaml new file mode 100644 index 0000000..084a3e1 --- /dev/null +++ b/.github/workflows/auto-merge-release.yaml @@ -0,0 +1,26 @@ +--- + +# https://github.com/peter-evans/enable-pull-request-automerge + +on: # yamllint disable-line rule:truthy + pull_request: + +permissions: + pull-requests: write + contents: write + +name: ๐Ÿคž Auto merge release + +jobs: + auto-merge: + uses: wayofdev/gh-actions/.github/workflows/auto-merge-release.yml@master + with: + os: ubuntu-latest + pull-request-number: ${{ github.event.pull_request.number }} + actor: lotyp + merge-method: merge + secrets: + # to trigger other workflows, pass PAT token instead of GITHUB_TOKEN + token: ${{ secrets.PERSONAL_GITHUB_TOKEN }} + +... diff --git a/.github/workflows/build-latest.yml b/.github/workflows/build-latest.yml new file mode 100644 index 0000000..ebb3aef --- /dev/null +++ b/.github/workflows/build-latest.yml @@ -0,0 +1,43 @@ +--- + +on: # yamllint disable-line rule:truthy + workflow_dispatch: + pull_request: + branches: + - master + +name: ๐Ÿš€ Build docker images with latest tag + +jobs: + # https://docs.github.com/en/enterprise-cloud@latest/actions/learn-github-actions/expressions#example-returning-a-json-object + prepare: + runs-on: "ubuntu-latest" + outputs: + matrix: ${{ steps.matrix.outputs.matrix }} + steps: + - name: โš™๏ธ Generate matrix + id: matrix + run: | + echo 'matrix={ + "os_name": ["alpine"], + "php_version": ["8.1", "8.2"], + "php_type": ["fpm", "cli", "supervisord"] + }' | tr -d '\n' >> $GITHUB_OUTPUT + + build: + needs: prepare + strategy: + matrix: ${{ fromJson(needs.prepare.outputs.matrix )}} + uses: wayofdev/gh-actions/.github/workflows/build-image.yml@master + with: + os: "ubuntu-latest" + push-to-hub: true + image-namespace: "wayofdev/php-dev" + image-template-path: "./dist/dev" + image-template: ${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }} + image-version: latest + secrets: + docker-username: ${{ secrets.DOCKER_USERNAME }} + docker-password: ${{ secrets.DOCKER_TOKEN }} + +... diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..0b1ca74 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,50 @@ +--- + +on: # yamllint disable-line rule:truthy + release: + types: + - released + +name: ๐Ÿš€ Build docker images with release tag + +jobs: + # https://docs.github.com/en/enterprise-cloud@latest/actions/learn-github-actions/expressions#example-returning-a-json-object + prepare: + runs-on: "ubuntu-latest" + outputs: + matrix: ${{ steps.matrix.outputs.matrix }} + version: ${{ steps.version.outputs.version }} + steps: + - name: โš™๏ธ Generate matrix + id: matrix + run: | + echo 'matrix={ + "os_name": ["alpine"], + "php_version": ["8.1", "8.2"], + "php_type": ["fpm", "cli", "supervisord"] + }' | tr -d '\n' >> $GITHUB_OUTPUT + + - name: โš™๏ธ Get version for image tag + id: version + run: | + version=${{ github.ref_name }} + version=${version#v} + echo "version=$version" >> $GITHUB_OUTPUT + + build: + needs: prepare + strategy: + matrix: ${{ fromJson(needs.prepare.outputs.matrix )}} + uses: wayofdev/gh-actions/.github/workflows/build-image.yml@master + with: + os: "ubuntu-latest" + push-to-hub: true + image-namespace: "wayofdev/php-dev" + image-template-path: "./dist/dev" + image-template: ${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }} + image-version: ${{ needs.prepare.outputs.version }} + secrets: + docker-username: ${{ secrets.DOCKER_USERNAME }} + docker-password: ${{ secrets.DOCKER_TOKEN }} + +... diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index cc175d7..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,114 +0,0 @@ ---- - -name: CI - -on: # yamllint disable-line rule:truthy - push: - branches: - - 'master' - tags: - - 'v*.*.*' - pull_request: - branches: - - 'master' - release: - types: - - 'created' - schedule: - # Every Sunday at 08:10 - - cron: '10 8 * * 0' - -jobs: - build: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - # Build only latest - php_version: ['8.1'] - # Build all versions - # php_version: ['7.4', '8.0', '8.1'] - php_type: ['fpm', 'cli', 'supervisord'] - os_name: ['alpine'] - steps: - - uses: e1himself/goss-installation-action@v1.1.0 - - - name: Checkout - uses: actions/checkout@v3.2.0 - - - name: Set Environment Variables - env: - IMAGE_NAMESPACE: wayofdev/php-dev - TEMPLATE: ${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }} - run: | - export RELEASE_VERSION=${GITHUB_REF#refs/*/} - echo "IMAGE_NAMESPACE=${IMAGE_NAMESPACE}" >> $GITHUB_ENV - echo "TEMPLATE=${TEMPLATE}" >> $GITHUB_ENV - echo "VERSION=${RELEASE_VERSION:1}" >> $GITHUB_ENV - - - name: Docker Meta - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.IMAGE_NAMESPACE }} - tags: | - type=raw,event=branch,value=latest - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - flavor: | - latest=false - prefix=${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}- - - - name: Login to DockerHub - if: github.event_name != 'pull_request' - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - - ### For Cross Platform OSX builds uncomment these lines - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - with: - platforms: arm64 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - with: - install: true - - - name: Build and Export to Docker - uses: docker/build-push-action@v3 - with: - context: ./dist/dev/${{ env.TEMPLATE }} - load: true - tags: ${{ steps.meta.outputs.tags }} - # cache-from: type=registry,ref=${{ env.IMAGE_TAG }} - # cache-to: type=inline - labels: ${{ steps.meta.outputs.labels }} - - - name: Test Docker Release Image - if: success() && startsWith(github.ref, 'refs/tags/') - run: | - IMAGE_TAG=${{ env.IMAGE_NAMESPACE }}:${{ env.TEMPLATE }}-${{ env.VERSION }} make test - echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV - - - name: Test Docker Master Image - if: success() && ! startsWith(github.ref, 'refs/tags/') - run: | - IMAGE_TAG=${{ env.IMAGE_NAMESPACE }}:${{ env.TEMPLATE }}-latest make test - echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV - - - name: Push Docker Image - uses: docker/build-push-action@v3 - with: - context: ./dist/dev/${{ env.TEMPLATE }} - ### For Cross Platform OSX builds uncomment these lines - platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - # cache-from: type=registry,ref=${{ env.IMAGE_TAG }} - # cache-to: type=inline - -... diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 0000000..16f1f51 --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,23 @@ +--- + +# https://github.com/wayofdev/gh-actions/blob/master/.github/workflows/create-release.yml +# https://github.com/google-github-actions/release-please-action#release-types-supported + +on: # yamllint disable-line rule:truthy + push: + branches: + - master + +name: ๐Ÿ“ฆ Create release + +jobs: + release: + uses: wayofdev/gh-actions/.github/workflows/create-release.yml@master + with: + os: ubuntu-latest + branch: master + package-name: docker-php-dev + secrets: + token: ${{ secrets.PERSONAL_GITHUB_TOKEN }} + +... diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml deleted file mode 100644 index 77e2961..0000000 --- a/.github/workflows/release-please.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- - -# https://github.com/google-github-actions/release-please-action#release-types-supported - -on: # yamllint disable-line rule:truthy - push: - branches: - - master - -name: release-please - -jobs: - release-please: - runs-on: ubuntu-latest - steps: - - uses: google-github-actions/release-please-action@v3 - id: release - with: - token: ${{ secrets.PERSONAL_GITHUB_TOKEN }} - release-type: node - package-name: docker-php-dev - default-branch: master - changelog-types: | - [ - { "type": "feat", "section": "Features", "hidden": false }, - { "type": "fix", "section": "Bug Fixes", "hidden": false }, - { "type": "perf", "section": "Performance Improvements", "hidden": false }, - { "type": "docs", "section": "Documentation", "hidden": false }, - { "type": "chore", "section": "Miscellaneous", "hidden": false }, - { "type": "style", "section": "Styles", "hidden": true }, - { "type": "revert", "section": "Reverts", "hidden": true }, - { "type": "deps", "section": "Dependencies", "hidden": true }, - { "type": "refactor", "section": "Code Refactoring", "hidden": true }, - { "type": "test", "section": "Tests", "hidden": true }, - { "type": "build", "section": "Build System", "hidden": true }, - { "type": "ci", "section": "Continuous Integration", "hidden": true } - ] - -... diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index e1f5062..d23d164 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -1,27 +1,20 @@ --- -name: Differential ShellCheck - on: # yamllint disable-line rule:truthy pull_request: +name: ๐Ÿž Differential shell-check + permissions: contents: read jobs: shellcheck: - runs-on: ubuntu-latest - - steps: - - name: Repository checkout - uses: actions/checkout@v3.2.0 - with: - fetch-depth: 0 - - - name: Differential ShellCheck - uses: redhat-plumbers-in-action/differential-shellcheck@v3 - with: - severity: warning - token: ${{ secrets.GITHUB_TOKEN }} + uses: wayofdev/gh-actions/.github/workflows/shellcheck.yml@master + with: + os: ubuntu-latest + severity: warning + secrets: + token: ${{ secrets.GITHUB_TOKEN }} ... diff --git a/.github/workflows/upload-assets.yml b/.github/workflows/upload-assets.yml new file mode 100644 index 0000000..0b45081 --- /dev/null +++ b/.github/workflows/upload-assets.yml @@ -0,0 +1,32 @@ +--- + +# https://github.com/google-github-actions/release-please-action#release-types-supported + +on: # yamllint disable-line rule:truthy + push: + tags: + - "v*.*.*" + +name: ๐Ÿ“ค Upload artifacts + +jobs: + upload-artifacts: + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v3 + + - name: ๐Ÿš€ Generate dist files + run: make generate + + - name: ๐Ÿ—œ๏ธ Archive dist files + run: tar -czvf dist.tar.gz dist + + - name: ๐Ÿ“ค Upload release assets + uses: alexellis/upload-assets@0.4.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + asset_paths: '["./dist.tar.gz"]' + +... diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9e39bea..c46c31b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,15 +2,45 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: fix-encoding-pragma + - repo: https://github.com/adrienverge/yamllint + rev: v1.31.0 + hooks: + - id: yamllint + files: \.(yaml|yml)$ + types: [file, yaml] + entry: yamllint --strict + - repo: https://github.com/commitizen-tools/commitizen - rev: v2.37.0 + rev: 3.2.2 hooks: - id: commitizen stages: - commit-msg + + - repo: https://github.com/ansible/ansible-lint + rev: v6.16.0 + hooks: + - id: ansible-lint + entry: ansible-lint . --force-color + pass_filenames: false + always_run: true + additional_dependencies: + - .[community] + + - repo: https://github.com/robertdebock/pre-commit + rev: v1.5.2 + hooks: + - id: ansible_role_find_unused_variable + - id: ansible_role_find_empty_files + - id: ansible_role_find_empty_directories + - id: ansible_role_fix_readability + - id: ansible_role_find_undefined_handlers + - id: ansible_role_find_unquoted_values + +... diff --git a/.yamllint b/.yamllint index 2575b35..b7bca9b 100644 --- a/.yamllint +++ b/.yamllint @@ -2,60 +2,57 @@ extends: "default" -ignore: | - .build/ - vendor/ # Overwrite above default rules rules: - braces: - # Defaults - # min-spaces-inside: 0 - # max-spaces-inside: 0 + braces: + # Defaults + # min-spaces-inside: 0 + # max-spaces-inside: 0 - # Keep 0 min-spaces to not error on empty {} collection definitions - min-spaces-inside: 0 + # Keep 0 min-spaces to not error on empty {} collection definitions + min-spaces-inside: 0 - # Allow one space inside braces to improve code readability - max-spaces-inside: 1 + # Allow one space inside braces to improve code readability + max-spaces-inside: 1 - brackets: - # Defaults - # min-spaces-inside: 0 - # max-spaces-inside: 0 + brackets: + # Defaults + # min-spaces-inside: 0 + # max-spaces-inside: 0 - # Keep 0 min-spaces to not error on empty [] collection definitions - min-spaces-inside: 0 + # Keep 0 min-spaces to not error on empty [] collection definitions + min-spaces-inside: 0 - # Allow one space inside braces to improve code readability - max-spaces-inside: 1 + # Allow one space inside braces to improve code readability + max-spaces-inside: 1 - colons: - # Defaults - # min-spaces-before: 0 - # max-spaces-after: 1 + colons: + # Defaults + # min-spaces-before: 0 + # max-spaces-after: 1 - # Allow multiple spaces after a colon to allow indentation of YAML - # dictionary values - max-spaces-after: -1 + # Allow multiple spaces after a colon to allow indentation of YAML + # dictionary values + max-spaces-after: -1 - commas: - # Defaults - # max-spaces-after: 1 + commas: + # Defaults + # max-spaces-after: 1 - # Allow multiple spaces after a comma to allow indentation of YAML - # dictionary values - max-spaces-after: -1 + # Allow multiple spaces after a comma to allow indentation of YAML + # dictionary values + max-spaces-after: -1 - comments: - require-starting-space: true - min-spaces-from-content: 1 + comments: + require-starting-space: true + min-spaces-from-content: 1 - line-length: - max: 180 - level: warning + line-length: + max: 180 + level: warning yaml-files: - - "*.yaml" - - "*.yml" + - "*.yaml" + - "*.yml" ... diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/Makefile b/Makefile index 0d81892..32573b3 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,20 @@ +# BuildKit enables higher performance docker builds and caching possibility +# to decrease build times and increase productivity for free. +# https://docs.docker.com/compose/environment-variables/envvars/ export DOCKER_BUILDKIT ?= 1 +export COMPOSE_DOCKER_CLI_BUILD ?= 1 + IMAGE_NAMESPACE ?= wayofdev/php-dev -TEMPLATE ?= 8.1-cli-alpine +IMAGE_TEMPLATE ?= 8.2-fpm-alpine +IMAGE_TAG ?= $(IMAGE_NAMESPACE):$(IMAGE_TEMPLATE)-latest -IMAGE_TAG ?= $(IMAGE_NAMESPACE):$(TEMPLATE)-latest -DOCKERFILE_DIR ?= ./dist/dev/$(TEMPLATE) +DOCKERFILE_DIR ?= ./dist/dev/$(IMAGE_TEMPLATE) CACHE_FROM ?= $(IMAGE_TAG) OS ?= $(shell uname) CURRENT_DIR ?= $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) +# Self documenting Makefile code +# ------------------------------------------------------------------------------------ ifneq ($(TERM),) BLACK := $(shell tput setaf 0) RED := $(shell tput setaf 1) @@ -47,14 +54,27 @@ help: @echo ' ๐Ÿข ${YELLOW}Org wayofdev (github.com/wayofdev)${RST}' .PHONY: help -all: build test +.EXPORT_ALL_VARIABLES: + +# Default action +# Defines default command when `make` is executed without additional parameters +# ------------------------------------------------------------------------------------ +all: generate build test PHONY: all + +# Docker Actions +# ------------------------------------------------------------------------------------ build: ## Build default docker image cd $(CURRENT_DIR)$(DOCKERFILE_DIR); \ - docker build . -t $(IMAGE_TAG) + docker build -t $(IMAGE_TAG) . PHONY: build +analyze: ## Analyze docker image + cd $(CURRENT_DIR)$(DOCKERFILE_DIR); \ + dive build -t $(IMAGE_TAG) . +.PHONY: analyze + build-from-cache: ## Build default docker image using cached layers cd $(CURRENT_DIR)$(DOCKERFILE_DIR); \ docker build --cache-from $(CACHE_FROM) . -t $(IMAGE_TAG) @@ -77,40 +97,44 @@ ssh: ## Login into built image docker run --rm -it -v $(PWD)/:/opt/docker-php-dev $(IMAGE_TAG) sh .PHONY: ssh -hadolint: ## Run hadolint over dist Dockerfiles - hadolint -V ./dist/dev/7.4-cli-alpine/Dockerfile - hadolint -V ./dist/dev/7.4-fpm-alpine/Dockerfile - hadolint -V ./dist/dev/7.4-supervisord-alpine/Dockerfile - hadolint -V ./dist/dev/8.0-cli-alpine/Dockerfile - hadolint -V ./dist/dev/8.0-fpm-alpine/Dockerfile - hadolint -V ./dist/dev/8.0-supervisord-alpine/Dockerfile - hadolint -V ./dist/dev/8.1-cli-alpine/Dockerfile - hadolint -V ./dist/dev/8.1-fpm-alpine/Dockerfile - hadolint -V ./dist/dev/8.1-supervisord-alpine/Dockerfile -.PHONY: hadolint +# Ansible Actions +# ------------------------------------------------------------------------------------ +generate: ## Generates dockerfiles from ansible templates + ansible-playbook src/playbook.yml +PHONY: generate -# Git Actions +clean: ## Cleans up generated files + rm -rf ./dist/* +PHONY: clean + + +# Code Quality, Git, Linting, Testing # ------------------------------------------------------------------------------------ hooks: ## Install git hooks from pre-commit-config pre-commit install pre-commit autoupdate .PHONY: hooks - -# Yaml Actions -# ------------------------------------------------------------------------------------ -lint: ## Lints yaml files inside project +lint-yaml: ## Lints yaml files inside project yamllint . -.PHONY: lint +.PHONY: lint-yaml +lint-ansible: ## Lint ansible files inside project + ansible-lint . +.PHONY: lint-ansible -# Ansible Actions -# ------------------------------------------------------------------------------------ -generate: - ansible-playbook src/generate.yml -PHONY: generate - -clean: - rm -rf ./dist/* -PHONY: clean +lint-docker: ## Run hadolint linter over dist Dockerfiles + hadolint -V ./dist/dev/7.4-cli-alpine/Dockerfile + hadolint -V ./dist/dev/7.4-fpm-alpine/Dockerfile + hadolint -V ./dist/dev/7.4-fpm-supervisord/Dockerfile + hadolint -V ./dist/dev/8.0-cli-alpine/Dockerfile + hadolint -V ./dist/dev/8.0-fpm-alpine/Dockerfile + hadolint -V ./dist/dev/8.0-fpm-supervisord/Dockerfile + hadolint -V ./dist/dev/8.1-cli-alpine/Dockerfile + hadolint -V ./dist/dev/8.1-fpm-alpine/Dockerfile + hadolint -V ./dist/dev/8.1-fpm-supervisord/Dockerfile + hadolint -V ./dist/dev/8.2-cli-alpine/Dockerfile + hadolint -V ./dist/dev/8.2-fpm-alpine/Dockerfile + hadolint -V ./dist/dev/8.2-fpm-supervisord/Dockerfile +.PHONY: lint-docker diff --git a/README.md b/README.md index 711a3fd..b0cd834 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Build Status Latest Version Docker Pulls -Software License +Software License Commits since latest release @@ -26,7 +26,6 @@ Repository contains dist folder with generated, local development ready, PHP ima **Upstream images:** * [wayofdev/docker-php-base](https://github.com/wayofdev/docker-php-base) -* [wayofdev/docker-php-prod](https://github.com/wayofdev/docker-php-prod) Additionaly to upstream images, enabled extensions by default: @@ -64,9 +63,6 @@ Ansible is used to generate distribution files, to add or remove PHP extensions, ext_pecl_enabled: - xdebug -ext_pecl_versions: - xdebug: "3.1.5" - install_composer: true install_faketime: true @@ -115,6 +111,7 @@ Building default image: ```bash $ git clone git@github.com:wayofdev/docker-php-dev.git +$ cd docker-php-dev $ make build ``` @@ -127,22 +124,25 @@ $ make Building all images: ```bash -$ make build TEMPLATE="7.4-cli-alpine" -$ make build TEMPLATE="7.4-fpm-alpine" -$ make build TEMPLATE="7.4-supervisord-alpine" -$ make build TEMPLATE="8.0-cli-alpine" -$ make build TEMPLATE="8.0-fpm-alpine" -$ make build TEMPLATE="8.0-supervisord-alpine" -$ make build TEMPLATE="8.1-cli-alpine" -$ make build TEMPLATE="8.1-fpm-alpine" -$ make build TEMPLATE="8.1-supervisord-alpine" +$ make build IMAGE_TEMPLATE="7.4-cli-alpine" +$ make build IMAGE_TEMPLATE="7.4-fpm-alpine" +$ make build IMAGE_TEMPLATE="7.4-supervisord-alpine" +$ make build IMAGE_TEMPLATE="8.0-cli-alpine" +$ make build IMAGE_TEMPLATE="8.0-fpm-alpine" +$ make build IMAGE_TEMPLATE="8.0-supervisord-alpine" +$ make build IMAGE_TEMPLATE="8.1-cli-alpine" +$ make build IMAGE_TEMPLATE="8.1-fpm-alpine" +$ make build IMAGE_TEMPLATE="8.1-supervisord-alpine" +$ make build IMAGE_TEMPLATE="8.2-cli-alpine" +$ make build IMAGE_TEMPLATE="8.2-fpm-alpine" +$ make build IMAGE_TEMPLATE="8.2-supervisord-alpine" ```
## ๐Ÿงช Testing -You can check `Makefile` to get full list of commands for local testing. For testing you can use these comands to test whole role or separate tasks: +You can check `Makefile` to get full list of commands for local testing. For testing, you can use these commands to test whole role or separate tasks: Testing default image: @@ -153,15 +153,18 @@ $ make test To test all images: ```bash -$ make test TEMPLATE="7.4-cli-alpine" -$ make test TEMPLATE="7.4-fpm-alpine" -$ make test TEMPLATE="7.4-supervisord-alpine" -$ make test TEMPLATE="8.0-cli-alpine" -$ make test TEMPLATE="8.0-fpm-alpine" -$ make test TEMPLATE="8.0-supervisord-alpine" -$ make test TEMPLATE="8.1-cli-alpine" -$ make test TEMPLATE="8.1-fpm-alpine" -$ make test TEMPLATE="8.1-supervisord-alpine" +$ make test IMAGE_TEMPLATE="7.4-cli-alpine" +$ make test IMAGE_TEMPLATE="7.4-fpm-alpine" +$ make test IMAGE_TEMPLATE="7.4-supervisord-alpine" +$ make test IMAGE_TEMPLATE="8.0-cli-alpine" +$ make test IMAGE_TEMPLATE="8.0-fpm-alpine" +$ make test IMAGE_TEMPLATE="8.0-supervisord-alpine" +$ make test IMAGE_TEMPLATE="8.1-cli-alpine" +$ make test IMAGE_TEMPLATE="8.1-fpm-alpine" +$ make test IMAGE_TEMPLATE="8.1-supervisord-alpine" +$ make test IMAGE_TEMPLATE="8.2-cli-alpine" +$ make test IMAGE_TEMPLATE="8.2-fpm-alpine" +$ make test IMAGE_TEMPLATE="8.2-supervisord-alpine" ```
@@ -171,13 +174,19 @@ $ make test TEMPLATE="8.1-supervisord-alpine" Run **yamllint** to validate all yaml files in project: ```bash -$ make lint +$ make lint-yaml ``` Run hadolint to validate created Dockerfiles: ```bash -$ make hadolint +$ make lint-docker +``` + +Run ansible-lint to validate project files: + +```bash +$ make lint-ansible ```
@@ -198,7 +207,7 @@ This repository was created in **2022** by [lotyp / wayofdev](https://github.com - + diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..a393664 --- /dev/null +++ b/renovate.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ], + "automerge": true, + "platformAutomerge": true +} diff --git a/src/Dockerfiles/dev/Dockerfile.j2 b/src/Dockerfiles/dev/Dockerfile.j2 index b9df264..9ff0086 100644 --- a/src/Dockerfiles/dev/Dockerfile.j2 +++ b/src/Dockerfiles/dev/Dockerfile.j2 @@ -1,6 +1,6 @@ {{ edit_comment_dev }} -FROM wayofdev/php-prod:{{ php_version }}-{{ php_type }}-{{ os_name }}-latest +FROM wayofdev/php-base:{{ php_version }}-{{ php_type }}-{{ os_name }}-latest # Labels # https://github.com/opencontainers/image-spec/blob/main/annotations.md @@ -16,6 +16,8 @@ LABEL "org.opencontainers.image.ref.name"="{{ php_version }}-{{ level }}" LABEL "org.opencontainers.image.title"="PHP-{{ php_type|upper }} {{ php_version }}-{{ level }}" LABEL "org.opencontainers.image.description"="PHP-{{ php_type|upper }} {{ php_version }}-{{ level }}" +ENV COMPOSER_ALLOW_SUPERUSER=1 + USER root RUN set -eux; \ @@ -25,18 +27,18 @@ RUN set -eux; \ {% for pkg in system_packages | unique %} {{ pkg }} \ {% endfor %} - # Temporary build dependencies for compiling Pecl extensions - && apk add --no-cache --virtual .temp-build-deps \ - $PHPIZE_DEPS \ - # Pecl Dependencies - # Xdebug -{% if 'xdebug' in ext_pecl_enabled %} - && pecl install xdebug-{{ ext_pecl_versions.xdebug }} \ - && docker-php-ext-enable xdebug \ -{% endif %} + && \ + curl -sSLf \ + -o /usr/local/bin/install-php-extensions \ + https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions \ + && chmod +x /usr/local/bin/install-php-extensions \ + && install-php-extensions \ +{% for ext in ext_pecl_enabled | unique | sort %} + {{ ext }} \ +{% endfor %} # Other Dependencies - # Composer {% if true == install_composer %} + # Composer && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \ {% endif %} {% if 'cli' == php_type %} @@ -58,8 +60,10 @@ RUN set -eux; \ && apk add --no-cache -X https://dl-cdn.alpinelinux.org/alpine/edge/testing libfaketime \ && echo "/usr/lib/faketime/libfaketime.so.1" >> /etc/ld.so.preload \ {% endif %} - && chown -R www-data:www-data /usr/local/etc/php/conf.d/ \ - && apk del -f .temp-build-deps + && install-php-extensions --cleanup \ + && rm -rf /var/cache/apk/* \ + && rm -rf /tmp/* \ + && rm -rf /var/log/* {% if 'xdebug' in ext_pecl_enabled %} COPY --chown=www-data ./configs/99-xdebug.ini /usr/local/etc/php/conf.d/ diff --git a/src/group_vars/dev.yml b/src/group_vars/dev.yml index 975f25a..702422a 100644 --- a/src/group_vars/dev.yml +++ b/src/group_vars/dev.yml @@ -38,15 +38,9 @@ tpl_docker_tests: # Enabled extensions ######################################################################################################################## -# ext_native_enabled: -# - ... - ext_pecl_enabled: - xdebug -ext_pecl_versions: - xdebug: "3.1.5" - install_composer: true install_faketime: true diff --git a/src/inventory.yml b/src/inventory.yml index aab17d3..e887f63 100644 --- a/src/inventory.yml +++ b/src/inventory.yml @@ -4,6 +4,7 @@ all: children: dev: hosts: + # PHP 7.4 7.4-cli-alpine: ansible_connection: local level: dev @@ -22,6 +23,7 @@ all: php_version: 7.4 php_type: supervisord os_name: alpine + # PHP 8.0 8.0-cli-alpine: ansible_connection: local level: dev @@ -40,6 +42,7 @@ all: php_version: 8.0 php_type: supervisord os_name: alpine + # PHP 8.1 8.1-cli-alpine: ansible_connection: local level: dev @@ -58,5 +61,24 @@ all: php_version: 8.1 php_type: supervisord os_name: alpine + # PHP 8.2 + 8.2-cli-alpine: + ansible_connection: local + level: dev + php_version: 8.2 + php_type: cli + os_name: alpine + 8.2-fpm-alpine: + ansible_connection: local + level: dev + php_version: 8.2 + php_type: fpm + os_name: alpine + 8.2-supervisord-alpine: + ansible_connection: local + level: dev + php_version: 8.2 + php_type: supervisord + os_name: alpine ... diff --git a/src/generate.yml b/src/playbook.yml similarity index 100% rename from src/generate.yml rename to src/playbook.yml