server/docker: unify test and main Dockerfiles

This commit is contained in:
Shyam Sunder 2020-08-28 14:43:10 -04:00
parent c004eb36c2
commit e656a3c46a
6 changed files with 66 additions and 81 deletions

View file

@ -1,21 +1,21 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/psf/black
rev: stable
rev: 20.8b1
hooks:
- id: black
files: server/szurubooru/
language_version: python3.8
- repo: https://github.com/timothycrosley/isort
rev: '4.3.21-2'
rev: '5.4.2'
hooks:
- id: isort
files: server/szurubooru/
@ -24,7 +24,7 @@ repos:
- toml
- repo: https://github.com/prettier/prettier
rev: '2.0.5'
rev: '2.1.1'
hooks:
- id: prettier
files: client/js/
@ -32,7 +32,7 @@ repos:
args: ['--config', 'client/.prettierrc.yml']
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v7.1.0
rev: v7.7.0
hooks:
- id: eslint
files: client/js/
@ -41,7 +41,7 @@ repos:
- eslint-config-prettier
- repo: https://gitlab.com/pycqa/flake8
rev: '3.8.2'
rev: '3.8.3'
hooks:
- id: flake8
files: server/szurubooru/
@ -69,7 +69,7 @@ repos:
- id: pytest
name: pytest
entry: bash -c 'docker run --rm -t $(docker build -f server/Dockerfile.test -q server/) szurubooru/'
entry: bash -c 'docker run --rm -t $(docker build --target testing -q server/) szurubooru/'
language: system
types: [python]
files: server/szurubooru/
@ -79,7 +79,7 @@ repos:
- id: pytest-cov
name: pytest
entry: bash -c 'docker run --rm -t $(docker build -f server/Dockerfile.test -q server/) --cov-report=term-missing:skip-covered --cov=szurubooru szurubooru/'
entry: bash -c 'docker run --rm -t $(docker build --target testing -q server/) --cov-report=term-missing:skip-covered --cov=szurubooru szurubooru/'
language: system
types: [python]
files: server/szurubooru/

View file

@ -22,7 +22,7 @@ WORKDIR /var/www
COPY --from=builder /opt/app/public/ .
FROM nginx:alpine
FROM nginx:alpine as release
RUN apk --no-cache add dumb-init
COPY --from=approot / /

View file

@ -1,13 +1,12 @@
FROM alpine:3.12
ARG ALPINE_VERSION=3.12
FROM alpine:$ALPINE_VERSION as prereqs
WORKDIR /opt/app
RUN \
apk --no-cache add \
RUN apk --no-cache add \
python3 \
dumb-init \
ffmpeg \
py3-waitress \
py3-setuptools \
py3-pip \
# from requirements.txt:
py3-yaml \
@ -19,30 +18,63 @@ RUN \
py3-pynacl \
py3-tz \
py3-pyrfc3339 \
&& \
pip3 install --no-cache-dir --disable-pip-version-check \
&& pip3 install --no-cache-dir --disable-pip-version-check \
alembic \
"coloredlogs==5.0" \
youtube-dl \
&& apk --no-cache del py3-pip
&& apk --no-cache del py3-pip
COPY ./ /opt/app/
RUN rm -rf /opt/app/szurubooru/tests
FROM prereqs as testing
WORKDIR /opt/app
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 \
&& apk --no-cache del py3-pip \
&& addgroup app \
&& adduser -SDH -h /opt/app -g '' -G app app \
&& chown app:app /opt/app
COPY --chown=app:app ./szurubooru/tests /opt/app/szurubooru/tests/
ENV TEST_ENVIRONMENT="true"
USER app
ENTRYPOINT ["pytest", "--tb=short"]
CMD ["szurubooru/"]
FROM prereqs as release
WORKDIR /opt/app
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
COPY --chown=app:app ./ /opt/app/
RUN apk --no-cache add \
dumb-init \
py3-setuptools \
py3-waitress \
&& 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
CMD ["/opt/app/docker-start.sh"]
ARG PORT=6666
ENV PORT=${PORT}
EXPOSE ${PORT}
VOLUME ["/data/"]
CMD ["/opt/app/docker-start.sh"]
ARG DOCKER_REPO
ARG BUILD_DATE

View file

@ -1,50 +0,0 @@
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 ["szurubooru/"]

View file

@ -2,7 +2,7 @@
set -e
docker run --rm \
-t $(docker build -f ${DOCKERFILE_PATH:-Dockerfile}.test -q .) \
-t $(docker build --target testing -q .) \
--color=no szurubooru/
exit $?

View file

@ -22,9 +22,12 @@ def _merge(left: Dict, right: Dict) -> Dict:
def _docker_config() -> Dict:
for key in ["POSTGRES_USER", "POSTGRES_PASSWORD", "POSTGRES_HOST"]:
if not os.getenv(key, False):
raise errors.ConfigError(f'Environment variable "{key}" not set')
if "TEST_ENVIRONMENT" not in os.environ:
for key in ["POSTGRES_USER", "POSTGRES_PASSWORD", "POSTGRES_HOST"]:
if key not in os.environ:
raise errors.ConfigError(
f'Environment variable "{key}" not set'
)
return {
"debug": True,
"show_sql": int(os.getenv("LOG_SQL", 0)),