From 0c4c15e5998b0a1720125673c4b4d30c3c04a541 Mon Sep 17 00:00:00 2001 From: raphaelrpl Date: Tue, 3 Oct 2023 09:25:37 -0300 Subject: [PATCH] :books: review examples/python docker and improve command line version --- CHANGES.rst | 4 +- bdc_collectors/cli.py | 32 +++++++++++++- bdc_collectors/version.py | 2 +- examples/Dockerfile | 88 ++++++++++++++++++++++----------------- 4 files changed, 83 insertions(+), 43 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 127473a..15eba86 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,8 +11,8 @@ Changes ======= -Version 1.0.0 (2023-10-03) --------------------------- +Version 1.0.0.dev1 (2023-10-03) +------------------------------- - Review module dependencies - Add driver for Copernicus DataSpace EcoSystem. diff --git a/bdc_collectors/cli.py b/bdc_collectors/cli.py index e18078f..e960539 100644 --- a/bdc_collectors/cli.py +++ b/bdc_collectors/cli.py @@ -27,7 +27,37 @@ from . import create_app -@click.group(cls=FlaskGroup, create_app=create_app) +def get_version(ctx, param, value): + """Retrieve the package version for command line.""" + if not value or ctx.resilient_parsing: + return + + import platform + from . import __version__ + + click.echo( + f"Python {platform.python_version()}\n" + f"BDC-Collector {__version__}", + color=ctx.color, + ) + ctx.exit() + + +version_option = click.Option( + ["--version"], + help="Show the application version.", + expose_value=False, + callback=get_version, + is_flag=True, + is_eager=True, +) + + +@click.group(cls=FlaskGroup, + create_app=create_app, + add_default_commands=False, + add_version_option=False, + params=[version_option]) def cli(): """Command line for BDC-Collectors.""" click.secho("""BDC-Collectors Copyright (C) 2023 INPE diff --git a/bdc_collectors/version.py b/bdc_collectors/version.py index 6ca450f..cd7f3e8 100644 --- a/bdc_collectors/version.py +++ b/bdc_collectors/version.py @@ -18,4 +18,4 @@ """Version information for BDC-Collectors.""" -__version__ = '1.0.0' +__version__ = '1.0.0.dev1' diff --git a/examples/Dockerfile b/examples/Dockerfile index 0920197..c2c5fee 100644 --- a/examples/Dockerfile +++ b/examples/Dockerfile @@ -1,40 +1,50 @@ -# -# This file is part of Brazil Data Cube BDC-Collectors. -# Copyright (C) 2022 INPE. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# - -FROM python:3.8.6 - -ENV START_DATE '' -ENV END_DATE '' -ENV DELTA_DAYS '' -ENV DATA_DIR '' -ENV SHP_DATA_DIR '' -ENV S2_GRID_NAME '' -ENV BDC_CREODIAS_USER '' -ENV BDC_CREODIAS_PASSWORD '' - -COPY . /app - -WORKDIR /app - -RUN pip3 install -U pip && \ - pip3 install -U setuptools && \ - pip3 install wheel && \ - pip3 install -e .[all] && \ - pip3 install fiona - +# +# This file is part of Brazil Data Cube BDC-Collectors. +# Copyright (C) 2023 INPE. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +ARG GIT_COMMIT +ARG BASE_IMAGE=python:3.11-bullseye +FROM ${BASE_IMAGE} + +ARG GIT_COMMIT + +LABEL "org.repo.maintainer"="Brazil Data Cube " +LABEL "org.repo.title"="Docker image for BDC Collectors - Examples" +LABEL "org.repo.description"="Docker image to collect data from multiple providers." +LABEL "org.repo.git_commit"="${GIT_COMMIT}" + +# Build arguments" +ARG APP_INSTALL_PATH="/opt/bdc-collectors" + +ENV START_DATE '' +ENV END_DATE '' +ENV DELTA_DAYS '' +ENV DATA_DIR '' +ENV SHP_DATA_DIR '' +ENV S2_GRID_NAME '' +ENV BDC_CREODIAS_USER '' +ENV BDC_CREODIAS_PASSWORD '' + +COPY . ${APP_INSTALL_PATH} + +WORKDIR ${APP_INSTALL_PATH} + +RUN pip3 install -U pip setuptools wheel --no-cache && \ + pip3 install -e .[docs,tests,raster] --no-cache && \ + pip3 install fiona --no-cache + CMD ["python3", "examples/download_sentinel_tile.py"] \ No newline at end of file