Skip to content
Snippets Groups Projects
Commit dc77a799 authored by Luc Yriarte's avatar Luc Yriarte
Browse files

Re-add container build for gitlab CICD

parent a084f969
No related branches found
No related tags found
1 merge request!7Slb code push 2
Pipeline #23282 failed
##################################################################
# Create a first image with credentials. It will download the dep.
##################################################################
FROM python:3.7-slim-buster as build
WORKDIR /root/build_directory
LABEL maintainer="OSDU Wellbore data domain services team <WellboreDDMS@slb.com>"
COPY requirements.txt .
RUN pip wheel uvicorn --wheel-dir=python-packages
ARG PIP_EXTRA_URL
ARG PIP_WHEEL_DIR
RUN pip wheel -r requirements.txt --extra-index-url=$PIP_EXTRA_URL --wheel-dir=$PIP_WHEEL_DIR
#################################################################
# Create a second image without credentials
#################################################################
FROM python:3.7-slim-buster
COPY --from=build /root/build_directory .
RUN pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps python-packages/*
COPY ./app /app
ENV PYTHONPATH=./
# record some detail of the build, must be passed as --build-arg
ARG build_date
ARG build_number
ARG build_origin="Personal build"
ARG commit_id
ARG commit_branch
ENV OS_WELLBORE_DDMS_BUILD_DETAILS build_date=$build_date;build_number=$build_number;build_origin=$build_origin;commit_id=$commit_id;commit_branch=$commit_branch
EXPOSE 8097
WORKDIR ./
# Make the container run as non-root user
#(https://medium.com/better-programming/running-a-container-with-a-non-root-user-e35830d1f42a)
RUN addgroup --system appuser && adduser --system appuser && adduser appuser appuser
USER appuser
CMD ["uvicorn", "app.wdms_app:wdms_app", "--host", "0.0.0.0", "--port", "8097"]
import re
import shutil
import sys
FILE_TO_UPDATE = 'app/__init__.py'
VERSION_FIELD_NAME = '__version__'
BUILD_NUMBER_FIELD_NAME = '__build_number__'
FIELDS_TO_CAPTURE = [VERSION_FIELD_NAME, BUILD_NUMBER_FIELD_NAME]
# capture KEY = basic string
regexp_key_value_capture = re.compile(
"^[\\s]*(" + '|'.join(FIELDS_TO_CAPTURE) + ")[\\s]*=[\\s]*[('\\\")](.+)[('\\\")].*"
)
regexp_key_capture = re.compile(
"^[\\s]*(" + '|'.join(FIELDS_TO_CAPTURE) + ")[\\s]*=.*"
)
def set_version(file_name: str, *, build_number: str, patch_number: str):
initial_value = {k: None for k in FIELDS_TO_CAPTURE}
lines = ['# updated by script -------------------\n', '\n']
# capture
with open(file_name) as f:
for line in f:
lines.append(line)
m = regexp_key_value_capture.match(line)
if m is not None and len(m.groups()) == 2:
key, value = m.group(1, 2)
initial_value[key] = value
# backup
shutil.copyfile(file_name, file_name + '.bck')
new_values = {
VERSION_FIELD_NAME: '"' + initial_value[VERSION_FIELD_NAME] + f'.{patch_number or "0000"}' + '"',
BUILD_NUMBER_FIELD_NAME: f'"{build_number or "unknown"}"',
}
with open(file_name, 'w') as f:
for line in lines:
m = regexp_key_capture.match(line)
if m is not None:
key = m.group(1)
if key in new_values:
f.write('# was: ' + line)
line = f'{key} = {new_values[key]}\n\n'
f.write(line) # other line kept untouched
if __name__ == "__main__":
kwargs = {arg.split('=')[0]: arg.split('=')[1] for arg in sys.argv[1:]}
assert 'build_number' in kwargs and 'patch_number' in kwargs, 'build_number and patch_number must be defined'
set_version(FILE_TO_UPDATE, build_number=kwargs['build_number'], patch_number=kwargs['patch_number'])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment