Skip to content

Commit

Permalink
chore(ci): sync changes with nr-spar (#64)
Browse files Browse the repository at this point in the history
Co-authored-by: Márcio Nemec <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: ronrobb <[email protected]>
Co-authored-by: ronrobb <[email protected]>
Co-authored-by: Ricardo Campos <[email protected]>
Co-authored-by: Craig Yu <[email protected]>
Co-authored-by: DustyD <[email protected]>
Co-authored-by: Xiao Peng <[email protected]>
Co-authored-by: mgaseta <[email protected]>
  • Loading branch information
10 people authored Feb 4, 2025
1 parent 0fed4f0 commit cab7bdf
Show file tree
Hide file tree
Showing 14 changed files with 571 additions and 2,082 deletions.
3 changes: 0 additions & 3 deletions sync/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,3 @@ jest.*
.vscode
.ps1
thumbs.db

venv/**
.venv/**
69 changes: 15 additions & 54 deletions sync/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,63 +1,24 @@
# ----------------- STAGE 1 -----------------
FROM python:3.13-slim-bookworm as base
# using slim for development as the wheels are not always compat with
# alpine, and builds can be slow as a result
# FROM python:3.12-slim as base
FROM python:3.13-slim

ARG DEV=false
ENV VIRTUAL_ENV=/app/docker_venv \
PATH="/app/docker_venv/bin:$PATH"
# Receive build number as argument, retain as environment variable
ARG BUILD_NUMBER
ENV BUILD_NUMBER=${BUILD_NUMBER}

# ----------------- STAGE 2 -----------------
FROM base as builder
WORKDIR /app

# Mostly config for poetry
# - disable prompting
# - disable virtualenv creation
# - specify the path to the venv
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=0 \
POETRY_VIRTUALENVS_CREATE=0 \
POETRY_CACHE_DIR=/tmp/poetry_cache \
VIRTUAL_ENV=/app/docker_venv \
PATH="/app/docker_venv/bin:$PATH"

# install build tools, and dev libs required to compile postgres stuff
# ideally these are not going to be used as for most of the libs
# there are wheels available, however they are available in case we
# need to compile something
# Packages and nonroot user
RUN apt update && \
apt install -y --no-install-recommends gcc libpq-dev python3-dev && \
useradd -M nonroot

# Install Poetry to global python env
RUN pip install poetry==1.8.4

# Grab the app dependency declarations
COPY pyproject.toml poetry.lock ./

# create the venv in $VIRTUAL_ENV so we can control where it is being created
# unfortunately this is the only way that we can control the venv that
# poetry will use, is to create it ourselves
RUN python -m venv $VIRTUAL_ENV; . $VIRTUAL_ENV/bin/activate
# Disable cache, disable upgrade message, don't write .pyc files
ENV PIP_NO_CACHE_DIR="1"
ENV PIP_DISABLE_PIP_VERSION_CHECK="1"
ENV PYTHONDONTWRITEBYTECODE="1"

# have created and activated the venv, now install the dependencies into it
RUN poetry install --without dev --no-root -v && rm -rf $POETRY_CACHE_DIR

# ----------------- STAGE 3 -----------------
FROM base as runtime
# Copy files and install requirements
WORKDIR /app
COPY . ./
RUN pip install -r ./requirements.txt --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org


# install the postgres client, required by psycopg2
RUN apt update && apt install -y --no-install-recommends postgresql-client

# only copy over the venv from the builder stage
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}

# RUN apk add bash
COPY src /app/src
COPY config /app/config

CMD ["python", "src/main.py"]
# Start the app
USER nonroot
CMD ["python3", "/app/src/main.py"]
56 changes: 0 additions & 56 deletions sync/README.md

This file was deleted.

803 changes: 0 additions & 803 deletions sync/poetry.lock

This file was deleted.

4 changes: 0 additions & 4 deletions sync/poetry.toml

This file was deleted.

48 changes: 0 additions & 48 deletions sync/pyproject.toml

This file was deleted.

7 changes: 7 additions & 0 deletions sync/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#cx-Oracle==8.3.0
oracledb
numpy==2.2.2
pandas==2.2.3
psycopg2==2.9.10
SQLAlchemy==2.0.34
pyyaml==6.0.2
35 changes: 15 additions & 20 deletions sync/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,25 @@ set -euo nounset
### Setup

# Several packages are not working for python 3.12
# PYVER=3.10.13

# export COMMAND=${1:-}
# if [ "${COMMAND}" == "setup" ]; then
# [ -z "${PYENV_ROOT}" ]|| export PYENV_ROOT="$HOME/.pyenv"
# command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
# eval "$(pyenv init -)"
# pyenv update
# pyenv install -s ${PYVER}
# pyenv global ${PYVER}
# python -m venv --clear venv
# source venv/bin/activate
# python -m pip install --upgrade pip
# fi
PYVER=3.10.13

export COMMAND=${1:-}
if [ "${COMMAND}" == "setup" ]; then
[ -z "${PYENV_ROOT}" ]|| export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
pyenv update
pyenv install -s ${PYVER}
pyenv global ${PYVER}
python -m venv --clear venv
source venv/bin/activate
python -m pip install --upgrade pip
fi


### Requirements

#python -m pip install -r ./requirements.txt --cache-dir ./data
poetry install

# activate env
poetry_path=$(poetry env info --path)
. $poetry_path/bin/activate
python -m pip install -r ./requirements.txt --cache-dir ./data


### Run
Expand Down
66 changes: 0 additions & 66 deletions sync/src/logging.config

This file was deleted.

22 changes: 22 additions & 0 deletions sync/src/logging.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[loggers]
keys=root

[handlers]
keys=stream_handler

[formatters]
keys=sample_formatter

[logger_root]
level=INFO
handlers=stream_handler

[handler_stream_handler]
class=StreamHandler
formatter=sample_formatter
args=(sys.stdout,)

[formatter_sample_formatter]
format=%(levelname)s: %(asctime)s: %(module)s - %(message)s
datefmt=%Y-%m-%d %H:%M:%S

Loading

0 comments on commit cab7bdf

Please sign in to comment.