diff --git a/Makefile b/Makefile index cb26f04..4462b90 100644 --- a/Makefile +++ b/Makefile @@ -2,20 +2,26 @@ REGISTRY_NAME=registry.runcible.io FRONTEND_IMAGE_NAME=$(REGISTRY_NAME)/demo-helm-frontend FRONTEND_IMAGE_VERSION=1.1.0 BACKEND_IMAGE_NAME=$(REGISTRY_NAME)/demo-helm-backend -BACKEND_IMAGE_VERSION=1.1.0 +BACKEND_IMAGE_VERSION=1.1.0-dev push-app-image: build-app-image docker push $(FRONTEND_IMAGE_NAME):$(FRONTEND_IMAGE_VERSION) build-app-image: - docker build -t $(FRONTEND_IMAGE_NAME):$(FRONTEND_IMAGE_VERSION) ./app/app + docker build -t $(FRONTEND_IMAGE_NAME):$(FRONTEND_IMAGE_VERSION) ./app push-backend-image: build-backend-image docker push $(BACKEND_IMAGE_NAME):$(BACKEND_IMAGE_VERSION) build-backend-image: - docker build -t $(BACKEND_IMAGE_NAME):$(BACKEND_IMAGE_VERSION) ./app/backend + docker build -t $(BACKEND_IMAGE_NAME):$(BACKEND_IMAGE_VERSION) ./backend -check: +update-backend-deps: + pip-compile -o backend/requirements.txt backend/requirements.in + +sync-virtualenv: + pip-sync dev_requirements.txt backend/requirements.txt + +check-images: echo $(FRONTEND_IMAGE_NAME):$(FRONTEND_IMAGE_VERSION) echo $(BACKEND_IMAGE_NAME):$(BACKEND_IMAGE_VERSION) diff --git a/app/app/.dockerignore b/app/.dockerignore similarity index 100% rename from app/app/.dockerignore rename to app/.dockerignore diff --git a/app/app/.gitignore b/app/.gitignore similarity index 100% rename from app/app/.gitignore rename to app/.gitignore diff --git a/app/app/.vscode/extensions.json b/app/.vscode/extensions.json similarity index 100% rename from app/app/.vscode/extensions.json rename to app/.vscode/extensions.json diff --git a/app/app/Dockerfile b/app/Dockerfile similarity index 100% rename from app/app/Dockerfile rename to app/Dockerfile diff --git a/app/app/README.md b/app/README.md similarity index 100% rename from app/app/README.md rename to app/README.md diff --git a/app/backend/requirements.txt b/app/backend/requirements.txt deleted file mode 100644 index c24781d..0000000 --- a/app/backend/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -flask==2.0.2 -gunicorn==20.1.0 -flask-cors==3.0.10 \ No newline at end of file diff --git a/app/app/index.html b/app/index.html similarity index 100% rename from app/app/index.html rename to app/index.html diff --git a/app/app/package-lock.json b/app/package-lock.json similarity index 100% rename from app/app/package-lock.json rename to app/package-lock.json diff --git a/app/app/package.json b/app/package.json similarity index 100% rename from app/app/package.json rename to app/package.json diff --git a/app/app/postcss.config.js b/app/postcss.config.js similarity index 100% rename from app/app/postcss.config.js rename to app/postcss.config.js diff --git a/app/app/public/favicon.ico b/app/public/favicon.ico similarity index 100% rename from app/app/public/favicon.ico rename to app/public/favicon.ico diff --git a/app/app/src/App.vue b/app/src/App.vue similarity index 100% rename from app/app/src/App.vue rename to app/src/App.vue diff --git a/app/app/src/assets/logo.png b/app/src/assets/logo.png similarity index 100% rename from app/app/src/assets/logo.png rename to app/src/assets/logo.png diff --git a/app/app/src/components/HelloWorld.vue b/app/src/components/HelloWorld.vue similarity index 100% rename from app/app/src/components/HelloWorld.vue rename to app/src/components/HelloWorld.vue diff --git a/app/app/src/index.css b/app/src/index.css similarity index 100% rename from app/app/src/index.css rename to app/src/index.css diff --git a/app/app/src/main.js b/app/src/main.js similarity index 100% rename from app/app/src/main.js rename to app/src/main.js diff --git a/app/app/src/services/AppService.js b/app/src/services/AppService.js similarity index 100% rename from app/app/src/services/AppService.js rename to app/src/services/AppService.js diff --git a/app/app/tailwind.config.js b/app/tailwind.config.js similarity index 100% rename from app/app/tailwind.config.js rename to app/tailwind.config.js diff --git a/app/app/vite.config.js b/app/vite.config.js similarity index 100% rename from app/app/vite.config.js rename to app/vite.config.js diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..7df1d53 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1 @@ +requirements.in diff --git a/app/backend/Dockerfile b/backend/Dockerfile similarity index 89% rename from app/backend/Dockerfile rename to backend/Dockerfile index ffac877..8a997ca 100644 --- a/app/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,5 +1,5 @@ # Base Image -FROM python:3.7.3-stretch +FROM python:3.10.0-buster ENV APP_HOME=/opt/app @@ -16,7 +16,7 @@ COPY requirements.txt . RUN pip install --no-cache -r requirements.txt # Install app -COPY app.py . +COPY app.py settings.py ./ # Chown all the files to the app user RUN chown -R app:app $APP_HOME diff --git a/app/backend/app.py b/backend/app.py similarity index 99% rename from app/backend/app.py rename to backend/app.py index e692a3d..bd5014c 100644 --- a/app/backend/app.py +++ b/backend/app.py @@ -7,6 +7,7 @@ cors = CORS(app) __version__ = "1.0.0" + @app.route("/ping") @app.route("/") def pong(): diff --git a/backend/requirements.in b/backend/requirements.in new file mode 100644 index 0000000..550ec13 --- /dev/null +++ b/backend/requirements.in @@ -0,0 +1,4 @@ +flask==2.0.2 +psycopg-binary==3.0.4 +gunicorn==20.1.0 +flask-cors==3.0.10 diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..2ef436d --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,31 @@ +# +# This file is autogenerated by pip-compile with python 3.8 +# To update, run: +# +# pip-compile --output-file=backend/requirements.txt backend/requirements.in +# +click==8.0.3 + # via flask +flask==2.0.2 + # via + # -r backend/requirements.in + # flask-cors +flask-cors==3.0.10 + # via -r backend/requirements.in +gunicorn==20.1.0 + # via -r backend/requirements.in +itsdangerous==2.0.1 + # via flask +jinja2==3.0.3 + # via flask +markupsafe==2.0.1 + # via jinja2 +psycopg-binary==3.0.4 + # via -r backend/requirements.in +six==1.16.0 + # via flask-cors +werkzeug==2.0.2 + # via flask + +# The following packages are considered to be unsafe in a requirements file: +# setuptools diff --git a/backend/settings.py b/backend/settings.py new file mode 100644 index 0000000..71c400e --- /dev/null +++ b/backend/settings.py @@ -0,0 +1,27 @@ +import os + + +def build_postgres_uri( + host, user, dbname, port, sslmode=None, passwd=None, params=None +): + """Builds a PostgreSQL uri. + + See https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING for additional details. + """ + + if passwd: + uri = f"postgresql://{user}:{passwd}@{host}:{port}/{dbname}" + else: + uri = f"postgresql://{user}@{host}:{port}/{dbname}" + if sslmode: + uri = f"{uri}?sslmode={sslmode}" + return uri + + +POSTGRES_HOST = os.getenv("POSTGRES_HOST") +POSTGRES_USER = os.getenv("POSTGRES_USER") +POSTGRES_APP_DATABASE = os.getenv("POSTGRES_APP_DATABASE") +POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD") +POSTGRES_PORT = os.getenv("POSTGRES_PORT", default="5432") +POSTGRES_SSL_MODE = os.getenv("POSTGRES_SSL_MODE", default="prefer") +POSTGRES_PARAMS = os.getenv("POSTGRES_PARAMS") diff --git a/dev_requirements.in b/dev_requirements.in new file mode 100644 index 0000000..650b4ac --- /dev/null +++ b/dev_requirements.in @@ -0,0 +1,3 @@ +black==21.10b0 +pip-tools==6.4.0 +pytest==6.2.5 \ No newline at end of file diff --git a/dev_requirements.txt b/dev_requirements.txt new file mode 100644 index 0000000..f397ed0 --- /dev/null +++ b/dev_requirements.txt @@ -0,0 +1,52 @@ +# +# This file is autogenerated by pip-compile with python 3.8 +# To update, run: +# +# pip-compile dev_requirements.in +# +attrs==21.2.0 + # via pytest +black==21.10b0 + # via -r dev_requirements.in +click==8.0.3 + # via + # black + # pip-tools +iniconfig==1.1.1 + # via pytest +mypy-extensions==0.4.3 + # via black +packaging==21.2 + # via pytest +pathspec==0.9.0 + # via black +pep517==0.12.0 + # via pip-tools +pip-tools==6.4.0 + # via -r dev_requirements.in +platformdirs==2.4.0 + # via black +pluggy==1.0.0 + # via pytest +py==1.11.0 + # via pytest +pyparsing==2.4.7 + # via packaging +pytest==6.2.5 + # via -r dev_requirements.in +regex==2021.11.10 + # via black +toml==0.10.2 + # via pytest +tomli==1.2.2 + # via + # black + # pep517 +typing-extensions==4.0.0 + # via black +wheel==0.37.0 + # via pip-tools + +# The following packages are considered to be unsafe in a requirements file: +# pip +# setuptools diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/backend/__init__.py b/tests/unit/backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/backend/test_settings.py b/tests/unit/backend/test_settings.py new file mode 100644 index 0000000..282f303 --- /dev/null +++ b/tests/unit/backend/test_settings.py @@ -0,0 +1,56 @@ +import pytest + +from backend.settings import build_postgres_uri + + +@pytest.mark.parametrize( + "kwargs,expected", + [ + # No password / No SSL + ( + { + "host": "localhost", + "user": "superman", + "port": "5432", + "dbname": "sample", + }, + "postgresql://superman@localhost:5432/sample", + ), + # No password / with SSL + ( + { + "host": "my-postgres.hostname.io", + "user": "superman", + "port": "5432", + "dbname": "sample", + "sslmode": "prefer", + }, + "postgresql://superman@my-postgres.hostname.io:5432/sample?sslmode=prefer", + ), + # No password / no SSL + ( + { + "host": "my-postgres.hostname.io", + "user": "superman", + "passwd": "supersecret", + "port": "5432", + "dbname": "sample", + }, + "postgresql://superman:supersecret@my-postgres.hostname.io:5432/sample", + ), + # password / SSL + ( + { + "host": "254.254.254.254", + "user": "superman", + "passwd": "supersecret", + "port": "15432", + "dbname": "sample", + }, + "postgresql://superman:supersecret@254.254.254.254:15432/sample", + ), + ], +) +def test_build_postgres_uri(kwargs, expected): + result = build_postgres_uri(**kwargs) + assert result == expected