Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
.git
.github
__pycache__
.*project
.pytest_cache
.vscode
docs/
/.settings/
/tests
bin
Dockerfile
docs/
include
lib
lib64
LICENSE.txt
Makefile
README.md
README.md
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Release new Docker image

on:
push:
branches:
- 'main'
tags:
- 'v*.*.*'
pull_request:
Expand Down Expand Up @@ -54,8 +56,6 @@ jobs:
- name: Test image
run: |
docker run --rm -v "${PWD}":/github/workspace ${{ env.IMAGE_NAME }}:${{ env.TEST_TAG }} check black ${{ env.TEST_PATHS }}
docker run --rm -v "${PWD}":/github/workspace ${{ env.IMAGE_NAME }}:${{ env.TEST_TAG }} check flake8 ${{ env.TEST_PATHS }}
docker run --rm -v "${PWD}":/github/workspace ${{ env.IMAGE_NAME }}:${{ env.TEST_TAG }} check isort ${{ env.TEST_PATHS }}

- name: Login to DockerHub
uses: docker/login-action@v1
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test codebase

on: push

jobs:

tests:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r tests/requirements.txt

- name: Run tests
run: |
python -m pytest tests/
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
__pycache__
.*project
.pytest_cache
.vscode
/.settings/
.*project
bin
include
lib
lib64
21 changes: 16 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
FROM python:3.10-slim
FROM python:3.10-slim as base
FROM base as builder

RUN pip install -U pip wheel \
&& mkdir /app /wheelhouse

COPY requirements.txt /app/
COPY src /app/src

RUN cd /app/ && pip wheel -r requirements.txt --wheel-dir=/wheelhouse

FROM base

LABEL maintainer="Plone Community <dev@plone.org>" \
org.label-schema.name="code-quality" \
org.label-schema.description="Plone code quality tool" \
org.label-schema.vendor="Plone Foundation" \
org.label-schema.docker.cmd="docker run -rm -v "${PWD}":/github/workspace plone/code-quality check black src"
Comment thread
ericof marked this conversation as resolved.

COPY requirements.txt pyproject.toml docker-entrypoint.py ./

RUN pip install -U pip && pip install -r requirements.txt

WORKDIR /github/workspace

ENTRYPOINT [ "/docker-entrypoint.py" ]

COPY docker-entrypoint.py /
COPY --from=builder /wheelhouse /wheelhouse
RUN pip install --force-reinstall --no-index --no-deps /wheelhouse/*
39 changes: 34 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
IMAGE_NAME=plone/code-quality
DOCKERFILE=Dockerfile
CODEBASE=docker-entrypoint.py
LINT=docker run --rm -v "${PWD}":/github/workspace "${IMAGE_NAME}:latest" check
FORMAT=docker run --rm -v "${PWD}":/github/workspace "${IMAGE_NAME}:latest" format
ifndef LOG_LEVEL
LOG_LEVEL=INFO
endif
CURRENT_USER=$$(whoami)
USER_INFO=$$(id -u ${CURRENT_USER}):$$(getent group ${CURRENT_USER}|cut -d: -f3)
CODEBASE=docker-entrypoint.py src/setup.py src/plone_code_analysis tests/fixtures/packages/ok tests/package tests/conftest.py
LINT=docker run -e LOG_LEVEL="${LOG_LEVEL}" --rm -v "${PWD}":/github/workspace "${IMAGE_NAME}:latest" check
FORMAT=docker run --user="${USER_INFO}" -e LOG_LEVEL="${LOG_LEVEL}" --rm -v "${PWD}":/github/workspace "${IMAGE_NAME}:latest" format


# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
.PHONY: help
help: ## This help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

bin/pip:
@echo "$(GREEN)==> Setup Virtual Env$(RESET)"
python3 -m venv .
bin/pip install -r requirements.txt

bin/pytest:
bin/pip install -r tests/requirements.txt

.PHONY: clean
clean: ## remove virtual environment
rm -fr bin include lib lib64

.PHONY: setup
setup: bin/pytest ## Create virtualenv and run pip install

.PHONY: test
test: bin/pytest ## Create virtualenv and run pip install
@echo "$(GREEN)==> Run tests $(RESET)"
bin/python -m pytest tests

.PHONY: build-image
build-image: ## Build Docker Image
@echo "Building $(IMAGE_NAME):latest"
Expand All @@ -23,8 +48,12 @@ lint: build-image ## Lint code with existing image
$(LINT) flake8 "${CODEBASE}"
$(LINT) isort "${CODEBASE}"

.PHONY: lint-all
lint-all: build-image ## Lint code with existing image using configurations from pyproject.toml
@echo "Linting ${CODEBASE} $(IMAGE_NAME):latest"
$(LINT)

.PHONY: format
format: build-image ## Format code with existing image
@echo "Formatting ${CODEBASE} $(IMAGE_NAME):latest"
$(FORMAT) "${CODEBASE}"
sudo chown -R ${CURRENT_USER}: *
$(FORMAT)
Loading