Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22921 account mailer gcp migration #3004

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 53 additions & 10 deletions queue_services/account-mailer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM python:3.8.5-buster
FROM python:3.8.10 as development_build

ARG VCS_REF="missing"
ARG BUILD_DATE="missing"

ENV VCS_REF=${VCS_REF}
ENV BUILD_DATE=${BUILD_DATE}
ENV PORT=8080

LABEL org.label-schema.vcs-ref=${VCS_REF} \
org.label-schema.build-date=${BUILD_DATE}
Expand All @@ -16,20 +17,62 @@ RUN mkdir /opt/app-root && chmod 755 /opt/app-root
WORKDIR /opt/app-root

# Install the requirements
COPY ./requirements.txt .
ARG APP_ENV \
UID=1000 \
GID=1000

RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
ENV APP_ENV=${APP_ENV} \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_DEFAULT_TIMEOUT=100 \
PIP_ROOT_USER_ACTION=ignore \
POETRY_VERSION=1.8.3 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_CACHE_DIR='/var/cache/pypoetry' \
POETRY_HOME='/usr/local'

COPY . .
SHELL ["/bin/bash", "-eo", "pipefail", "-c"]

RUN pip install .
RUN apt-get update && apt-get upgrade -y \
&& apt-get install --no-install-recommends -y \
bash \
build-essential \
curl \
git \
libpq-dev \
&& curl -sSL 'https://install.python-poetry.org' | python3 - \
&& poetry --version \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

USER 1001
WORKDIR /code

# Set Python path
ENV PYTHONPATH=/opt/app-root/src
RUN groupadd -g "${GID}" -r web \
&& useradd -d '/code' -g web -l -r -u "${UID}" web \
&& chown web:web -R '/code'

#EXPOSE 8080
COPY --chown=web:web ./poetry.lock ./pyproject.toml /code/

CMD ["gunicorn", "-b 0.0.0.0:8080", "app:app"]
COPY --chown=web:web ./src /code/src
COPY --chown=web:web ./README.md /code

RUN --mount=type=cache,target="$POETRY_CACHE_DIR" \
echo "$APP_ENV" \
&& poetry version \
&& poetry run pip install -U pip \
&& poetry install \
$(if [ -z ${APP_ENV+x} ] || [ "$APP_ENV" = 'production' ]; then echo '--only main'; fi) \
--no-interaction --no-ansi

USER web

FROM development_build AS production_build
COPY --chown=web:web . /code

CMD gunicorn --bind 0.0.0.0:${PORT} --config /code/gunicorn_config.py app:app
32 changes: 13 additions & 19 deletions queue_services/account-mailer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ DOCKER_NAME:=account-mailer
setup: clean install install-dev ## Setup the project

clean: clean-build clean-pyc clean-test ## Clean the project
rm -rf venv/
rm -rf .venv/
rm -rf poetry.lock

clean-build: ## Clean build files
rm -fr build/
Expand All @@ -37,40 +38,33 @@ clean-test: ## clean test files
rm -fr htmlcov/

build-req: clean ## Upgrade requirements
test -f venv/bin/activate || python3 -m venv $(CURRENT_ABS_DIR)/venv ;\
. venv/bin/activate ;\
pip install --upgrade pip ;\
pip install -Ur requirements/prod.txt ;\
pip freeze | sort > requirements.txt ;\
cat requirements/repo-libraries.txt >> requirements.txt ;\
pip install -Ur requirements/repo-libraries.txt
update: ## Upgrade lock
poetry update

install: clean ## Install python virtrual environment
test -f venv/bin/activate || python3 -m venv $(CURRENT_ABS_DIR)/venv ;\
. venv/bin/activate ;\
pip install --upgrade pip ;\
pip install -Ur requirements.txt
unset HOME ## unset HOME because it's in the DEV .env file, will cause permissions issues
pip install poetry ;\
poetry install

install-dev: ## Install local application
. venv/bin/activate ; \
pip install -Ur requirements/dev.txt; \
pip install -e .
poetry add --dev pylint astroid
poetry install --with dev

#################################################################################
# COMMANDS - CI #
#################################################################################
ci: lint flake8 test ## CI flow

pylint: ## Linting with pylint
. venv/bin/activate && pylint --rcfile=setup.cfg src/$(PROJECT_NAME)
poetry run pylint --rcfile=setup.cfg src/$(PROJECT_NAME)

flake8: ## Linting with flake8
. venv/bin/activate && flake8 src/$(PROJECT_NAME) tests
poetry run flake8 src/$(PROJECT_NAME) tests

lint: pylint flake8 ## run all lint type scripts

test: ## Unit testing
. venv/bin/activate && pytest
poetry run pytest

mac-cov: test ## Run the coverage report and display in a browser window (mac)
@open -a "Google Chrome" htmlcov/index.html
Expand Down Expand Up @@ -131,7 +125,7 @@ tag: push ## tag image
#################################################################################

run: ## Run the project in local
. venv/bin/activate && python -m flask run -p 5002
poetry run flask run -p 5000

#################################################################################
# Self Documenting Commands #
Expand Down
2 changes: 1 addition & 1 deletion queue_services/account-mailer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
app = create_app()

if __name__ == '__main__':
server_port = os.environ.get('PORT', '5002')
server_port = os.environ.get('PORT', '8080')
app.run(debug=False, port=server_port, host='0.0.0.0')
25 changes: 25 additions & 0 deletions queue_services/account-mailer/gunicorn_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright © 2024 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The configuration for gunicorn, which picks up the
runtime options from environment variables
"""

import os


workers = int(os.environ.get('GUNICORN_PROCESSES', '1')) # pylint: disable=invalid-name
threads = int(os.environ.get('GUNICORN_THREADS', '1')) # pylint: disable=invalid-name

forwarded_allow_ips = '*' # pylint: disable=invalid-name
secure_scheme_headers = {'X-Forwarded-Proto': 'https'} # pylint: disable=invalid-name
Loading
Loading