From 2a64066d5002502f83e2bec5098965be09ce70bb Mon Sep 17 00:00:00 2001 From: Vagiz Duseev Date: Tue, 15 Jun 2021 15:32:48 +0200 Subject: [PATCH] Added version and user docker image dbload --- .github/workflows/build-test-release.yml | 29 +++++++++++++++++ Dockerfile | 41 ++++++------------------ Dockerfile.dev | 36 +++++++++++++++++++++ dbload/cli.py | 24 +++++++++----- 4 files changed, 90 insertions(+), 40 deletions(-) create mode 100644 Dockerfile.dev diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml index b39fa59..42a0109 100644 --- a/.github/workflows/build-test-release.yml +++ b/.github/workflows/build-test-release.yml @@ -44,6 +44,7 @@ jobs: docker build \ --tag docker.pkg.github.com/$GITHUB_REPOSITORY/db-load-generator:${GITHUB_SHA:0:6} \ --cache-from docker.pkg.github.com/$GITHUB_REPOSITORY/db-load-generator:latest \ + -f Dockerfile.dev \ . - name: Push image to GitHub docker registry @@ -288,3 +289,31 @@ jobs: -v "$(pwd):/app" \ docker.pkg.github.com/$GITHUB_REPOSITORY/db-load-generator:${GITHUB_SHA:0:6} \ poetry publish --username __token__ --password "$PYPI_TOKEN" + + build-prod-docker-image: + name: Build docker image for users + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + needs: + - publish-to-pypi + + steps: + - uses: actions/checkout@v2 + + - name: Authenticate in GitHub docker registry + run: | + echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u $GITHUB_ACTOR --password-stdin + + - name: Pull latest cached docker image + run: | + docker pull docker.pkg.github.com/$GITHUB_REPOSITORY/dbload:latest || true + + - name: Build docker image + run: | + docker build \ + --cache-from docker.pkg.github.com/$GITHUB_REPOSITORY/dbload:latest \ + . + + - name: Push image to GitHub docker registry + run: | + docker push docker.pkg.github.com/$GITHUB_REPOSITORY/dbload:latest diff --git a/Dockerfile b/Dockerfile index bb63aa5..447d79e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,36 +1,13 @@ -FROM fedora:latest as base +FROM python:latest AS base -RUN dnf install -y \ - which \ - make \ - automake \ - gcc \ - gcc-c++ \ - kernel-devel \ - python3-devel \ - poetry \ - java-1.8.0-openjdk.x86_64 +RUN apt-get update \ + && apt-get install -y --no-install-recommends openjdk-11-jre-headless \ + && apt-get purge -y --auto-remove \ + && rm -rf /var/lib/apt/lists/* \ + && pip install db-load-generator[dramatiq] -WORKDIR /app +ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64 -COPY . . +WORKDIR /dbload -RUN poetry install - -RUN echo "export JAVA_HOME=$(dirname $(dirname $(dirname $(readlink $(readlink $(which java))))))" >> ~/.bashrc - -# RUN dnf remove -y \ -# which \ -# make \ -# automake \ -# gcc \ -# gcc-c++ \ -# kernel-devel \ -# python3-devel \ -# && dnf autoremove -y - -# RUN rm -rf /var/cache/dnf \ -# && rm -rf /var/lib/rpm \ -# rm -rf /var/lib/dnf - -CMD [ "poetry", "run", "dbload", "--help" ] +ENTRYPOINT [ "dbload" ] diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..bb63aa5 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,36 @@ +FROM fedora:latest as base + +RUN dnf install -y \ + which \ + make \ + automake \ + gcc \ + gcc-c++ \ + kernel-devel \ + python3-devel \ + poetry \ + java-1.8.0-openjdk.x86_64 + +WORKDIR /app + +COPY . . + +RUN poetry install + +RUN echo "export JAVA_HOME=$(dirname $(dirname $(dirname $(readlink $(readlink $(which java))))))" >> ~/.bashrc + +# RUN dnf remove -y \ +# which \ +# make \ +# automake \ +# gcc \ +# gcc-c++ \ +# kernel-devel \ +# python3-devel \ +# && dnf autoremove -y + +# RUN rm -rf /var/cache/dnf \ +# && rm -rf /var/lib/rpm \ +# rm -rf /var/lib/dnf + +CMD [ "poetry", "run", "dbload", "--help" ] diff --git a/dbload/cli.py b/dbload/cli.py index d003354..cee7924 100644 --- a/dbload/cli.py +++ b/dbload/cli.py @@ -25,6 +25,7 @@ from .config_singleton import get_config from .connection import get_connection from .query_result import QueryResult +from . import __version__ # Global CLI context for nested command line args @@ -101,21 +102,23 @@ def update_cli_args(kwargs) -> None: def decorate_with_common_options(f): - f = click.option("-C", "--config", help="Path to the config file.", type=click.Path(exists=True, dir_okay=False))(f) - f = click.option("-m", "--module", help="Path python module with scenarios to import.", type=str)(f) - f = click.option("-d", "--dsn", help="The database connection string for JDBC.", type=str)(f) - f = click.option("-a", "--driver-arg", help="Arguments to the driver. Can be key=value pairs or just values.", multiple=True, type=str)(f) - f = click.option("-s", "--sql", help="Paths to files with SQL queries.", multiple=True, type=click.Path(exists=True, dir_okay=False, readable=True))(f) - f = click.option("-i", "--ignore", help="Ignore errors during query executions.", is_flag=True)(f) - f = click.option("-c", "--classpath", help="Paths to libraries, including JDBC 4.0 database driver. Can include wildcard.", multiple=True, type=click.Path(exists=True))(f) - f = click.option("-D", "--driver", help="Driver class name to instantiate (example: com.ibm.db2.jcc.DB2Jcc).", type=str)(f) + f = click.version_option(__version__)(f) f = click.option("-v", "--verbose", help="Log verbosity: 3 levels from error (default) to debug. Stack them up: -vvv to get debug.", count=True)(f) f = click.option("-q", "--quiet", help="Do not print any results. Errors are still printed.", is_flag=True)(f) f = click.option("-p", "--predefined", help="Name of the predefined simulation for one of the supported databases.", type=str)(f) + f = click.option("-D", "--driver", help="Driver class name to instantiate (example: com.ibm.db2.jcc.DB2Jcc).", type=str)(f) + f = click.option("-c", "--classpath", help="Paths to libraries, including JDBC 4.0 database driver. Can include wildcard.", multiple=True, type=click.Path(exists=True))(f) + f = click.option("-i", "--ignore", help="Ignore errors during query executions.", is_flag=True)(f) + f = click.option("-s", "--sql", help="Paths to files with SQL queries.", multiple=True, type=click.Path(exists=True, dir_okay=False, readable=True))(f) + f = click.option("-a", "--driver-arg", help="Arguments to the driver. Can be key=value pairs or just values.", multiple=True, type=str)(f) + f = click.option("-d", "--dsn", help="The database connection string for JDBC.", type=str)(f) + f = click.option("-m", "--module", help="Path python module with scenarios to import.", type=str)(f) + f = click.option("-C", "--config", help="Path to the config file.", type=click.Path(exists=True, dir_okay=False))(f) return f @click.group() +@click.version_option(__version__) @decorate_with_common_options def main(**kwargs): update_cli_args(kwargs) @@ -456,5 +459,10 @@ def worker(**kwargs): sys.exit(1) +@main.command(help="Display version of dbload") +def version(): + click.echo(f"{__version__}") + + if __name__ == "__main__": main()