summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorShyam Sunder <sgsunder1@gmail.com>2020-06-05 12:47:23 -0400
committerShyam Sunder <sgsunder1@gmail.com>2020-06-05 12:47:23 -0400
commitc06aaa63af977e64ef08bfba7829214f0f0ed38e (patch)
treeca8e1ab9fa46e44e8343903395aa162af3b70356 /server
parent454685755bc3be4b651d44509e135990c72923f5 (diff)
dev: add pre-commit hooks for pytest and docker building
Diffstat (limited to 'server')
-rw-r--r--server/Dockerfile.test50
-rwxr-xr-xserver/hooks/test30
2 files changed, 52 insertions, 28 deletions
diff --git a/server/Dockerfile.test b/server/Dockerfile.test
new file mode 100644
index 0000000..d5b1133
--- /dev/null
+++ b/server/Dockerfile.test
@@ -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/"]
diff --git a/server/hooks/test b/server/hooks/test
index 056ca2c..bf7776d 100755
--- a/server/hooks/test
+++ b/server/hooks/test
@@ -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 $?