From 319e587f299552e35142e868e5e38679a14fd26c Mon Sep 17 00:00:00 2001 From: Blair Vanderlugt Date: Wed, 7 Jul 2021 16:00:11 -0700 Subject: [PATCH] cic ussd refactor --- apps/cic-cache/.gitlab-ci.yml | 6 ++-- apps/cic-ussd/.dockerignore | 4 +++ apps/cic-ussd/.gitlab-ci.yml | 29 ++++++++++++++++-- apps/cic-ussd/docker/Dockerfile | 52 +++++++++------------------------ docker-compose.yml | 12 ++++---- 5 files changed, 54 insertions(+), 49 deletions(-) create mode 100644 apps/cic-ussd/.dockerignore diff --git a/apps/cic-cache/.gitlab-ci.yml b/apps/cic-cache/.gitlab-ci.yml index 1234a87c..c88a72d8 100644 --- a/apps/cic-cache/.gitlab-ci.yml +++ b/apps/cic-cache/.gitlab-ci.yml @@ -14,10 +14,10 @@ build-mr-cic-cache: - apps/cic-cache/**/* when: always -test-mr-cic-eth: +test-mr-cic-cache: stage: test extends: - - .cic_eth_variables + - .cic_cache_variables cache: key: files: @@ -32,7 +32,7 @@ test-mr-cic-eth: --extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple -r test_requirements.txt - export PYTHONPATH=. && pytest -x --cov=cic_cache --cov-fail-under=90 --cov-report term-missing tests - needs: ["build-mr-cic-eth"] + needs: ["build-mr-cic-cache"] rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" changes: diff --git a/apps/cic-ussd/.dockerignore b/apps/cic-ussd/.dockerignore new file mode 100644 index 00000000..a58c5dc8 --- /dev/null +++ b/apps/cic-ussd/.dockerignore @@ -0,0 +1,4 @@ +.git +.cache +.dot +**/doc \ No newline at end of file diff --git a/apps/cic-ussd/.gitlab-ci.yml b/apps/cic-ussd/.gitlab-ci.yml index 463381ae..94e8f06d 100644 --- a/apps/cic-ussd/.gitlab-ci.yml +++ b/apps/cic-ussd/.gitlab-ci.yml @@ -1,8 +1,8 @@ .cic_ussd_variables: variables: APP_NAME: cic-ussd - DOCKERFILE_PATH: $APP_NAME/docker/Dockerfile - CONTEXT: apps/ + DOCKERFILE_PATH: docker/Dockerfile + CONTEXT: apps/$APP_NAME build-mr-cic-ussd: extends: @@ -14,6 +14,31 @@ build-mr-cic-ussd: - apps/cic-ussd/**/* when: always +test-mr-cic-ussd: + stage: test + extends: + - .cic_ussd_variables + cache: + key: + files: + - test_requirements.txt + paths: + - /root/.cache/pip + image: $MR_IMAGE_TAG + script: + - cd apps/$APP_NAME/ + - > + pip install --extra-index-url https://pip.grassrootseconomics.net:8433 + --extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple + -r test_requirements.txt + - export PYTHONPATH=. && pytest -x --cov=cic_eth --cov-fail-under=90 --cov-report term-missing tests + needs: ["build-mr-cic-ussd"] + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + changes: + - apps/cic-eth/**/* + when: always + build-push-cic-ussd: extends: - .py_build_push diff --git a/apps/cic-ussd/docker/Dockerfile b/apps/cic-ussd/docker/Dockerfile index ecaa14dc..7ff4a715 100644 --- a/apps/cic-ussd/docker/Dockerfile +++ b/apps/cic-ussd/docker/Dockerfile @@ -1,14 +1,6 @@ -# FROM python:3.8.5-alpine -FROM python:3.8.6-slim-buster +# syntax = docker/dockerfile:1.2 +FROM registry.gitlab.com/grassrootseconomics/cic-base-images:python-3.8.6-dev-55da5f4e as dev -# set working directory -WORKDIR /usr/src - -# add args for installing from self-hosted packages -ARG pip_extra_index_url_flag='--extra-index-url https://pip.grassrootseconomics.net:8433' - -RUN apt-get update && \ - apt install -y gcc gnupg libpq-dev wget make g++ gnupg bash procps git # create secrets directory RUN mkdir -vp pgp/keys @@ -17,39 +9,23 @@ RUN mkdir -vp pgp/keys RUN mkdir -vp cic-ussd RUN mkdir -vp data -COPY cic-ussd/setup.cfg \ - cic-ussd/setup.py \ - cic-ussd/ +COPY requirements.txt . -COPY cic-ussd/requirements.txt \ - cic-ussd/test_requirements.txt \ - cic-ussd/ +RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \ + pip install --index-url https://pypi.org/simple \ + --extra-index-url $GITLAB_PYTHON_REGISTRY --extra-index-url $EXTRA_INDEX_URL \ + -r requirements.txt -# install requirements -RUN cd cic-ussd && \ - pip install -r requirements.txt $pip_extra_index_url_flag +COPY . . +RUN python setup.py install -# copy all necessary files -COPY cic-ussd/cic_ussd/ cic-ussd/cic_ussd/ -COPY cic-ussd/cic_ussd/db/ussd_menu.json data/ -COPY cic-ussd/scripts/ cic-ussd/scripts/ -COPY cic-ussd/states/ cic-ussd/states/ -COPY cic-ussd/transitions/ cic-ussd/transitions/ -COPY cic-ussd/var/ cic-ussd/var/ - -COPY cic-ussd/docker/db.sh \ - cic-ussd/docker/start_cic_user_tasker.sh \ - cic-ussd/docker/start_cic_user_ussd_server.sh\ - cic-ussd/docker/start_cic_user_server.sh\ - /root/ +COPY cic_ussd/db/ussd_menu.json data/ +COPY docker/*.sh . RUN chmod +x /root/*.sh -RUN cd cic-ussd && \ - pip install $pip_extra_index_url_flag . - # copy config and migration files to definitive file so they can be referenced in path definitions for running scripts -COPY cic-ussd/.config/ /usr/local/etc/cic-ussd/ -COPY cic-ussd/cic_ussd/db/migrations/ /usr/local/share/cic-ussd/alembic +COPY .config/ /usr/local/etc/cic-ussd/ +COPY cic_ussd/db/migrations/ /usr/local/share/cic-ussd/alembic -WORKDIR /root +ENTRYPOINT [] diff --git a/docker-compose.yml b/docker-compose.yml index cacb0d2f..b8ed2162 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -464,8 +464,8 @@ services: cic-user-ussd-server: build: - context: apps/ - dockerfile: cic-ussd/docker/Dockerfile + context: apps/cic-ussd + dockerfile: docker/Dockerfile environment: DATABASE_USER: grassroots DATABASE_HOST: postgres @@ -493,8 +493,8 @@ services: cic-user-server: build: - context: apps - dockerfile: cic-ussd/docker/Dockerfile + context: apps/cic-ussd + dockerfile: docker/Dockerfile environment: DATABASE_USER: grassroots DATABASE_HOST: postgres @@ -515,8 +515,8 @@ services: cic-user-tasker: build: - context: apps - dockerfile: cic-ussd/docker/Dockerfile + context: apps/cic-ussd/ + dockerfile: docker/Dockerfile environment: DATABASE_USER: grassroots DATABASE_HOST: postgres