Skip to content

Commit

Permalink
✨ ooil executable in a docker image (#3458)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored Oct 25, 2022
1 parent 97a99c0 commit 86b0800
Show file tree
Hide file tree
Showing 15 changed files with 360 additions and 70 deletions.
169 changes: 169 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,172 @@ dask*-space/

# mypy cache
**/.mypy_cache/


#------------------------------------------------------------------------------
# ignore python artifacts
#
# https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore
#
#------------------------------------------------------------------------------

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
3 changes: 2 additions & 1 deletion .github/workflows/ci-testing-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,8 @@ jobs:
name: docker-buildx-images-${{ runner.os }}-${{ github.sha }}
path: /${{ runner.temp }}/build
- name: load docker images
run: make load-images local-src=/${{ runner.temp }}/build
run: |
make load-images local-src=/${{ runner.temp }}/build
- name: set owner variable
run: echo "OWNER=${GITHUB_REPOSITORY%/*}" >> $GITHUB_ENV
- if: github.ref == 'refs/heads/master'
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CLIENT_WEB_OUTPUT := $(CURDIR)/services/static-webserver/client/source-out

# version control
export VCS_URL := $(shell git config --get remote.origin.url)
export VCS_REF := $(shell git rev-parse --short HEAD)
export VCS_REF := $(shell git rev-parse HEAD)
export VCS_REF_CLIENT := $(shell git log --pretty=tformat:"%h" -n1 services/static-webserver/client)
export VCS_STATUS_CLIENT:= $(if $(shell git status -s),'modified/untracked','clean')
export BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
Expand Down
56 changes: 56 additions & 0 deletions packages/service-integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
ARG PYTHON_VERSION="3.9.12"
FROM python:${PYTHON_VERSION}-slim-buster as base

LABEL maintainer=pcrespov

# Sets utf-8 encoding for Python et al
ENV LANG=C.UTF-8
# Turns off writing .pyc files; superfluous on an ephemeral container.
ENV PYTHONDONTWRITEBYTECODE=1 \
VIRTUAL_ENV=/home/scu/.venv
# Ensures that the python and pip executables used
# in the image will be those from our virtualenv.
ENV PATH="${VIRTUAL_ENV}/bin:$PATH"


# -------------------------- Build stage -------------------

FROM base as build

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*


# NOTE: python virtualenv is used here such that installed
# packages may be moved to production image easily by copying the venv
RUN python -m venv "${VIRTUAL_ENV}"

RUN pip install --no-cache-dir --upgrade \
pip~=22.0 \
wheel \
setuptools

WORKDIR /build

COPY --chown=scu:scu packages/models-library packages/models-library
COPY --chown=scu:scu packages/service-integration packages/service-integration


# WARNING: keep synced with `make install-prod` (did not use it directly because if would require copying scripts/common.Makefile and other parts of the repo)
RUN cd packages/service-integration \
&& pip install --no-cache-dir -r requirements/_base.txt \
&& pip install --no-cache-dir ../models-library/ \
&& pip install --no-cache-dir .


# -------------------------- Build stage -------------------

FROM base as production

COPY --from=build --chown=scu:scu ${VIRTUAL_ENV} ${VIRTUAL_ENV}

# NOTE: do not activate ENV PYTHONOPTIMIZE=TRUE since excutable contains pytest code
ENTRYPOINT [ "ooil" ]
26 changes: 25 additions & 1 deletion packages/service-integration/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
include ../../scripts/common.Makefile
include ../../scripts/common-package.Makefile


.PHONY: requirements
requirements: ## compiles pip requirements (.in -> .txt)
@$(MAKE_C) requirements reqs
Expand Down Expand Up @@ -46,8 +47,9 @@ tests-ci: ## runs unit tests [ci-mode]
-m "not heavy_load" \
$(CURDIR)/tests


#
# Auto-generation of compose-spec model
#

compose-spec.json:
# Downloading schema from https://github.com/compose-spec/compose-spec
Expand All @@ -68,3 +70,25 @@ _compose_spec_model.py: ## auto-generates pydantic model for compose-specificati
# formats and moves
black $@
mv $@ src/service_integration/$@



#
# Docker image (executable)
#

.PHONY: build build-nc
build build-nc: ## [docker] builds docker image of executable w/ or w/o cache
# Building docker image for ${PACKAGE_NAME} ...
@$(MAKE_C) ${REPO_BASE_DIR} $@ target=${PACKAGE_NAME}
# Test run
docker run local/${PACKAGE_NAME}:production --version

.PHONY: inspect
inspect:
docker image inspect local/${PACKAGE_NAME}:production | jq '.[0] | .RepoTags, .Config.Labels, .Architecture'


.PHONY: shell
shell:
docker run -it --entrypoint bash local/${PACKAGE_NAME}:production
Loading

0 comments on commit 86b0800

Please sign in to comment.