Copy paste and adjust build code from rule-engine repo

That build code is more recent and the current build code fails.
This commit is contained in:
Matthias Bisping 2023-01-03 10:51:20 +01:00
parent aee7ee9b97
commit f0bba5bbdb
2 changed files with 180 additions and 54 deletions

View File

@ -1,30 +1,64 @@
FROM python:3.8
# 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"]
ARG YOUR_ENV
WORKDIR /app/service
COPY ./src ./src
COPY ./cv_analysis ./cv_analysis
COPY pyproject.toml .
COPY poetry.lock .
FROM python:3.8 as builder
ARG SSH_KEY
ENV PYTHONUNBUFFERED=true
WORKDIR /app
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
ENV POETRY_HOME=/opt/poetry
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
ENV PATH="$POETRY_HOME/bin:$PATH"
# System deps:
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/etc/poetry python3 -
ENV PATH="$PATH:/etc/poetry/bin/"
RUN poetry --version
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
# Project initialization:
RUN poetry config virtualenvs.create false
RUN poetry install --no-interaction --no-ansi
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python
CMD ["python3", "-u", "src/serve.py"]
COPY pyproject.toml poetry.lock ./src ./
COPY cv_analysis ./cv_analysis
RUN /opt/poetry/bin/poetry install --no-interaction --no-root --only main
FROM python:3.8-bullseye as prod
ENV PYTHONUNBUFFERED=true
WORKDIR /app
ENV PATH="/app/.venv/bin:$PATH"
COPY --from=builder /app /app
COPY ./src ./
USER 1001
CMD ["python3", "-u", "src/serve.py"]

View File

@ -1,53 +1,145 @@
##!/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
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"
if check_poetry_version
then
poetry version minor
fi
newVersion="$(poetry version -s)"
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)"
if check_poetry_version
then
poetry version patch
fi
newVersion="$(poetry version -s)"
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"
echo "new special version build 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
echo "dev build with tag: ${newVersion}"
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 .
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 .
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}
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}