1
0
mirror of https://github.com/enpaul/kodak.git synced 2024-11-14 10:36:55 +00:00

Add dockerfile and build integration to makefile

This commit is contained in:
Ethan Paul 2021-11-23 19:37:03 -05:00
parent fe0811d525
commit ade6929dc3
No known key found for this signature in database
GPG Key ID: D0E2CBF1245E92BF
2 changed files with 85 additions and 2 deletions

77
Dockerfile Normal file
View File

@ -0,0 +1,77 @@
FROM python:3.9 as build
RUN python -m pip install pip==19.3.1
ADD https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py /get-poetry.py
ENV POETRY_HOME /pypoetry
RUN python /get-poetry.py \
--yes \
--force
ADD . /source
WORKDIR /source
RUN $POETRY_HOME/bin/poetry export \
--format requirements.txt \
--output /requirements.txt \
--without-hashes \
--extras deployment
RUN python -m pip wheel \
--wheel-dir /wheels \
--requirement /requirements.txt \
--disable-pip-version-check \
--no-cache-dir
RUN mv /source/openapi.yaml /source/kodak/openapi.yaml
RUN $POETRY_HOME/bin/poetry build \
--format wheel
RUN mv /source/dist/*.whl /wheels
FROM python:3.9-slim as runtime
RUN apt update --yes && \
apt install --yes \
libjpeg-dev \
zlib1g \
liblcms2-2 && \
apt clean all --yes && \
python -m pip install pip==19.3.1 && \
useradd kodak \
--no-create-home \
--no-log-init \
--system \
--user-group && \
mkdir --parents /kodak/pictures && \
mkdir --parents /kodak/content && \
chown --recursive kodak:kodak /kodak && \
chmod 0775 /kodak /kodak/content
COPY --from=build /wheels /wheels
RUN python -m pip install kodak[deployment] \
--upgrade \
--pre \
--no-index \
--no-cache-dir \
--find-links /wheels \
--disable-pip-version-check && \
rm --recursive --force /wheels
ENV KODAK_SOURCE_DIR /pictures
ENV KODAK_CONTENT_DIR /kodak/content
ENV KODAK_DATABASE_SQLITE_PATH /kodak/kodak.db
VOLUME /kodak
VOLUME /pictures
USER kodak
CMD [ \
"python", \
"-m", \
"gunicorn", \
"kodak.application:APPLICATION", \
"--bind=0.0.0.0:8080", \
"--workers=8", \
"--log-level=info", \
"--access-logfile=-" \
]

View File

@ -1,7 +1,7 @@
# kodak makefile
# You can set these variables from the command line
PROJECT = kodak
VERSION = $(shell poetry version --short)
.PHONY: help
# Put it first so that "make" without argument is like "make help"
@ -36,10 +36,16 @@ wheel: prep ## Build Python binary distribution wheel package
source: prep ## Build Python source distribution package
poetry build --format sdist
image: prep
docker build . --tag $(PROJECT):$(VERSION)
docker image save $(PROJECT):$(VERSION) --output dist/$(PROJECT)-$(VERSION)-docker.tar.gz
build: clean wheel source image; ## Build all distribution packages
test: clean-tox prep ## Run the project testsuite(s)
poetry run tox
publish: clean test wheel source ## Build and upload to pypi (requires $PYPI_API_KEY be set)
publish: clean test build ## Build and upload to pypi (requires $PYPI_API_KEY be set)
@poetry publish --username __token__ --password $(PYPI_API_KEY)
dev: ## Create local dev environment