Skip to content

Commit

Permalink
Added distroless build
Browse files Browse the repository at this point in the history
  • Loading branch information
garethr committed Dec 14, 2019
1 parent 4f518d8 commit ff03fbe
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
19 changes: 18 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ RUN conftest test --namespace docker Dockerfile
RUN conftest test snyky.yaml


FROM ${IMAGE} AS build-env
COPY Pipfile .
COPY Pipfile.lock .
RUN pip install pipenv && pipenv install --system --deploy


FROM gcr.io/distroless/python3 as Distroless
WORKDIR src /app
COPY --from=build-env /usr/local/lib/python3.7/site-packages /site-packages
COPY src/ .
ENV PYTHONPATH=/site-packages
CMD ["run.py", "app:app"]


FROM base AS Shell
CMD ["flask", "shell"]

Expand All @@ -79,4 +93,7 @@ ENV FLASK_ENV=development


FROM release AS Prod
CMD gunicorn --capture-output --access-logfile=- --log-file=- --workers=2 --threads=4 --worker-class=gthread --worker-tmp-dir /dev/shm -b :${PORT} "app:app"
CMD ["gunicorn", "app:app"]



11 changes: 10 additions & 1 deletion Makefile.docker
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ endif
build: check-buildkit
@$(BUILD) -t $(IMAGE) .

slim: check-buildkit
@$(BUILD) --build-arg IMAGE=python:slim -t $(IMAGE):slim .

alpine: check-buildkit
@$(BUILD) --build-arg DISTRO=alpine --build-arg IMAGE=python:3.7-alpine3.8 -t $(IMAGE):alpine .

distroless: check-buildkit
@$(BUILD) --target Distroless -t $(IMAGE):distroless .

test: check-buildkit
@$(BUILD) --target Test .

Expand All @@ -27,4 +36,4 @@ snyk: check-buildkit check-snyk-token
policy:
@$(BUILD) --target Policy .

.PHONY: build test snyk policy
.PHONY: build slim alpine distroless test snyk policy
11 changes: 11 additions & 0 deletions src/gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import structlog
import log_helper

Expand Down Expand Up @@ -36,3 +37,13 @@
},
},
}

capture_output = True
access_logfile = "-"
log_file = "-"
workers = 2
threads = 4
worker_class = "gthread"
woker_tmp_dir = "/dev/shm"
port = os.getenv('PORT') or 8000
bind = ":%s" % port
5 changes: 5 additions & 0 deletions src/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python
import sys
from gunicorn.app.wsgiapp import run
if __name__ == '__main__':
sys.exit(run())

0 comments on commit ff03fbe

Please sign in to comment.