Skip to content

Commit

Permalink
Merge pull request #45 from geoadmin/develop
Browse files Browse the repository at this point in the history
New Release v3.0.0 - #major
  • Loading branch information
ltshb authored May 17, 2022
2 parents 3c9b145 + dd2e258 commit 864e661
Show file tree
Hide file tree
Showing 25 changed files with 1,061 additions and 1,173 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ tests/report

# files for local testing
logs

.vscode
4 changes: 4 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,13 @@ function-naming-style=snake_case
good-names=i,
j,
k,
m,
n,
db,
ex,
fd,
Run,
assertRedirects,
_

# Good variable names regexes, separated by a comma. If names match any regex,
Expand Down
6 changes: 3 additions & 3 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[style]
based_on_style=google
# Put closing brackets on a separate line, dedent, if the bracketed
# Put closing brackets on a separate line, dedented, if the bracketed
# expression can't fit in a single line. Applies to all kinds of brackets,
# including function definitions and calls. For example:
#
# config = {
# 'key1': 'value1',
# 'key2': 'value2',
# } # <--- this bracket is dedent and on a separate line
# } # <--- this bracket is dedented and on a separate line
#
# time_series = self.remote_client.query_entity_counters(
# entity='dev3246.region1',
# key='dns.query_latency_tcp',
# transform=Transformation.AVERAGE(window=timedelta(seconds=60)),
# start_ts=now()-timedelta(days=3),
# end_ts=now(),
# ) # <--- this bracket is dedent and on a separate line
# ) # <--- this bracket is dedented and on a separate line
dedent_closing_brackets=True
coalesce_brackets=True

Expand Down
10 changes: 4 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Buster slim python 3.7 base image.
FROM python:3.7-slim-buster
ENV HTTP_PORT 8080
FROM python:3.9-slim-buster
RUN groupadd -r geoadmin && useradd -r -s /bin/false -g geoadmin geoadmin


Expand All @@ -19,22 +17,22 @@ RUN cd /tmp && \

COPY "./" "/app/"


ARG GIT_HASH=unknown
ARG GIT_BRANCH=unknown
ARG GIT_DIRTY=""
ARG VERSION=unknown
ARG AUTHOR=unknown
ARG HTTP_PORT=5000
LABEL git.hash=$GIT_HASH
LABEL git.branch=$GIT_BRANCH
LABEL git.dirty="$GIT_DIRTY"
LABEL version=$VERSION
LABEL author=$AUTHOR

# Overwrite the version.py from source with the actual version
RUN echo "APP_VERSION = '$VERSION'" > /app/app/version.py
RUN echo "APP_VERSION = '$VERSION'" > /app/app/version.py && \
chown -R geoadmin:geoadmin /app

RUN chown -R geoadmin:geoadmin /app
USER geoadmin

EXPOSE $HTTP_PORT
Expand Down
59 changes: 20 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,17 @@ SERVICE_NAME := service-shortlink

CURRENT_DIR := $(shell pwd)
INSTALL_DIR := $(shell pipenv --venv)
HTTP_PORT ?= 5000
PYTHON_LOCAL_DIR := $(CURRENT_DIR)/build/local
PYTHON_FILES := $(shell find ./* -type f -name "*.py" -print)
TEST_REPORT_DIR := $(CURRENT_DIR)/tests/report
TEST_REPORT_FILE := nose2-junit.xml

# general targets timestamps
TIMESTAMPS = .timestamps
REQUIREMENTS_TIMESTAMP = $(TIMESTAMPS)/.requirements.timestamp
DEV_REQUIREMENTS_TIMESTAMP = $(TIMESTAMPS)/.dev-requirements.timestamps
LOGS_DIR = $(PWD)/logs


# PIPENV files
PIP_FILE = Pipfile
PIP_FILE_LOCK = Pipfile.lock

# default configuration
HTTP_PORT ?= 8080
HTTP_PORT ?= 5000

# Commands

Expand Down Expand Up @@ -63,8 +55,7 @@ help:
@echo
@echo "Possible targets:"
@echo -e " \033[1mBUILD TARGETS\033[0m "
@echo "- setup Create the python virtual environment and activate it"
@echo "- dev Create the python virtual environment with developper tools and activate it"
@echo "- setup Create the python virtual environment with developper tools and activate it"
@echo "- ci Create the python virtual environment and install requirements based on the Pipfile.lock"
@echo -e " \033[1mFORMATING, LINTING AND TESTING TOOLS TARGETS\033[0m "
@echo "- format Format the python source code"
Expand All @@ -87,31 +78,27 @@ help:

# Build targets. Calling setup is all that is needed for the local files to be installed as needed.

.PHONY: dev
dev: $(DEV_REQUIREMENTS_TIMESTAMP)
pipenv shell


.PHONY: setup
setup: $(REQUIREMENTS_TIMESTAMP)
setup:
pipenv install --dev
pipenv shell

.PHONY: ci
ci: $(TIMESTAMPS) $(PIP_FILE) $(PIP_FILE_LOCK)
ci:
# Create virtual env with all packages for development using the Pipfile.lock
pipenv sync --dev

# linting target, calls upon yapf to make sure your code is easier to read and respects some conventions.

.PHONY: format
format: $(DEV_REQUIREMENTS_TIMESTAMP)
format:
$(YAPF_CMD) -p -i --style .style.yapf $(PYTHON_FILES)
$(ISORT_CMD) $(PYTHON_FILES)



.PHONY: lint
lint: $(DEV_REQUIREMENTS_TIMESTAMP)
lint:
$(PYLINT_CMD) $(PYTHON_FILES)


Expand All @@ -120,17 +107,17 @@ format-lint: format lint


.PHONY: test
test: $(DEV_REQUIREMENTS_TIMESTAMP)
test:
mkdir -p $(TEST_REPORT_DIR)
ENV_FILE=.env.testing $(NOSE_CMD) -c tests/unittest.cfg -v --junit-xml-path $(TEST_REPORT_DIR)/$(TEST_REPORT_FILE) -s tests/

# Serve targets. Using these will run the application on your local machine. You can either serve with a wsgi front (like it would be within the container), or without.
.PHONY: serve
serve: clean_logs $(LOGS_DIR) $(REQUIREMENTS_TIMESTAMP)
serve: clean_logs $(LOGS_DIR)
ENV_FILE=.env.default LOGS_DIR=$(LOGS_DIR) FLASK_APP=service_launcher FLASK_DEBUG=1 $(FLASK_CMD) run --host=0.0.0.0 --port=$(HTTP_PORT)

.PHONY: gunicornserve
gunicornserve: clean_logs $(LOGS_DIR) $(REQUIREMENTS_TIMESTAMP)
gunicornserve: clean_logs $(LOGS_DIR)
ENV_FILE=.env.default LOGS_DIR=$(LOGS_DIR) ${PYTHON_CMD} wsgi.py

# Docker related functions.
Expand All @@ -145,7 +132,9 @@ dockerbuild:
--build-arg GIT_BRANCH="$(GIT_BRANCH)" \
--build-arg GIT_DIRTY="$(GIT_DIRTY)" \
--build-arg VERSION="$(GIT_TAG)" \
--build-arg AUTHOR="$(AUTHOR)" -t $(DOCKER_IMG_LOCAL_TAG) .
--build-arg HTTP_PORT="$(HTTP_PORT)" \
--build-arg AUTHOR="$(AUTHOR)" \
-t $(DOCKER_IMG_LOCAL_TAG) .

.PHONY: dockerpush
dockerpush: dockerbuild
Expand All @@ -154,7 +143,13 @@ dockerpush: dockerbuild

.PHONY: dockerrun
dockerrun: clean_logs dockerbuild $(LOGS_DIR)
docker run -it -p 5000:8080 --network=host --env-file=.env.default $(DOCKER_IMG_LOCAL_TAG) --mount type=bind,source="${LOGS_DIR}",target=/logs
docker run \
-it \
--network=host \
--env-file=.env.default \
--env LOGS_DIR=/logs \
--mount type=bind,source="${LOGS_DIR}",target=/logs \
$(DOCKER_IMG_LOCAL_TAG)


# Cleaning functions. clean_venv will only remove the virtual environment, while clean will also remove the local python installation.
Expand All @@ -174,23 +169,9 @@ clean: clean_venv clean_logs
@# clean python cache files
find . -name __pycache__ -type d -print0 | xargs -I {} -0 rm -rf "{}"
rm -rf $(TEST_REPORT_DIR)
rm -rf $(TIMESTAMPS)

# Actual builds targets with dependencies

$(TIMESTAMPS):
mkdir -p $(TIMESTAMPS)


$(REQUIREMENTS_TIMESTAMP): $(TIMESTAMPS) $(LOGS_DIR) $(PIP_FILE) $(PIP_FILE_LOCK)
pipenv install
@touch $(REQUIREMENTS_TIMESTAMP)


$(DEV_REQUIREMENTS_TIMESTAMP): $(TIMESTAMPS) $(LOGS_DIR) $(PIP_FILE) $(PIP_FILE_LOCK)
pipenv install --dev
@touch $(DEV_REQUIREMENTS_TIMESTAMP)


$(LOGS_DIR):
mkdir -p -m=777 $(LOGS_DIR)
23 changes: 11 additions & 12 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ verify_ssl = true
name = "pypi"

[packages]
boto3 = "~=1.14.51"
boto3 = "~=1.23.0"
logging-utilities = ">=1.2.3,~=1.2"
Flask = "~=2.0"
gevent = "~=20.9.0"
gunicorn = "~=19.9.0"
Flask = "~=2.1.0"
gevent = "~=21.12.0"
gunicorn = "~=20.1.0"
PyYAML = ">=5.4"
moto = "~=2.2.13"
python-dotenv = "~=0.19"
validators = "~=0.18.2"
python-dotenv = "~=0.20.0"
validators = "~=0.19.0"

[dev-packages]
flask-testing = "~=0.8.0"
yapf = "~=0.30.0"
nose2 = "~=0.9.2"
pylint = "~=2.5.3"
pylint-flask = "~=0.6"
moto = "~=3.1.9"
nose2 = "*"
pylint = "*"
pylint-flask = "*"

[requires]
python_version = "3.7"
python_version = "3.9"
Loading

0 comments on commit 864e661

Please sign in to comment.