Skip to content

Commit

Permalink
feat: use ceph container for building container, also add more info t…
Browse files Browse the repository at this point in the history
…o pyproject.toml, adapt Makefile and remove unnecessary methods and also add more clear tag

Signed-off-by: R.A. te Boekhorst <[email protected]>
  • Loading branch information
boekhorstb1 committed Mar 13, 2024
1 parent 248d6b5 commit b28c22e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ cython_debug/
# Project specific
data.yaml
config.yaml
.ceph
.ceph
27 changes: 8 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,18 @@ RUN python -m build /app/rookify/


# Base
FROM debian:stable-slim as base
From quay.io/ceph/ceph:v17.2.7 as base

COPY requirements.txt /app/rookify/src/

# Install Librados:
# Get rados version from requirements.txt and install it using apt,
# because librados does not exist as pip package
RUN apt-get update && apt-get install -y python3-pip python3-rados python3-venv && \
# Save the path to PKG-INFO file to a variable
PKG_INFO_PATH=$(dpkg -L python3-rados | grep -E '/rados-[0-9.]+\.egg-info/PKG-INFO') && \
# Extract the installed version from the PKG-INFO file
INSTALLED_VERSION=$(grep -oP '(?<=Version: )\d+\.\d+\.\d+' "$PKG_INFO_PATH") && \
# Extract the required version from the requirements.txt file
REQUIRED_VERSION=$(grep -oP '(?<=rados==)\d+\.\d+\.\d+' /app/rookify/src/requirements.txt) && \
# Check if the installed version matches the required version, if not than give a warning and exit process
if [ "$INSTALLED_VERSION" != "$REQUIRED_VERSION" ]; then \
echo "WARNING: Installed version of rados Python package ($INSTALLED_VERSION) does not match required version ($REQUIRED_VERSION)." >&2; \
exit 1; \
fi

# Install package with requirements including systempackages and simlinks (rados) into a venv
RUN python3 -m venv --system-site-packages --symlinks /app/rookify/ && \
/app/rookify/bin/pip install -r /app/rookify/src/requirements.txt
RUN cat /etc/os-release && dnf install -y python39-pip python3-virtualenv

# Install package with requirements including systempackages with simlinks
RUN /usr/bin/python3.9 -m venv --system-site-packages /app/rookify/.venv && \
/app/rookify/.venv/bin/pip3.9 install --ignore-installed -r /app/rookify/src/requirements.txt

# Rookify
FROM base AS rookify
Expand All @@ -44,10 +33,10 @@ ARG ROOKIFY_VERSION=0.0.1
WORKDIR /app/rookify

COPY --from=builder /app/rookify/dist/Rookify-${ROOKIFY_VERSION}-py3-none-any.whl ./src/
RUN ./bin/pip install ./src/Rookify-${ROOKIFY_VERSION}-py3-none-any.whl
RUN .venv/bin/pip3.9 install ./src/Rookify-${ROOKIFY_VERSION}-py3-none-any.whl

# This is for debugging and will not be used when ENTRYPOINT is set
CMD ["sleep", "infinity"]

# Set the ENTRYPOINT to activate the venv and then run the 'rookify' command
ENTRYPOINT ["/bin/bash", "-c", "source ./bin/activate && exec python -m rookify"]
ENTRYPOINT ["/app/rookify/bin/rookify"]
15 changes: 3 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ help: ## Display this help message
.PHONY: setup
setup: ## Setting up the docker-compose environment
${MAKE} setup-venv

setup-venv:
python -m venv ./.venv
source ./.venv/bin/activate
Expand All @@ -41,15 +41,6 @@ setup-venv:
pip install -r requirements.txt

.PHONY: build-container
TAG ?= 0.0.1
ROOKIFY_VERSION ?= 0.0.1
build-container: ## Build container from Dockerfile, add e.g. TAG=0.0.0.1 to specify the version. Default value is 0.0.0-dev
${CONTAINERCMD} build --build-arg ROOKIFY_VERSION=$(TAG) -t rookify:latest -f Dockerfile .

.PHONY: run-rookify-from-container
run-rookify-from-container: ## Run rookify from the container (Note: the ceph volume needs to be set correctly)
${CONTAINERCMD} run -v ./src/config.yaml:/app/rookify/config.yaml:Z -v ./.ceph:/.ceph:Z rookify:latest

.PHONY: run-interactive-container
run-interactive-container: ## Run an insteractive container (make sure that Dockerfile has the DEBBUGING sleep command set at the end)
${CONTAINERCMD} run -it rookify:latest bash

${CONTAINERCMD} build --build-arg ROOKIFY_VERSION=$(ROOKIFY_VERSION) -t rookify:latest -f Dockerfile .
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ requires = [ "setuptools", "wheel" ]
build-backend = "setuptools.build_meta"

[project]
name = "Rookify"
version = "0.0.1"
requires-python = ">=3.9"
readme = "README.md"
description = "Migration tool"
license.file = "LICENSE"
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pycparser==2.21
PyNaCl==1.5.0
python-dateutil==2.8.2
PyYAML==6.0.1
rados==2.0.0
requests==2.31.0
requests-oauthlib==1.3.1
rsa==4.9
Expand Down

0 comments on commit b28c22e

Please sign in to comment.