Skip to content

Commit 34cccc3

Browse files
author
Rufina
authored
Build: multistage, maintenance info, .dockerignore (#16)
Build: multistage, .dockerignore, delete volume
1 parent 3fc742f commit 34cccc3

File tree

5 files changed

+55
-39
lines changed

5 files changed

+55
-39
lines changed

.dockerignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# Created by .ignore support plugin (hsz.mobi)
22
test
33
.idea
4-
venv
4+
venv
5+
.dockerignore
6+
.github
7+
.gitignore
8+
jenkinsfile.disable.groovy
9+
Dockerfile*
10+
README.md

Dockerfile

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,58 @@
1-
ARG PYTHON_IMAGE_VERSION=latest
2-
FROM python:${PYTHON_IMAGE_VERSION}-slim
3-
ARG GRPC_HEALTH_PROBE_VERSION=v0.4.2
1+
# syntax=docker/dockerfile:1
2+
ARG PYTHON_IMAGE_VERSION=3.7
3+
FROM python:${PYTHON_IMAGE_VERSION}-slim as base
4+
LABEL DEPLOYMENT_TYPE="APP" maintainer="support@hydrosphere.io"
5+
6+
ENV PYTHONUNBUFFERED=1 \
7+
PYTHONDONTWRITEBYTECODE=1 \
8+
POETRY_PATH=/opt/poetry \
9+
VENV_PATH=/opt/pysetup/.venv \
10+
POETRY_VERSION=1.1.6
11+
ENV PATH="$POETRY_PATH/bin:$VENV_PATH/bin:$PATH"
12+
13+
FROM base AS build
14+
15+
RUN apt-get update && apt-get -y install \
16+
curl \
17+
sudo \
18+
wget && \
19+
\
20+
GRPC_HEALTH_PROBE_VERSION=v0.4.2 && wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
21+
chmod +x /bin/grpc_health_probe && \
22+
\
23+
curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python && \
24+
mv /root/.poetry $POETRY_PATH && \
25+
python -m venv $VENV_PATH && \
26+
poetry config virtualenvs.create false && \
27+
poetry config experimental.new-installer false && \
28+
pip install --upgrade pip && \
29+
rm -rf /var/lib/apt/lists/*
430

5-
ENV APP_PORT=9091
6-
ENV MODEL_DIR=/model
31+
COPY poetry.lock pyproject.toml ./
32+
RUN poetry install --no-interaction
733

8-
ENV POETRY_HOME="/opt/poetry"
9-
ENV VENV_PATH="/opt/pysetup/.venv"
10-
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
1134

12-
VOLUME /model
13-
LABEL DEPLOYMENT_TYPE=APP
35+
FROM base as runtime
1436

15-
RUN apt-get update && \
16-
apt-get -y install wget curl sudo
37+
RUN useradd -u 42069 --create-home --shell /bin/bash app
1738

18-
RUN wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
19-
chmod +x /bin/grpc_health_probe
20-
RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
39+
WORKDIR /home/app
2140

41+
ENV APP_PORT=9091
42+
EXPOSE ${APP_PORT}
2243
HEALTHCHECK --start-period=10s CMD /bin/grpc_health_probe -addr=:${APP_PORT}
2344

24-
WORKDIR /app
25-
26-
COPY poetry.lock pyproject.toml ./
27-
RUN poetry config virtualenvs.create false
28-
RUN poetry install --no-interaction
29-
30-
COPY . /app/
45+
COPY --from=build --chown=app:app /bin/grpc_health_probe /bin/grpc_health_probe
46+
COPY --from=build --chown=app:app $VENV_PATH $VENV_PATH
3147

32-
RUN chmod +x /app/src/main.py
33-
RUN sync
48+
COPY --chown=app:app src/ /home/app/src/
49+
COPY --chown=app:app start.sh start.sh
3450

35-
RUN useradd -u 42069 app && \
36-
mkdir /home/app && \
37-
chown app /home/app && \
38-
chown app /app && \
39-
chmod +x /app/start.sh
51+
RUN chmod +x /home/app/src/main.py && \
52+
sync && \
53+
chmod +x /home/app/start.sh
4054

4155
RUN echo "app ALL=NOPASSWD: /usr/bin/apt" > /etc/sudoers
4256
USER app
4357

44-
CMD ["/app/start.sh"]
58+
ENTRYPOINT ["bash", "/home/app/start.sh"]

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ PYTHON_EXEC=python
22
VERSION=dev
33

44
.PHONY: python-all
5-
python-all: python-3.7 python-3.8
6-
7-
.PHONY: python
8-
python: python-latest
5+
python-all: python-3.7 python-3.8.11
96

107
.PHONY: python-%
118
python-%:

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
Python runtime for [Hydrosphere Serving](https://github.com/Hydrospheredata/hydro-serving).
33
Provides a GRPC API for Python scripts.
44

5-
Supported versions are: python-3.6 python-3.7 python-3.8
5+
Supported versions are: python-3.7 python-3.8
66

77
## Build commands
88
- `make test`
9-
- `make python` - build docker runtime with python:latest-alpine base image
109
- `make python-${VERSION}` - build docker runtime with python:${VERSION}-alpine base image
1110
- `make clean` - clean repository from temp files
1211

start.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22

3-
cd /app/src
4-
PYTHONPATH=/app:/app/src/ python3 main.py
3+
cd /home/app/src
4+
PYTHONPATH=/home/app:/home/app/src/ python3 main.py

0 commit comments

Comments
 (0)