Porting build logic to poetry not economical right now.
This commit is contained in:
Matthias Bisping 2023-01-03 11:38:32 +01:00
parent f0bba5bbdb
commit 35d046c454
2 changed files with 51 additions and 177 deletions

View File

@ -1,64 +1,30 @@
# FROM python:3.8
#
# ARG YOUR_ENV
#
# WORKDIR /app/service
#
# COPY ./src ./src
# COPY ./cv_analysis ./cv_analysis
# COPY pyproject.toml .
# COPY poetry.lock .
#
# ENV YOUR_ENV=${YOUR_ENV} \
# PYTHONFAULTHANDLER=1 \
# PYTHONUNBUFFERED=1 \
# PYTHONHASHSEED=random \
# PIP_NO_CACHE_DIR=off \
# PIP_DISABLE_PIP_VERSION_CHECK=on \
# PIP_DEFAULT_TIMEOUT=100 \
# POETRY_VERSION=1.2.2
#
# # System deps:
# RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/etc/poetry python3 -
# ENV PATH="$PATH:/etc/poetry/bin/"
# RUN poetry --version
#
# # Project initialization:
# RUN poetry config virtualenvs.create false
# RUN poetry install --no-interaction --no-ansi
#
# CMD ["python3", "-u", "src/serve.py"]
FROM python:3.10
RUN python -m venv /app/venv
ENV PATH="/app/venv/bin:$PATH"
RUN python -m pip install --upgrade pip
FROM python:3.8 as builder
ARG SSH_KEY
ENV PYTHONUNBUFFERED=true
WORKDIR /app
WORKDIR /app/service
ENV POETRY_HOME=/opt/poetry
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
ENV PATH="$POETRY_HOME/bin:$PATH"
COPY ./requirements.txt ./requirements.txt
RUN python3 -m pip install -r requirements.txt
RUN mkdir /root/.ssh/ && \
chmod 700 /root/.ssh/ && \
echo "${SSH_KEY}" > /root/.ssh/id_rsa && \
chmod 600 /root/.ssh/id_rsa && \
ssh-keyscan -p 2222 git.iqser.com >> /root/.ssh/known_hosts
COPY ./incl/pyinfra/requirements.txt ./incl/pyinfra/requirements.txt
RUN python -m pip install -r incl/pyinfra/requirements.txt
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python
COPY ./incl/pdf2image/requirements.txt ./incl/pdf2image/requirements.txt
RUN python -m pip install -r incl/pdf2image/requirements.txt
COPY pyproject.toml poetry.lock ./src ./
COPY cv_analysis ./cv_analysis
RUN /opt/poetry/bin/poetry install --no-interaction --no-root --only main
COPY ./incl ./incl
FROM python:3.8-bullseye as prod
ENV PYTHONUNBUFFERED=true
WORKDIR /app
ENV PATH="/app/.venv/bin:$PATH"
COPY --from=builder /app /app
RUN python3 -m pip install -e incl/pyinfra
RUN python3 -m pip install -e incl/pdf2image
COPY ./src ./
USER 1001
COPY ./src ./src
COPY ./cv_analysis ./cv_analysis
COPY ./setup.py ./setup.py
CMD ["python3", "-u", "src/serve.py"]
RUN python3 -m pip install -e .
CMD ["python3", "-u", "src/serve.py"]

View File

@ -1,145 +1,53 @@
##!/bin/bash
#set -e
#
#SERVICE_NAME=$1
#
#if [[ "$bamboo_planRepository_branchName" == "master" ]]
#then
# branchVersion=$(cat version.yaml | grep -Eo "version: .*" | sed -s 's|version: \(.*\)\..*\..*|\1|g')
# latestVersion=$( semver $(git tag -l "${branchVersion}.*" ) | tail -n1 )
# newVersion="$(semver $latestVersion -p -i minor)"
# echo "new release on master with version $newVersion"
#elif [[ "$bamboo_planRepository_branchName" == release* ]]
#then
# branchVersion=$(echo $bamboo_planRepository_branchName | sed -s 's|release\/\([0-9]\+\.[0-9]\+\)\.x|\1|')
# latestVersion=$( semver $(git tag -l "${branchVersion}.*" ) | tail -n1 )
# newVersion="$(semver $latestVersion -p -i patch)"
# echo "new release on $bamboo_planRepository_branchName with version $newVersion"
#elif [[ "${bamboo_version_tag}" != "dev" ]]
#then
# newVersion="${bamboo_version_tag}"
# echo "new special version bild with $newVersion"
#else
# newVersion="${bamboo_planRepository_1_branch}_${bamboo_buildNumber}"
# echo "gitTag=${newVersion}" > git.tag
# echo "dev build with tag ${newVersion}"
# python3 -m venv build_venv
# source build_venv/bin/activate
# python3 -m pip install --upgrade pip
#
# pip install dvc
# pip install 'dvc[ssh]'
# dvc pull
#
# echo "index-url = https://${bamboo_nexus_user}:${bamboo_nexus_password}@nexus.iqser.com/repository/python-combind/simple" >> pip.conf
# echo "${bamboo_nexus_password}" | docker login --username "${bamboo_nexus_user}" --password-stdin nexus.iqser.com:5001
# docker build -f Dockerfile .
# exit 0
#fi
#
#echo "gitTag=${newVersion}" > git.tag
#
#python3 -m venv build_venv
#source build_venv/bin/activate
#python3 -m pip install --upgrade pip
#
#pip install dvc
#pip install 'dvc[ssh]'
#dvc pull
#
#echo "index-url = https://${bamboo_nexus_user}:${bamboo_nexus_password}@nexus.iqser.com/repository/python-combind/simple" >> pip.conf
#docker build -f Dockerfile -t nexus.iqser.com:5001/red/$SERVICE_NAME:${newVersion} .
#echo "${bamboo_nexus_password}" | docker login --username "${bamboo_nexus_user}" --password-stdin nexus.iqser.com:5001
#docker push nexus.iqser.com:5001/red/$SERVICE_NAME:${newVersion}
#!/bin/bash
set -e
SERVICE_NAME=$1
project_name="sil"
HOST="nexus.iqser.com"
PORT="5001"
mkdir -p ~/.ssh
echo "${bamboo_agent_ssh}" | base64 -d >> ~/.ssh/id_rsa
python3 -m venv build_venv
source build_venv/bin/activate
python3 -m pip install --upgrade pip
pip install poetry
# update version in poetry to latest version in git if it is lower
check_poetry_version () {
currentVersion=$(poetry version -s)
tagCount=$(git rev-list --tags --max-count=1 | wc -l)
if [[ $tagCount -gt 0 ]]
then
latestVersion=$(git rev-list --tags --max-count=1 | git describe --tags)
echo "latest version tag in git: ${latestVersion}"
echo "current version in project: ${currentVersion}"
if [[ "$currentVersion" < "$latestVersion" ]]
then
echo "project version is behind"
echo "setting latest git tag as current version"
poetry version "$latestVersion"
updateVersion=0
elif [[ "$currentVersion" == "$latestVersion" ]]
then
echo "project version matches"
echo "keeping the project version"
updateVersion=0
else
echo "project version is higher"
echo "keeping the project version, be aware that a version might have been skipped"
updateVersion=1
fi
else
updateVersion=1
fi
return $updateVersion
}
if [[ "$bamboo_planRepository_branchName" == "master" ]]
then
if check_poetry_version
then
poetry version minor
fi
newVersion="$(poetry version -s)"
echo "new release on master with version: $newVersion"
branchVersion=$(cat version.yaml | grep -Eo "version: .*" | sed -s 's|version: \(.*\)\..*\..*|\1|g')
latestVersion=$( semver $(git tag -l "${branchVersion}.*" ) | tail -n1 )
newVersion="$(semver $latestVersion -p -i minor)"
echo "new release on master with version $newVersion"
elif [[ "$bamboo_planRepository_branchName" == release* ]]
then
if check_poetry_version
then
poetry version patch
fi
newVersion="$(poetry version -s)"
branchVersion=$(echo $bamboo_planRepository_branchName | sed -s 's|release\/\([0-9]\+\.[0-9]\+\)\.x|\1|')
latestVersion=$( semver $(git tag -l "${branchVersion}.*" ) | tail -n1 )
newVersion="$(semver $latestVersion -p -i patch)"
echo "new release on $bamboo_planRepository_branchName with version $newVersion"
elif [[ "${bamboo_version_tag}" != "dev" ]]
then
newVersion="${bamboo_version_tag}"
echo "new special version build with: $newVersion"
echo "new special version bild with $newVersion"
else
newVersion="${bamboo_planRepository_1_branch}_${bamboo_buildNumber}"
echo "gitTag=${newVersion}" > git.tag
echo "dev build with tag: ${newVersion}"
echo "dev build with tag ${newVersion}"
python3 -m venv build_venv
source build_venv/bin/activate
python3 -m pip install --upgrade pip
echo "index-url = https://${bamboo_nexus_user}:${bamboo_nexus_password}@${HOST}/repository/python-combind/simple" >> pip.conf
echo "${bamboo_nexus_password}" | docker login --username "${bamboo_nexus_user}" --password-stdin ${HOST}:${PORT}
docker build --build-arg SSH_KEY="$(cat ~/.ssh/id_rsa)" -f Dockerfile .
pip install dvc
pip install 'dvc[ssh]'
dvc pull
echo "index-url = https://${bamboo_nexus_user}:${bamboo_nexus_password}@nexus.iqser.com/repository/python-combind/simple" >> pip.conf
echo "${bamboo_nexus_password}" | docker login --username "${bamboo_nexus_user}" --password-stdin nexus.iqser.com:5001
docker build -f Dockerfile .
exit 0
fi
echo "gitTag=${newVersion}" > git.tag
echo "index-url = https://${bamboo_nexus_user}:${bamboo_nexus_password}@${HOST}/repository/python-combind/simple" >> pip.conf
echo "${bamboo_nexus_password}" | docker login --username "${bamboo_nexus_user}" --password-stdin ${HOST}:${PORT}
docker build --build-arg SSH_KEY="$(cat ~/.ssh/id_rsa)" -f Dockerfile -t ${HOST}:${PORT}/${project_name}/$SERVICE_NAME:${newVersion} --build-arg VERSION_TAG=${newVersion} .
docker push ${HOST}:${PORT}/${project_name}/$SERVICE_NAME:${newVersion}
python3 -m venv build_venv
source build_venv/bin/activate
python3 -m pip install --upgrade pip
pip install dvc
pip install 'dvc[ssh]'
dvc pull
echo "index-url = https://${bamboo_nexus_user}:${bamboo_nexus_password}@nexus.iqser.com/repository/python-combind/simple" >> pip.conf
docker build -f Dockerfile -t nexus.iqser.com:5001/red/$SERVICE_NAME:${newVersion} .
echo "${bamboo_nexus_password}" | docker login --username "${bamboo_nexus_user}" --password-stdin nexus.iqser.com:5001
docker push nexus.iqser.com:5001/red/$SERVICE_NAME:${newVersion}