Skip to content

Commit d36d824

Browse files
authored
Emailer queue upgrade (#1911) (#1912)
* queue replacement * unit tests * dockerfile * fix logger
1 parent 053ab8f commit d36d824

17 files changed

Lines changed: 1989 additions & 1221 deletions

File tree

services/emailer/Dockerfile

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM python:3.12.2
21

3-
USER root
2+
# Stage 1: Build environment (with Poetry + dependencies installed)
3+
FROM python:3.12-slim AS development_build
44

55
ARG VCS_REF="missing"
66
ARG BUILD_DATE="missing"
@@ -10,32 +10,32 @@ ENV BUILD_DATE=${BUILD_DATE}
1010
ENV PORT=8080
1111

1212
LABEL org.label-schema.vcs-ref=${VCS_REF} \
13-
org.label-schema.build-date=${BUILD_DATE}
13+
org.label-schema.build-date=${BUILD_DATE} \
14+
vendor="BCROS"
1415

15-
LABEL vendor="BCROS"
16+
USER root
1617

1718
ARG APP_ENV \
18-
# Needed for fixing permissions of files created by Docker:
19-
UID=1000 \
20-
GID=1000
19+
UID=1000 \
20+
GID=1000
2121

2222
ENV APP_ENV=${APP_ENV} \
23-
# python:
24-
PYTHONFAULTHANDLER=1 \
25-
PYTHONUNBUFFERED=1 \
26-
PYTHONHASHSEED=random \
27-
PYTHONDONTWRITEBYTECODE=1 \
28-
# pip:
29-
PIP_NO_CACHE_DIR=1 \
30-
PIP_DISABLE_PIP_VERSION_CHECK=1 \
31-
PIP_DEFAULT_TIMEOUT=100 \
32-
PIP_ROOT_USER_ACTION=ignore \
33-
# poetry:
34-
POETRY_VERSION=1.3.2 \
35-
POETRY_NO_INTERACTION=1 \
36-
POETRY_VIRTUALENVS_CREATE=false \
37-
POETRY_CACHE_DIR='/var/cache/pypoetry' \
38-
POETRY_HOME='/usr/local'
23+
# python:
24+
PYTHONFAULTHANDLER=1 \
25+
PYTHONUNBUFFERED=1 \
26+
PYTHONHASHSEED=random \
27+
PYTHONDONTWRITEBYTECODE=1 \
28+
# pip:
29+
PIP_NO_CACHE_DIR=1 \
30+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
31+
PIP_DEFAULT_TIMEOUT=100 \
32+
PIP_ROOT_USER_ACTION=ignore \
33+
# poetry:
34+
POETRY_VERSION=2.1.3 \
35+
POETRY_NO_INTERACTION=1 \
36+
POETRY_VIRTUALENVS_CREATE=false \
37+
POETRY_CACHE_DIR='/var/cache/pypoetry' \
38+
POETRY_HOME='/usr/local'
3939

4040
SHELL ["/bin/bash", "-eo", "pipefail", "-c"]
4141

@@ -51,7 +51,7 @@ RUN apt-get update && apt-get upgrade -y \
5151
wait-for-it \
5252
&& curl -sSL 'https://install.python-poetry.org' | python - \
5353
&& poetry --version \
54-
# Cleaning cache:
54+
# Clean up apt cache
5555
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
5656
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
5757

@@ -61,29 +61,30 @@ RUN groupadd -g "${GID}" -r web \
6161
&& useradd -d '/code' -g web -l -r -u "${UID}" web \
6262
&& chown web:web -R '/code'
6363

64-
# Copy only requirements, to cache them in docker layer
64+
# Copy dependency files first (better caching)
6565
COPY --chown=web:web ./poetry.lock ./pyproject.toml /code/
6666

67+
# Copy app source
6768
COPY --chown=web:web ./src /code/src
6869
COPY --chown=web:web ./README.md /code
6970

70-
# Project initialization:
71+
# Install dependencies
7172
RUN --mount=type=cache,target="$POETRY_CACHE_DIR" \
7273
echo "$APP_ENV" \
74+
&& poetry config installer.max-workers 1 \
7375
&& poetry version \
74-
# Install deps:
7576
&& poetry run pip install -U pip \
7677
&& poetry install \
77-
$(if [ -z ${APP_ENV+x} ] | [ "$APP_ENV" = 'production' ]; then echo '--only main'; fi) \
78+
$(if [ -z "${APP_ENV}" ] || [ "$APP_ENV" = 'production' ]; then echo '--only main'; fi) \
7879
--no-interaction --no-ansi
7980

80-
# Running as non-root user:
81+
# Run as non-root
8182
USER web
8283

83-
# The following stage is only for production:
84-
# FROM development_build AS production_build
84+
# Stage 2: Production image (lighter)
85+
FROM development_build AS production_build
8586
COPY --chown=web:web . /code
8687

87-
# ENV PYTHONPATH=/opt/app-root/src
88+
EXPOSE 8080
8889

89-
CMD gunicorn --preload --bind 0.0.0.0:${PORT} --config /code/gunicorn_config.py wsgi:app
90+
CMD gunicorn --bind 0.0.0.0:${PORT} --config /code/gunicorn_config.py wsgi:app

services/emailer/Makefile

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
.PHONY: license
2+
.PHONY: setup
3+
.PHONY: ci cd
4+
.PHONY: run
5+
6+
MKFILE_PATH:=$(abspath $(lastword $(MAKEFILE_LIST)))
7+
CURRENT_ABS_DIR:=$(patsubst %/,%,$(dir $(MKFILE_PATH)))
8+
9+
PROJECT_NAME:=solr_names_updater
10+
DOCKER_NAME:=solr-names-updater
11+
12+
#################################################################################
13+
# COMMANDS -- Setup #
14+
#################################################################################
15+
setup: install ## Setup the project
16+
17+
clean: clean-build clean-pyc clean-test ## Clean the project
18+
rm -rf .venv/
19+
rm -rf poetry.lock
20+
21+
clean-build: ## Clean build files
22+
rm -fr build/
23+
rm -fr dist/
24+
rm -fr .eggs/
25+
find . -name '*.egg-info' -exec rm -fr {} +
26+
find . -name '*.egg' -exec rm -fr {} +
27+
28+
clean-pyc: ## Clean cache files
29+
find . -name '*.pyc' -exec rm -f {} +
30+
find . -name '*.pyo' -exec rm -f {} +
31+
find . -name '*~' -exec rm -f {} +
32+
find . -name '__pycache__' -exec rm -fr {} +
33+
34+
clean-test: ## clean test files
35+
find . -name '.pytest_cache' -exec rm -fr {} +
36+
rm -fr .tox/
37+
rm -f .coverage
38+
rm -fr htmlcov/
39+
40+
update: ## Upgrade lock
41+
poetry update
42+
43+
install: clean ## Install python virtrual environment
44+
test -f .venv/bin/activate || python3.12 -m venv $(CURRENT_ABS_DIR)/.venv ;\
45+
. .venv/bin/activate ;\
46+
pipx install poetry
47+
poetry install
48+
49+
#################################################################################
50+
# COMMANDS - CI #
51+
#################################################################################
52+
ci: docker-build-check ruff test ## CI flow
53+
54+
docker-build-check: ## Check if Dockerfile builds successfully
55+
docker build -f Dockerfile -t namex-emailer .
56+
57+
ruff: ## ruff linter
58+
poetry run ruff check
59+
60+
ruff-fix: ## auto fix lint issues with ruff
61+
poetry run ruff check --fix
62+
63+
test: ## unit testing with local db
64+
poetry run pytest
65+
66+
#################################################################################
67+
# COMMANDS - Local #
68+
#################################################################################
69+
70+
run: ## Run the project in local
71+
. .venv/bin/activate && python3.12 run.py
72+
73+
#################################################################################
74+
# Self Documenting Commands #
75+
#################################################################################
76+
.PHONY: help
77+
78+
.DEFAULT_GOAL := help
79+
80+
help:
81+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

0 commit comments

Comments
 (0)