forked from ISPsystem/isp-maintenance
		
	
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Docker
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Docker
		
	
	
	
	
	
| # app/Dockerfile
 | |
| 
 | |
| # pull the official docker image
 | |
| FROM python:3.12-alpine AS poetry-base
 | |
| 
 | |
| # default build args
 | |
| ARG APP_VERSION=0.1.1 \
 | |
|     APP_DIR=/app \
 | |
|     SRC_DIR=./mgrctl \
 | |
|     PKG_NAME=mgrctl \
 | |
|     PKG_VERSION=0.1.1
 | |
| 
 | |
| # set env variables
 | |
| ENV APP_NAME=mgrctl \
 | |
|     # Python3:
 | |
|     PYTHONFAULTHANDLER=1 \
 | |
|     PYTHONUNBUFFERED=1 \
 | |
|     PYTHONHASHSEED=random \
 | |
|     # Pip:
 | |
|     PIP_NO_CACHE_DIR=on \
 | |
|     PIP_DISABLE_PIP_VERSION_CHECK=on \
 | |
|     PIP_ROOT_USER_ACTION=ignore \
 | |
|     PIP_DEFAULT_TIMEOUT=100 \
 | |
|     # Poetry:
 | |
|     POETRY_NO_INTERACTION=1 \
 | |
|     POETRY_VIRTUALENVS_CREATE=false \
 | |
|     POETRY_CACHE_DIR='/var/cache/pypoetry' \
 | |
|     POETRY_HOME='/usr/local' \
 | |
|     POETRY_VERSION=2.1.2
 | |
| 
 | |
| # install system deps
 | |
| RUN apk --no-cache add curl \
 | |
|     && curl -sSL https://install.python-poetry.org | python3 - \
 | |
|     && mkdir ${APP_DIR}
 | |
| 
 | |
| COPY ./pyproject.toml ./poetry.lock ./README.md ${APP_DIR}
 | |
| COPY ${SRC_DIR} ${APP_DIR}/${PKG_NAME}
 | |
| 
 | |
| # set workdir
 | |
| WORKDIR ${APP_DIR}
 | |
| 
 | |
| # build pkg whl
 | |
| RUN poetry build --format wheel \
 | |
|     && pip install ${APP_DIR}/dist/${PKG_NAME}-${PKG_VERSION}-py3-none-any.whl \
 | |
|     && rm -r /usr/local/venv
 | |
| 
 | |
| # now multistage builds
 | |
| FROM python:3.12-alpine
 | |
| 
 | |
| # copy app and dependencies
 | |
| COPY --from=poetry-base /usr/local/ /usr/local/
 | |
| 
 | |
| # install bash and mgrctl shell completion
 | |
| RUN apk --no-cache add bash \
 | |
|     && echo 'eval "$(_MGRCTL_COMPLETE=bash_source mgrctl)"' > ~/.bashrc
 | |
| 
 | |
| # "demonize" container
 | |
| # use docker attach mgrctl or docker exec -it mgrctl mgrctl --help for example
 | |
| CMD [ "bash"]
 |