Skip to content

Commit 6396956

Browse files
taotegwesleyboar
andauthored
Task/fp 1461 convert core cms to poetry (#468)
* Initialized poetry 1.1.13 in the existing cms codebase to generate the pyproject.tml file with no added dependencies or dev-dependencies. * Completed changes to Makefile to align with usage in Portal. AFter poetry transition gets meged, Jenkins will need to be modified to call the new build-full target in the CMS codebase. * Added the requirements.txt dependencies manually to the pyproject.toml file to test installation against Dockerfile. Edits to Dockerfile are next. * Changed the name of the pyproject.toml to be more specific. * Added poetry setup and build steps to the Dockerfile. Builds and runs succesfully using both the build and build-full make commands. * Update Dockerfile Great catch! Co-authored-by: W. Bomar <62723358+tacc-wbomar@users.noreply.github.com> * Update pyproject.toml Removing unused dev dependencies. Co-authored-by: W. Bomar <62723358+tacc-wbomar@users.noreply.github.com>
1 parent 088cb03 commit 6396956

File tree

5 files changed

+2303
-116
lines changed

5 files changed

+2303
-116
lines changed

Dockerfile

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,61 @@ ARG DEBIAN_FRONTEND=noninteractive
66

77
ENV PYTHONUNBUFFERED 1
88

9+
# https://python-poetry.org/docs/configuration/#using-environment-variables
10+
ENV POETRY_VERSION=1.1.0 \
11+
POETRY_HOME="/opt/poetry" \
12+
POETRY_VIRTUALENVS_IN_PROJECT=true \
13+
POETRY_NO_INTERACTION=1 \
14+
PYSETUP_PATH="/opt/pysetup" \
15+
VENV_PATH="/opt/pysetup/.venv"
16+
17+
# prepend poetry and venv to path
18+
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
19+
20+
FROM python-base as builder-base
21+
922
RUN apt-get update && apt-get install -y \
1023
build-essential python3-dev \
1124
libldap2-dev libsasl2-dev ldap-utils tox \
1225
lcov valgrind vim \
1326
&& pip3 install uwsgi
1427

28+
RUN pip3 install --upgrade pip setuptools wheel
29+
30+
# Install Poetry - respects $POETRY_VERSION & $POETRY_HOME
31+
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3
32+
33+
# copy project requirement files here to ensure they will be cached.
34+
WORKDIR $PYSETUP_PATH
35+
COPY pyproject.toml poetry.lock ./
36+
37+
# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
38+
RUN poetry install --no-dev
39+
40+
# `development` image is used for local development
41+
FROM python-base as development
42+
WORKDIR $PYSETUP_PATH
43+
44+
# copy in our built poetry + venv
45+
COPY --from=builder-base $POETRY_HOME $POETRY_HOME
46+
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
47+
48+
# quicker install as runtime deps are already installed
49+
RUN poetry install
50+
51+
# `production` image is used for deployed runtime environments
52+
FROM python-base as production
53+
1554
# install node 12.x
1655
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
1756
RUN apt-get install -y nodejs
1857

58+
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
59+
1960
# load files
2061
RUN mkdir /code
2162
COPY . /code
2263
WORKDIR /code
2364

24-
# install python packages
25-
RUN pip3 install --no-cache-dir -r requirements.txt
26-
2765
# build assets
2866
RUN npm ci && npm run build

Makefile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,32 @@ DOCKERHUB_REPO := taccwma/$(shell cat ./docker_repo.var)
22
DOCKER_TAG ?= $(shell git rev-parse --short HEAD)
33
DOCKER_IMAGE := $(DOCKERHUB_REPO):$(DOCKER_TAG)
44
DOCKER_IMAGE_LATEST := $(DOCKERHUB_REPO):latest
5-
DOCKER_IMAGE_LOCAL := $(DOCKERHUB_REPO):local
65

76
.PHONY: build
87
build:
9-
docker build -t $(DOCKER_IMAGE) .
10-
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE_LATEST)
8+
docker-compose -f ./docker-compose.yml build
9+
10+
.PHONY: build-full
11+
build-full:
12+
docker build -t $(DOCKER_IMAGE) --target production -f ./Dockerfile .
1113

1214
.PHONY: publish
1315
publish:
1416
docker push $(DOCKER_IMAGE)
1517

1618
.PHONY: publish-latest
1719
publish-latest:
20+
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE_LATEST)
1821
docker push $(DOCKER_IMAGE_LATEST)
1922

2023
.PHONY: start
2124
start:
2225
docker-compose -f docker-compose.yml up
2326

24-
requirements-frozen.txt: build
25-
docker run --rm $(DOCKER_IMAGE) pip freeze > $@
27+
.PHONY: stop
28+
stop:
29+
docker-compose -f docker-compose.yml down
30+
31+
.PHONY: stop-verbose
32+
stop-v:
33+
docker-compose -f docker-compose.yml down -v

0 commit comments

Comments
 (0)