๋๋ ๊ทธ๊ฒ์ ๊ณ ๋ คํ ๊ฒ์ด์ง๋ง, ์ด๊ฒ์ ํ์ฌ ๋งค์ฐ ๋ฎ์ ์ฐ์ ์์(ํญ์ ๋ฐ๋ ์ ์์)๋ผ๊ณ ์๊ฐํฉ๋๋ค.
๋์ค์ ์ฐธ์กฐํ ์ ์๋๋ก ์ฝ๋ ํจํค์ง/๋ฐฐํฌ์ ๋ํ Python ๋ฌธ์:
PR์ ๋ํ ์๊ฒฌ์ ๋ณด๋ด ์ฃผ์ @pcmoore ์๊ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ๋๋ ํ์ด์ฌ ๋ฐ์ธ๋ฉ ํจํค์ง์ ๋์์ด ๋๊ธฐ๋ฅผ ๋ฐ๋๊ณ ์ด์ ๋ฐค์ ๊ทธ๊ฒ์ ์กฐ์ฌํ๊ธฐ ์์ํ์ต๋๋ค.
๋น ๋ฅธ ์์ ์ค ์ผ๋ถ๋ MANIFEST.in์ ์ถ๊ฐํ๊ณ setup.py ํ์ผ์ ์
๋ฐ์ดํธํ๋ ๊ฒ์ด์์ต๋๋ค. pip install
์ ํจ๊ป ์๋ํ๋๋ก ์
๋ฐ์ดํธ๋ setup.py๋ฅผ ์ป์ ์ ์์์ง๋ง ๊ฐ๋ฐ ๋ฒ์ ๊ณผ ์ค์ ๋ก ์์
ํ๋ ค๋ฉด ๋ ๋ง์ ์์
์ด ํ์ํฉ๋๋ค(์์ง #217์ ์คํจ๋ฅผ ์ดํด๋ณด์ง๋ ์์์ง๋ง ๊ณง ).
IMO, ๋ ๋์ ๊ฐ๋ฐ/ํ ์คํธ/๋ฆด๋ฆฌ์ค ์ํฌํ๋ก๋ฅผ ์ํด Python ๋ฐ์ธ๋ฉ์ ๋ณ๋์ ๋ฆฌํฌ์งํ ๋ฆฌ๋ก ๋ถํ ํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ์ ๋ Python ํ๋ก์ ํธ์์ ์ผํ์ง๋ง Cythonized ํ๋ก์ ํธ์์๋ ๊ทธ๋ค์ง ๋ง์ด ์์ ํ์ง ์์์ง๋ง ์ ๊ฐ ํ ์ ์๋ ๋ชจ๋ ์ญ๋์์ ๋์์ ๋๋ฆด ์ ์์ด ๊ธฐ์ฉ๋๋ค.
์ ๋ #61์ ์์ ํ ํ ๋ฌธ์๋ฅผ ์ค์ ํ๋ ๋ฐ ๋์์ ์ฃผ๊ณ ์ถ์์ต๋๋ค(์ด๋ฅผ ์ ์ ์ฅ์๋ก ์ฎ๊ธฐ๋ฉด ์๋ง๋ ๋จ์ํ๋ ๊ฒ์
๋๋ค. ํ์ง๋ง sphinx
Python ๋ฌธ์ ๋๊ตฌ๊ฐ cython ํ์ผ์ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ์ ์ ์์).
๋ฌธ์ #216์ @pcmoore ์๊ฒฌ์์:
๊ธฐ๋ณธ์ ์ผ๋ก ๊ธฐ๋ณธ libseccomp ์์ค ๋ฐฐํฌ์ ์ผ๋ถ๋ก Python ๋ฐ์ธ๋ฉ์ ๊ณ์ ์ง์ํ ๊ฒ์ธ์ง ์๋๋ฉด golang ๋ฐ์ธ๋ฉ์ ๋ํด ์ํํ๋ ๊ฒ์ฒ๋ผ ๋ถํ ํ ๊ฒ์ธ์ง ๊ฒฐ์ ํด์ผ ํฉ๋๋ค.
์ ๋ ํ์ด์ฌ ๋ฐ์ธ๋ฉ์ ๋ฉ์ธ libseccomp ํจํค์ง์์ ๋ถ๋ฆฌํ๋ ์์ด๋์ด๊ฐ ๋ง์์ ๋ค๊ณ , ์ ์๊ฒ๋ ์ด๊ฒ์ด ์ฐ์ ์์๊ฐ ์๋นํ ๋ฎ๋ค๋ ๋ฐ์๋ ๋์ํฉ๋๋ค. ๋ค๋ฅธ ์ฌ๋์ด ์์ ์ ์ ํํ๋ ๋ฐ ๊ด์ฌ์ด ์๋ค๋ฉด ๊ธฐ๊บผ์ด ๊ฒํ ํ๋ ๋ฐ ๋์์ ๋๋ฆฌ๊ฒ ์ต๋๋ค. :)
BTW ํ์ด์ฌ ๋ฐ์ธ๋ฉ์ด ๋ณ๋์ ์ ์ฅ์์ ์์ด์ผ ํ๋ค๋ ๋ฐ ๋์ํฉ๋๋ค. ๋น๋ก ์์๋ด์ฌ๋ ์๋์ง๋ง. :^)
seccomp ์กฐ์ง ์๋์ ์ ๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ ์์ฑํ ์ ์๋ ๊ถํ์ด ์๋ ์ฌ๋์ด ์ด๋ฅผ ์ค์ ํ ์ ์์ผ๋ฉด ๋ฆฌํฌ์งํ ๋ฆฌ์์ Python ๋ฐ์ธ๋ฉ์ ๊ฐ์ ธ์์ PR์ ์์ฑํ ์ ์์ต๋๋ค.
๋ด๊ฐ ์์ํ๋ ๋ช ๊ฐ์ง ๋ณ๊ฒฝ ์ฌํญ์ด ์์ต๋๋ค.
setup.py build
์ด๋ฉด ์ถฉ๋ถํฉ๋๋ค.setup.py
ํ๋์ฝ๋ฉ๋๊ฑฐ๋ ํ์ํ ๊ฒฝ์ฐ git ํ๊ทธ์์ ๋์ ์ ํํ ์ ์์ต๋๋ค(setuptools-scm ํจํค์ง ์ฌ์ฉ).pytest
๋๋ nose2
์คํ์ผ ํ
์คํธ ํ๋ ์์ํฌ๋ฅผ ํตํด ๋ค์ดํฐ๋ธ ํ์ด์ฌ ํ
์คํธ๋ฅผ ์ฌ์ฉํ๋๋ก ์ด์ํ๋ ์ข์ ๋ฐฉ๋ฒ์ด ์๋์ง ์์๋ณด๊ธฐ ์ํด ํ
์คํธ ํ๋ค์ค๋ฅผ ๋๋ฌด ๋ง์ด ์ดํด๋ณด์ง ์์์ต๋๋ค.
๋ง์ง๋ง์ผ๋ก ์์ค ๋ฐ ๋ฐ์ด๋๋ฆฌ ๋ฐฐํฌํ ๋ชจ๋์ ๋ฐฐํฌ ํจํค์ง๋ฅผ ๋น๋ํ๊ธฐ ์ํ ๋ช ๊ฐ์ง ์ถ๊ฐ ๋ฌธ์์ ๋๋ค.
์ ๋ ์ด๊ฒ์ v2.6์ ๋ํด ์ ์ ์ ์ผ๋ก ํ์ํ ๊ฒ์ ๋๋ค. ์ด๋ "v2.5๊ฐ ์ถ์๋ ํ ์ธ์ ๊ฐ"๋ฅผ ์๋ฏธํฉ๋๋ค. v2.5๋ฅผ ์๋ฃํ๋ ๊ฒ์ด ์ง๊ธ ์ฐ๋ฆฌ์ ์ฐ์ ์์์ ๋๋ค. ๋์ค์ ์ด ๋ฌธ์ ๋ฅผ ๋ค์ ๋ ผ์ํ ์ ์์ต๋๋ค.
libseccomp pip-installable์ ๋ง๋๋ ๊ฒ์ ์ ์๊ฒ๋ ๋งค์ฐ ๋์์ด ๋ ๊ฒ์ ๋๋ค. ์ฌ๊ธฐ์ ๋ค๋ฅธ ์ฌ๋์ด ์์๋ด๋ ค๊ณ ํ๋ ๊ฒฝ์ฐ make/poetry/docker(๋ฐ setup.py ํจ์น)๋ฅผ ์ฌ์ฉํ๋ ์๋ง์ถ์ด ์์ ์ด ์์ต๋๋ค. ๋ํ sudo๊ฐ ํ์ํ์ง ์๋๋ก ๋น๋ ๋งค๊ฐ๋ณ์๋ฅผ ์กฐ์ /์ค์ ํ์ต๋๋ค.
build-seccomp/setup.py ( /src/python/setup.py
์ฝ๊ฐ ์์ ๋จ):
# OLD IMPORTS
# -----------------------------------------
# import os
#
# from distutils.core import setup
# from distutils.extension import Extension
# from Cython.Distutils import build_ext
# -----------------------------------------
# Replace with these NEW IMPORTS
# -----------------------------------------
import os
from setuptools import setup, Extension
from Cython.Distutils import build_ext
# -----------------------------------------
# rest of the file unmodified...
๋ฉ์ดํฌํ์ผ :
.ONESHELL: install-libseccomp-native install-libseccomp-deps install-libseccomp build-whl-libseccomp
SECCOMP_BUILD_ENV = VERSION_RELEASE="0.0.0" \
CPPFLAGS="-I ../../include " \
CFLAGS="-Wall -g -O2" \
LDFLAGS="-Wl,-z -Wl,relro "
WHEEL_DIR = $(CURDIR)/dist
install-libseccomp-native:
ifeq (,$(wildcard libseccomp/.)) # If already cloned/built ignore
git clone https://github.com/seccomp/libseccomp.git --branch v2.4.3 --depth 1
cp build-seccomp/setup.py libseccomp/src/python/setup.py
cd libseccomp
./autogen.sh
./configure --prefix=$(CURDIR)/libseccomp/build-aux
make install
endif
install-deps:
poetry install --no-root
# `make install-libseccomp` will install seccomp library into poetry virtual environment.
# this is a good option for local development
install-libseccomp: install-libseccomp-native install-deps
cd libseccomp/src/python
export $(SECCOMP_BUILD_ENV)
poetry run python setup.py install
# `make build-whl-libseccomp` will create a .whl file for the seccomp library
# this is a good option for generating a build artifact in CI/CD or Docker
build-whl-libseccomp: install-libseccomp-native install-deps
cd libseccomp/src/python
export $(SECCOMP_BUILD_ENV)
poetry run python setup.py bdist_wheel --dist-dir=$(WHEEL_DIR)
build-docker:
docker build -t libseccomp-python .
run-docker:
docker run --env SOME_VAR_1=42 --env SOME_VAR_2="Hello, World!" libseccomp-python
Dockerfile (๋ด ์ ํ๋ฆฌ์ผ์ด์ ์ ๋๋ฑํ์ง๋ง ๋
# ============= BUILD STAGE ============= #
FROM python:3.8.3-buster as builder
# Install poetry
RUN pip install "poetry==1.0.5"
# Build/install wheels
WORKDIR /app
COPY pyproject.toml poetry.lock Makefile ./
COPY build-seccomp ./build-seccomp
RUN make build-whl-libseccomp
# ========== FINAL IMAGE STAGE ========== #
FROM python:3.8.3-slim-buster
# Install application
COPY --from=builder /app/dist /app/dist
WORKDIR /app
RUN pip install --no-index --find-links dist seccomp
COPY app ./app
# Configure
ENV SOME_VAR_1=
ENV SOME_VAR_2=
# Run the application
CMD ["python", "app/main.py"]
pyproject.toml :
[tool.poetry]
name = "libseccomp-demo"
version = "0.1.0"
description = "Building libseccomp for Python projects."
authors = ["Han Solo"]
[tool.poetry.dependencies]
python = "^3.8"
[tool.poetry.dev-dependencies]
cython = "^0.29.19"
wheel = "^0.34.2"
[build-system]
requires = ["poetry==1.0.5"]
build-backend = "poetry.masonry.api"
์ฑ/๋ฉ์ธ.py :
import os
import seccomp
print(os.environ['SOME_VAR_1'])
print(os.environ['SOME_VAR_2'])
๋๋ ๋จ์ง ์ด๊ฒ์ ๋ํ ๋ชจ๋ ๋์์ ๋ํด "๊ฐ์ฌํฉ๋๋ค"๋ฅผ ๊ณต์ ํ๊ณ ์ถ์์ต๋๋ค. @drakenclimber ์ ์ ๋ v2.5.0 ๋ฆด๋ฆฌ์ค๋ฅผ ์๋ฃํ๊ธฐ ์ํด ์ฌ์ ํ ๋ฐ์๊ธฐ ๋๋ฌธ์ ์๋ฃ๋ ๋๊น์ง ๋ง์ ๊ด์ฌ์ ๋ฐ์ง ๋ชปํ ์๋ ์์ง๋ง, ์ด ์ ์ ์์ง ์๊ณ ์๋ค๊ณ ์ฝ์๋๋ฆด ์ ์์ต๋๋ค. :)