From e93a68586e77496d17d4585582bcb153b206713d Mon Sep 17 00:00:00 2001 From: mike dupont Date: Mon, 2 Oct 2023 09:48:16 -0400 Subject: [PATCH] work in progress still having python issues. --- .github/workflows/debug.yml | 20 ----- .github/workflows/pipeline.yml | 112 +++++++++++++++++++++++++++ .github/workflows/python-package.yml | 15 ++-- Dockerfile | 43 +++++++++- docker-compose.yml | 2 +- poetry.lock | 7 ++ pyproject.toml | 39 +++++++++- runact.sh | 4 +- 8 files changed, 209 insertions(+), 33 deletions(-) delete mode 100644 .github/workflows/debug.yml create mode 100644 .github/workflows/pipeline.yml create mode 100644 poetry.lock diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml deleted file mode 100644 index 5d63fd2..0000000 --- a/.github/workflows/debug.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Python package -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] -jobs: - debug: - runs-on: ubuntu-latest - steps: - - name: test - env: - GITHUB_PAT: ${{ secrets.PAT }} - GITHUB_1: ${{ secrets.PAT }} - DOCKERTEST: ${{ secrets.DOCKER }} - run: echo pat ${{ secrets.PAT }} docker ${{ secrets.DOCKER }} and test1 ${DOCKERTEST} and $GITHUB_1 - - name: test2 - env: - GITHUB_PAT: ${{ secrets.PAT }} - run: docker-compose -e GIHUB_PAT="${{ secrets.PAT }}" up diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000..a51aabc --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,112 @@ +name: Pipeline + +on: push + +jobs: + code-quality: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + # - name: Setup Python + # uses: actions/setup-python@v4 + # with: + # python-version: 3.10.12 + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.4.1 + virtualenvs-in-project: true + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: | + poetry install --no-interaction --no-root + - name: pylint + run: | + source .venv/bin/activate + pylint build tests + - name: black + run: | + source .venv/bin/activate + black --check . + + run-tests: + needs: code-quality + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + # - name: Setup Python + # uses: actions/setup-python@v4 + # with: + # python-version: 3.10.12 + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.4.1 + virtualenvs-in-project: true + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: | + poetry install --no-interaction --no-root + - name: Run all tests with pytest + run: | + source .venv/bin/activate + pytest --cov + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} + + publish-all-images: + needs: run-tests + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Get Git Commit Tag Name + uses: olegtarasov/get-tag@v2.1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + # - name: Setup Python + # uses: actions/setup-python@v4 + # with: + # python-version: 3.10.12 + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.4.1 + virtualenvs-in-project: true + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: | + poetry install --no-interaction --no-root + - name: Publish Image to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + source .venv/bin/activate + python -m build.publish diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 9f97959..75faa8f 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -50,18 +50,19 @@ jobs: GITHUB_REPO: "jmikedupont2/ai-ticket" run: docker-compose build - - name: Docker Compose Action echo + + - name: create openai env: GITHUB_PAT: ${{ secrets.PAT }} GITHUB_REPO: "jmikedupont2/ai-ticket" - run: echo pat ${{ secrets.PAT }} -# run: echo docker-compose up -e GITHUB_PAT=${{ secrets.PAT }} -e GITHUB_REPO="jmikedupont2/ai-ticket" - - - name: Docker Compose Action do it - #uses: meta-introspector/compose-action@main + run: | + GITHUB_PAT=${{ secrets.PAT }} GITHUB_REPO="jmikedupont2/ai-ticket" docker-compose up -d mockopenai + + - name: run autogpt env: GITHUB_PAT: ${{ secrets.PAT }} GITHUB_REPO: "jmikedupont2/ai-ticket" run: | - GITHUB_PAT=${{ secrets.PAT }} GITHUB_REPO="jmikedupont2/ai-ticket" docker-compose up + GITHUB_PAT=${{ secrets.PAT }} GITHUB_REPO="jmikedupont2/ai-ticket" docker-compose run autogpt + diff --git a/Dockerfile b/Dockerfile index ae68579..3517970 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,44 @@ -FROM python:3.10-slim +# The Poetry installation is provided through the base image. Please check the +# base image if you interested in the details. +# Base image: https://hub.docker.com/r/pfeiffermax/python-poetry +# Dockerfile: https://github.com/max-pfeiffer/python-poetry/blob/main/build/Dockerfile +ARG BASE_IMAGE +FROM ${BASE_IMAGE} +ARG APPLICATION_SERVER_PORT + +LABEL maintainer="Mike DuPont " + +ENV PYTHONUNBUFFERED=1 \ + # https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE + PYTHONDONTWRITEBYTECODE=1 \ + PYTHONPATH=/application_root \ + # https://python-poetry.org/docs/configuration/#virtualenvsin-project + POETRY_VIRTUALENVS_IN_PROJECT=true \ + POETRY_CACHE_DIR="/application_root/.cache" \ + VIRTUAL_ENVIRONMENT_PATH="/application_root/.venv" \ + APPLICATION_SERVER_PORT=$APPLICATION_SERVER_PORT +# Adding the virtual environment to PATH in order to "activate" it. +# https://docs.python.org/3/library/venv.html#how-venvs-work +ENV PATH="$VIRTUAL_ENVIRONMENT_PATH/bin:$PATH" + +# Principle of least privilege: create a new user for running the application +RUN groupadd -g 1001 python_application && \ + useradd -r -u 1001 -g python_application python_application + +# Set the WORKDIR to the application root. +# https://www.uvicorn.org/settings/#development +# https://docs.docker.com/engine/reference/builder/#workdir +WORKDIR ${PYTHONPATH} +RUN chown python_application:python_application ${PYTHONPATH} + +# Create cache directory and set permissions because user 1001 has no home +# and poetry cache directory. +# https://python-poetry.org/docs/configuration/#cache-directory +RUN mkdir ${POETRY_CACHE_DIR} && chown python_application:python_application ${POETRY_CACHE_DIR} + +# Use the unpriveledged user to run the application +USER 1001 + WORKDIR /opt/ai-ticket COPY pyproject.toml /opt/ai-ticket/ COPY setup.cfg /opt/ai-ticket/ @@ -6,7 +46,6 @@ COPY requirements.txt /opt/ai-ticket/ COPY ./src/ /opt/ai-ticket/src/ RUN pip install /opt/ai-ticket/ - RUN apt update RUN apt install -y git RUN pip install --trusted-host pypi.python.org -r requirements.txt diff --git a/docker-compose.yml b/docker-compose.yml index baeef35..73d1454 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: #tty: true # docker run -t autogpt: - entrypoint: bash -c "poetry run pip install /opt/ai-ticket && poetry run autogpt --install-plugin-deps --skip-news -y --ai-name 'meta-autogpt' --ai-role 'you will introspect autogpt and reveal its internals via reflection and comprehension' --ai-goal 'Observe your behaviour' --ai-goal 'Reflect over your outcomes' --ai-goal 'Orient yourself to your knowledge' --ai-goal 'Decide on your next step' --ai-goal 'Act on your chosen next experiment' " + entrypoint: bash -c "poetry run pip install /opt/ai-ticket && poetry run autogpt --install-plugin-deps --skip-news -y --ai-name 'meta-autogpt' --ai-role 'you will introspect autogpt and reveal its internals via reflection and comprehension' --ai-goal 'Observe your behaviour' --ai-goal 'Reflect over your outcomes' --ai-goal 'Orient yourself to your knowledge' --ai-goal 'Decide on your next step' --ai-goal 'Act on your chosen next experiment' " # uncomment thse next 3 lines for debugging #entrypoint: /bin/bash diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..4e433ab --- /dev/null +++ b/poetry.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Poetry and should not be changed by hand. +package = [] + +[metadata] +lock-version = "2.0" +python-versions = "*" +content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" diff --git a/pyproject.toml b/pyproject.toml index cfc991c..94356c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,13 @@ [build-system] +python = "^3.7" requires = [ "setuptools>=42", - "wheel" + "wheel", + "poetry-core" ] -build-backend = "setuptools.build_meta" +#build-backend = "setuptools.build_meta" +build-backend = "poetry.core.masonry.api" + [tool.black] line-length = 120 @@ -16,3 +20,34 @@ combine_as_imports = true combine_star = true known_local_folder = ["tests", "cli"] known_first_party = ["test_utils"] + +[tool.poetry] +name = "ai-ticket" +version = "0.0.1" +authors = [ + "Mike Dupont ", +] +readme = "README.md" +description = "AI ticket" + +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] +#packages = . + +# [tool.poetry.scripts] +# [tool.poetry.dependencies] +[tool.poetry.group.dev.dependencies] +python = "^3.7" +pytest = "7.4.0" +pytest-cov = "4.1.0" +coverage = "7.3.1" +requests = "2.31.0" +black = "23.7.0" +pre-commit = "3.3.3" +semver = "3.0.1" +pylint = "2.17.5" +testcontainers = "3.7.1" + diff --git a/runact.sh b/runact.sh index b9b418c..b2302a3 100644 --- a/runact.sh +++ b/runact.sh @@ -9,6 +9,8 @@ # use .secrets PAT And DOCKER act -P ubuntu-latest=localhost/my_local_act \ --verbose \ - --job python-package-build + --job code-quality + +# --job python-package-build # --pull=false \