dev: add pre-commit hooks for pytest and docker building
This commit is contained in:
parent
454685755b
commit
c06aaa63af
3 changed files with 79 additions and 28 deletions
|
@ -20,4 +20,31 @@ repos:
|
|||
additional_dependencies:
|
||||
- flake8-print
|
||||
args: ['--config=server/setup.cfg']
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: pytest
|
||||
name: pytest
|
||||
entry: >-
|
||||
bash -c
|
||||
'docker build -f server/Dockerfile.test -t $(git rev-parse --short HEAD)-test server/
|
||||
&& docker run --rm -t $(git rev-parse --short HEAD)-test szurubooru/
|
||||
&& docker rmi --no-prune $(git rev-parse --short HEAD)-test'
|
||||
language: system
|
||||
types: [python]
|
||||
files: server/szurubooru/
|
||||
pass_filenames: false
|
||||
- id: docker-build-client
|
||||
name: Test building the client in Docker
|
||||
entry: bash -c 'docker build -t szurubooru-client:$(git rev-parse --short HEAD) client/'
|
||||
language: system
|
||||
types: [file]
|
||||
files: client/
|
||||
pass_filenames: false
|
||||
- id: docker-build-server
|
||||
name: Test building the server in Docker
|
||||
entry: bash -c 'docker build -t szurubooru-server:$(git rev-parse --short HEAD) server/'
|
||||
language: system
|
||||
types: [file]
|
||||
files: server/
|
||||
pass_filenames: false
|
||||
exclude: LICENSE.md
|
||||
|
|
50
server/Dockerfile.test
Normal file
50
server/Dockerfile.test
Normal file
|
@ -0,0 +1,50 @@
|
|||
FROM alpine:3.12
|
||||
WORKDIR /opt/app
|
||||
|
||||
RUN \
|
||||
apk --no-cache add \
|
||||
python3 \
|
||||
ffmpeg \
|
||||
py3-pip \
|
||||
# from requirements.txt:
|
||||
py3-yaml \
|
||||
py3-psycopg2 \
|
||||
py3-sqlalchemy \
|
||||
py3-certifi \
|
||||
py3-numpy \
|
||||
py3-pillow \
|
||||
py3-pynacl \
|
||||
py3-tz \
|
||||
py3-pyrfc3339 \
|
||||
# for testing
|
||||
py3-pytest \
|
||||
py3-pytest-cov \
|
||||
postgresql \
|
||||
&& \
|
||||
pip3 install --no-cache-dir --disable-pip-version-check \
|
||||
alembic \
|
||||
"coloredlogs==5.0" \
|
||||
youtube-dl \
|
||||
# for testing
|
||||
pytest-pgsql \
|
||||
freezegun \
|
||||
&& apk --no-cache del py3-pip
|
||||
|
||||
ARG PUID=1000
|
||||
ARG PGID=1000
|
||||
RUN \
|
||||
# Set users
|
||||
mkdir -p /opt/app /data && \
|
||||
addgroup -g ${PGID} app && \
|
||||
adduser -SDH -h /opt/app -g '' -G app -u ${PUID} app && \
|
||||
chown -R app:app /opt/app /data
|
||||
USER app
|
||||
|
||||
ENV POSTGRES_HOST=x \
|
||||
POSTGRES_USER=x \
|
||||
POSTGRES_PASSWORD=x
|
||||
|
||||
COPY --chown=app:app ./ /opt/app/
|
||||
|
||||
ENTRYPOINT ["pytest", "--tb=short"]
|
||||
CMD ["--cov-report=term-missing:skip-covered", "--cov=szurubooru", "szurubooru/"]
|
|
@ -1,34 +1,8 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
docker build \
|
||||
--build-arg BASE_IMAGE=${IMAGE_NAME} \
|
||||
--file - \
|
||||
--tag ${IMAGE_NAME}-test \
|
||||
. <<'EOF'
|
||||
ARG BASE_IMAGE
|
||||
FROM ${BASE_IMAGE}
|
||||
WORKDIR /opt/app
|
||||
USER root
|
||||
RUN apk --no-cache add \
|
||||
py3-pip \
|
||||
py3-pytest \
|
||||
py3-pytest-cov \
|
||||
postgresql \
|
||||
&& \
|
||||
pip3 install \
|
||||
--no-cache-dir \
|
||||
--disable-pip-version-check \
|
||||
pytest-pgsql \
|
||||
freezegun
|
||||
USER app
|
||||
ENV POSTGRES_HOST=x \
|
||||
POSTGRES_USER=x \
|
||||
POSTGRES_PASSWORD=x
|
||||
CMD ["pytest", "szurubooru/", \
|
||||
"--cov-report=term-missing", "--cov=szurubooru", "--tb=short"]
|
||||
EOF
|
||||
|
||||
docker build -f ${DOCKERFILE_PATH:-Dockerfile}.test -t ${IMAGE_NAME}-test .
|
||||
docker run --rm -t ${IMAGE_NAME}-test
|
||||
docker rmi ${IMAGE_NAME}-test
|
||||
|
||||
exit $?
|
||||
|
|
Loading…
Reference in a new issue