Skip to content

Commit

Permalink
split out Dockerfiles
Browse files Browse the repository at this point in the history
change up locking too
  • Loading branch information
amancevice committed Sep 21, 2023
1 parent 5d9de89 commit f6d31eb
Show file tree
Hide file tree
Showing 11 changed files with 507 additions and 472 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*
!Pipfile*
!requirements*.txt
29 changes: 14 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ on:
pull_request:
push:
paths:
- Dockerfile
- Dockerfile*
- Pipfile.lock
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install -g dockerlint
- run: dockerlint
build:
runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
target:
- alpine
- jupyter
- latest
- slim
file:
- Dockerfile
- Dockerfile.alpine
- Dockerfile.jupyter
- Dockerfile.slim
steps:
- uses: actions/checkout@v3
- run: make ${{ matrix.target }}
- uses: actions/setup-node@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: npm install -g dockerlint
- run: dockerlint -f ${{ matrix.file }}
- run: pip install pipenv
- run: make ${{ matrix.file }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**/.docker/
requirements*.txt
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.5
39 changes: 3 additions & 36 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,5 @@
ARG PYTHON_VERSION=3.11

FROM python:$PYTHON_VERSION AS lock
FROM python:$PYTHON_VERSION
WORKDIR /var/lib/pandas/
RUN pip install pipenv==2023.8.28
RUN pipenv --python $PYTHON_VERSION
COPY Pipfile* ./
RUN pipenv lock
RUN pipenv requirements > requirements.txt
RUN pipenv requirements --dev-only > requirements-dev.txt

FROM python:$PYTHON_VERSION AS latest
WORKDIR /var/lib/pandas/
COPY --from=lock /var/lib/pandas/ .
RUN pip install $(grep -Eoh 'numpy==[0-9.]+' requirements.txt) && \
pip install -r requirements.txt

FROM python:$PYTHON_VERSION AS jupyter
WORKDIR /var/lib/pandas/
COPY --from=lock /var/lib/pandas/ .
RUN pip install $(grep -Eoh 'numpy==[0-9.]+' requirements.txt) && \
pip install -r requirements.txt -r requirements-dev.txt

FROM python:$PYTHON_VERSION-slim AS slim
WORKDIR /var/lib/pandas/
COPY --from=lock /var/lib/pandas/ .
RUN pip install $(grep -Eoh 'numpy==[0-9.]+' requirements.txt) && \
pip install -r requirements.txt

FROM python:$PYTHON_VERSION-alpine as alpine
WORKDIR /var/lib/pandas/
COPY --from=lock /var/lib/pandas/ .
RUN apk add --no-cache libstdc++ && \
apk add --no-cache --virtual .build-deps g++ && \
ln -s /usr/include/locale.h /usr/include/xlocale.h && \
pip install $(grep -Eoh 'numpy==[0-9.]+' requirements.txt) && \
pip install -r requirements.txt && \
apk del .build-deps
COPY . .
RUN pip install -r requirements.txt
9 changes: 9 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ARG PYTHON_VERSION=3.11
FROM python:$PYTHON_VERSION-alpine
WORKDIR /var/lib/pandas/
COPY . .
RUN apk add --no-cache libstdc++ && \
apk add --no-cache --virtual .build-deps g++ && \
ln -s /usr/include/locale.h /usr/include/xlocale.h && \
pip install -r requirements.txt && \
apk del .build-deps
5 changes: 5 additions & 0 deletions Dockerfile.jupyter
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG PYTHON_VERSION=3.11
FROM python:$PYTHON_VERSION
WORKDIR /var/lib/pandas/
COPY . .
RUN pip install -r requirements.txt -r requirements-dev.txt
5 changes: 5 additions & 0 deletions Dockerfile.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG PYTHON_VERSION=3.11
FROM python:$PYTHON_VERSION-slim
WORKDIR /var/lib/pandas/
COPY . .
RUN pip install -r requirements.txt
42 changes: 27 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
REPO := amancevice/pandas
PANDAS_VERSION := $(shell grep pandas Pipfile | grep -o '[0-9.]\+')
PANDAS_VERSION := $(shell grep pandas Pipfile | grep -Eo '[0-9.]+')
PIPENV_VERSION := $(shell pipenv --version | grep -Eo '[0-9.]+')
PYTHON_VERSION := $(shell python --version | grep -Eo '[0-9.]+')

all: Pipfile.lock

clean:
docker image ls --quiet $(REPO) | uniq | xargs docker image rm --force
docker image rm --force $(shell docker image ls --quiet $(REPO) | uniq | xargs)

alpine slim jupyter: lock
docker build --tag $(REPO):$@ --tag $(REPO):$(PANDAS_VERSION)-$@ --target $@ .
push:
docker push --all-tags $(REPO)

latest:
docker build --tag $(REPO):$@ --tag $(REPO):$(PANDAS_VERSION) --target $@ .
Dockerfile: requirements.txt
docker build --build-arg PYTHON_VERSION=$(PYTHON_VERSION) --tag $(REPO) --tag $(REPO):$(PANDAS_VERSION) .

lock: Pipfile.lock
Dockerfile.%: requirements.txt requirements-dev.txt
docker build --build-arg PYTHON_VERSION=$(PYTHON_VERSION) --file $@ --tag $(REPO):$* --tag $(REPO):$(PANDAS_VERSION)-$* .

ls:
docker image ls $(REPO)
.PHONY: all clean push Dockerfile Dockerfile.%

push:
docker push --all-tags $(REPO)
requirements.txt:
pipenv requirements > requirements.txt

requirements-dev.txt:
pipenv requirements --dev > requirements-dev.txt

.PHONY: all clean push alpine slim jupyter latest lock ls push
Pipfile.lock: .venv
docker container run --detach --rm --name pandas python:3.11.5 python -m http.server
docker container exec --tty pandas pip install pipenv==$(PIPENV_VERSION) &> /dev/null
docker container cp Pipfile* pandas:/tmp/
docker container exec --tty --workdir /tmp/ pandas pipenv lock
docker container cp pandas:/tmp/Pipfile.lock .
docker container stop pandas

Pipfile.lock: Pipfile
docker build --tag $(REPO):lock --target lock .
docker run --rm --entrypoint cat $(REPO):lock $@ > $@
.venv: Pipfile
mkdir -p $@
pipenv --python $(PYTHON_VERSION)
touch $@
5 changes: 4 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ jupyterlab = "*"
matplotlib = "*"

[packages]
pandas = "==2.1.0"
pandas = "==2.1.1"

[requires]
python_version = "3.11"
Loading

0 comments on commit f6d31eb

Please sign in to comment.