server/docker: unify test and main Dockerfiles
This commit is contained in:
parent
c004eb36c2
commit
e656a3c46a
6 changed files with 66 additions and 81 deletions
|
@ -1,21 +1,21 @@
|
||||||
repos:
|
repos:
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v2.4.0
|
rev: v3.2.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
|
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: stable
|
rev: 20.8b1
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
files: server/szurubooru/
|
files: server/szurubooru/
|
||||||
language_version: python3.8
|
language_version: python3.8
|
||||||
|
|
||||||
- repo: https://github.com/timothycrosley/isort
|
- repo: https://github.com/timothycrosley/isort
|
||||||
rev: '4.3.21-2'
|
rev: '5.4.2'
|
||||||
hooks:
|
hooks:
|
||||||
- id: isort
|
- id: isort
|
||||||
files: server/szurubooru/
|
files: server/szurubooru/
|
||||||
|
@ -24,7 +24,7 @@ repos:
|
||||||
- toml
|
- toml
|
||||||
|
|
||||||
- repo: https://github.com/prettier/prettier
|
- repo: https://github.com/prettier/prettier
|
||||||
rev: '2.0.5'
|
rev: '2.1.1'
|
||||||
hooks:
|
hooks:
|
||||||
- id: prettier
|
- id: prettier
|
||||||
files: client/js/
|
files: client/js/
|
||||||
|
@ -32,7 +32,7 @@ repos:
|
||||||
args: ['--config', 'client/.prettierrc.yml']
|
args: ['--config', 'client/.prettierrc.yml']
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-eslint
|
- repo: https://github.com/pre-commit/mirrors-eslint
|
||||||
rev: v7.1.0
|
rev: v7.7.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: eslint
|
- id: eslint
|
||||||
files: client/js/
|
files: client/js/
|
||||||
|
@ -41,7 +41,7 @@ repos:
|
||||||
- eslint-config-prettier
|
- eslint-config-prettier
|
||||||
|
|
||||||
- repo: https://gitlab.com/pycqa/flake8
|
- repo: https://gitlab.com/pycqa/flake8
|
||||||
rev: '3.8.2'
|
rev: '3.8.3'
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
files: server/szurubooru/
|
files: server/szurubooru/
|
||||||
|
@ -69,7 +69,7 @@ repos:
|
||||||
|
|
||||||
- id: pytest
|
- id: pytest
|
||||||
name: 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
|
language: system
|
||||||
types: [python]
|
types: [python]
|
||||||
files: server/szurubooru/
|
files: server/szurubooru/
|
||||||
|
@ -79,7 +79,7 @@ repos:
|
||||||
|
|
||||||
- id: pytest-cov
|
- id: pytest-cov
|
||||||
name: pytest
|
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
|
language: system
|
||||||
types: [python]
|
types: [python]
|
||||||
files: server/szurubooru/
|
files: server/szurubooru/
|
||||||
|
|
|
@ -22,7 +22,7 @@ WORKDIR /var/www
|
||||||
COPY --from=builder /opt/app/public/ .
|
COPY --from=builder /opt/app/public/ .
|
||||||
|
|
||||||
|
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine as release
|
||||||
|
|
||||||
RUN apk --no-cache add dumb-init
|
RUN apk --no-cache add dumb-init
|
||||||
COPY --from=approot / /
|
COPY --from=approot / /
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
FROM alpine:3.12
|
ARG ALPINE_VERSION=3.12
|
||||||
|
|
||||||
|
|
||||||
|
FROM alpine:$ALPINE_VERSION as prereqs
|
||||||
WORKDIR /opt/app
|
WORKDIR /opt/app
|
||||||
|
|
||||||
RUN \
|
RUN apk --no-cache add \
|
||||||
apk --no-cache add \
|
|
||||||
python3 \
|
python3 \
|
||||||
dumb-init \
|
|
||||||
ffmpeg \
|
ffmpeg \
|
||||||
py3-waitress \
|
|
||||||
py3-setuptools \
|
|
||||||
py3-pip \
|
py3-pip \
|
||||||
# from requirements.txt:
|
# from requirements.txt:
|
||||||
py3-yaml \
|
py3-yaml \
|
||||||
|
@ -19,30 +18,63 @@ RUN \
|
||||||
py3-pynacl \
|
py3-pynacl \
|
||||||
py3-tz \
|
py3-tz \
|
||||||
py3-pyrfc3339 \
|
py3-pyrfc3339 \
|
||||||
&& \
|
&& pip3 install --no-cache-dir --disable-pip-version-check \
|
||||||
pip3 install --no-cache-dir --disable-pip-version-check \
|
|
||||||
alembic \
|
alembic \
|
||||||
"coloredlogs==5.0" \
|
"coloredlogs==5.0" \
|
||||||
youtube-dl \
|
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 PUID=1000
|
||||||
ARG PGID=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
|
ARG PORT=6666
|
||||||
ENV PORT=${PORT}
|
ENV PORT=${PORT}
|
||||||
EXPOSE ${PORT}
|
EXPOSE ${PORT}
|
||||||
|
|
||||||
VOLUME ["/data/"]
|
VOLUME ["/data/"]
|
||||||
CMD ["/opt/app/docker-start.sh"]
|
|
||||||
|
|
||||||
ARG DOCKER_REPO
|
ARG DOCKER_REPO
|
||||||
ARG BUILD_DATE
|
ARG BUILD_DATE
|
||||||
|
|
|
@ -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/"]
|
|
|
@ -2,7 +2,7 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
-t $(docker build -f ${DOCKERFILE_PATH:-Dockerfile}.test -q .) \
|
-t $(docker build --target testing -q .) \
|
||||||
--color=no szurubooru/
|
--color=no szurubooru/
|
||||||
|
|
||||||
exit $?
|
exit $?
|
||||||
|
|
|
@ -22,9 +22,12 @@ def _merge(left: Dict, right: Dict) -> Dict:
|
||||||
|
|
||||||
|
|
||||||
def _docker_config() -> Dict:
|
def _docker_config() -> Dict:
|
||||||
for key in ["POSTGRES_USER", "POSTGRES_PASSWORD", "POSTGRES_HOST"]:
|
if "TEST_ENVIRONMENT" not in os.environ:
|
||||||
if not os.getenv(key, False):
|
for key in ["POSTGRES_USER", "POSTGRES_PASSWORD", "POSTGRES_HOST"]:
|
||||||
raise errors.ConfigError(f'Environment variable "{key}" not set')
|
if key not in os.environ:
|
||||||
|
raise errors.ConfigError(
|
||||||
|
f'Environment variable "{key}" not set'
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
"debug": True,
|
"debug": True,
|
||||||
"show_sql": int(os.getenv("LOG_SQL", 0)),
|
"show_sql": int(os.getenv("LOG_SQL", 0)),
|
||||||
|
|
Loading…
Reference in a new issue