Skip to content

Commit b4ce3f8

Browse files
committed
updates
2 parents 3d7ba11 + e0aa784 commit b4ce3f8

File tree

8 files changed

+112
-40
lines changed

8 files changed

+112
-40
lines changed

.github/workflows/publish.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
<<<<<<< HEAD
12
name: Publish package
3+
=======
4+
# This workflow will upload a Python Package using Twine when a release is created
5+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
6+
7+
# This workflow uses actions that are not certified by GitHub.
8+
# They are provided by a third-party and are governed by
9+
# separate terms of service, privacy policy, and support
10+
# documentation.
11+
12+
name: Upload Python Package
13+
>>>>>>> e0aa78494152ccb561414e3c0595297eb7f86980
214

315
on:
416
release:
517
types: [published]
618

19+
<<<<<<< HEAD
720
jobs:
821
build:
922
runs-on: ubuntu-latest
@@ -34,4 +47,30 @@ jobs:
3447
# if: startsWith(github.ref, 'refs/tags')
3548
uses: pypa/gh-action-pypi-publish@release/v1
3649
with:
50+
=======
51+
permissions:
52+
contents: read
53+
54+
jobs:
55+
deploy:
56+
57+
runs-on: ubuntu-latest
58+
59+
steps:
60+
- uses: actions/checkout@v3
61+
- name: Set up Python
62+
uses: actions/setup-python@v3
63+
with:
64+
python-version: '3.x'
65+
- name: Install dependencies
66+
run: |
67+
python -m pip install --upgrade pip
68+
pip install build
69+
- name: Build package
70+
run: python -m build
71+
- name: Publish package
72+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
73+
with:
74+
user: __token__
75+
>>>>>>> e0aa78494152ccb561414e3c0595297eb7f86980
3776
password: ${{ secrets.PYPI_API_TOKEN }}

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ up: build ## Run docker compose service
2424

2525
down: ## Stop docker compose service
2626
docker compose down
27+
docker compose down --volumes
2728

2829
rebuild: down up ## Rebuild docker compose service
2930

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
# jupyter-pgadmin-proxy
1+
# Jupyter pgAdmin proxy
22

3-
jupyter-pgadmin-proxy provides Jupyter extension to run [pgAdmin 4](https://pypi.org/project/pgadmin4/). See also official pages for ([pgAdmin](https://www.pgadmin.org/).
3+
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/jupyter-pgadmin-proxy.svg)](https://pypi.org/project/jupyter-pgadmin-proxy/)
4+
5+
jupyter-pgadmin-proxy provides Jupyter extension to run [pgAdmin 4](https://pypi.org/project/pgadmin4/). See also official pages for [pgAdmin](https://www.pgadmin.org/).
46

57
## Installation
68

79
You can install jupyter-pgadmin-proxy inside your environment with Jupyter / Jupyterlab:
810

911
```
10-
python3 -m pip install git+https://github.com/huntdatacenter/jupyter-pgadmin-proxy.git@main
12+
python3 -m pip install jupyter-pgadmin-proxy
13+
```
14+
15+
## Build
16+
17+
```
18+
python3 -m pip install hatch
19+
20+
hatch build
21+
22+
ls -la dist/*
1123
```
1224

1325
## Development
@@ -18,6 +30,10 @@ Try `make help` to see available commands:
1830
make help
1931
```
2032

33+
```
34+
python3 -m pip install git+https://github.com/huntdatacenter/jupyter-pgadmin-proxy.git@main
35+
``
36+
2137
## Testing in docker
2238
2339
Run/rebuild local Jupyterlab service:

docker-compose.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ services:
1616
PGDATABASE: postgres
1717
PGUSER: postgres
1818
PGPASSWORD: postgres
19+
# PGADMIN_ENABLED: 'false'
1920
volumes:
2021
- "${PWD}:/home/jovyan/jupyter-pgadmin-proxy"
2122
postgres:
@@ -28,9 +29,8 @@ services:
2829
POSTGRES_USER: postgres
2930
POSTGRES_PASSWORD: postgres
3031
volumes:
31-
- db:/var/lib/postgresql/data
32+
- pgtestdb:/var/lib/postgresql/data
3233

3334
volumes:
34-
db:
35-
name: db
35+
pgtestdb: {}
3636

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "jupyter-pgadmin-proxy"
7-
version = "0.0.1"
7+
version = "0.0.2"
88
authors = [
99
{ name="Matus Kosut", email="[email protected]" },
1010
{ name="Diepiriye Okujagu", email="[email protected]" },
@@ -14,11 +14,11 @@ readme = "README.md"
1414
license = { file = "LICENSE.md" }
1515
requires-python = ">=3.8"
1616
dependencies = [
17-
"jupyter-server-proxy>=3.2.2",
17+
"jupyter-server-proxy>=3.2.2,<4.0.0",
1818
"pgadmin4",
1919
"simple-websocket",
2020
"psycopg",
21-
"uwsgi"
21+
"gunicorn",
2222
]
2323
classifiers = [
2424
"Framework :: Jupyter",

setup/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ RUN set -x \
55
&& apt-get update \
66
&& apt-get install -y curl postgresql-client
77

8-
WORKDIR /etc/pgadmin
9-
COPY setup/config_system.py /etc/pgadmin/config_system.py
10-
118
# setup package, enable classic extension, build lab extension
129
# USER "${NB_USER}"
1310
RUN mamba install -q -c conda-forge -y uwsgi simple-websocket psycopg
@@ -31,5 +28,8 @@ RUN cp /etc/jupyter/jupyter_notebook_config.py /etc/jupyter/jupyter_notebook_con
3128
COPY setup/jupyter_notebook_config.py /etc/jupyter/jupyter_notebook_config.py
3229
RUN fix-permissions /etc/jupyter
3330

31+
WORKDIR /etc/pgadmin
32+
COPY setup/config_system.py /etc/pgadmin/config_system.py
3433

3534
USER "${NB_USER}"
35+
WORKDIR "${HOME}"

setup/config_system.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424

2525
# from pgadmin.utils import env
2626

27+
28+
TRUTHY = ("true", "1", "yes", "on", "y")
29+
30+
31+
def truthy(val):
32+
return str(val).strip('"').strip("'").lower() in TRUTHY
33+
34+
2735
##########################################################################
2836
# Application settings
2937
##########################################################################
@@ -115,11 +123,11 @@
115123
# SESSION_DB_PATH, STORAGE_DIR, KERBEROS_CCACHE_DIR, and
116124
# AZURE_CREDENTIAL_CACHE_DIR
117125

118-
if (not hasattr(builtins, 'SERVER_MODE')) or builtins.SERVER_MODE is None:
119-
SERVER_MODE = True
120-
else:
121-
SERVER_MODE = builtins.SERVER_MODE
122-
# SERVER_MODE = False
126+
# if (not hasattr(builtins, 'SERVER_MODE')) or builtins.SERVER_MODE is None:
127+
# SERVER_MODE = True
128+
# else:
129+
# SERVER_MODE = builtins.SERVER_MODE
130+
SERVER_MODE = truthy(os.getenv('PGADMIN_SERVER_MODE'))
123131

124132
# HTTP headers to search for CSRF token when it is not provided in the form.
125133
# Default is ['X-CSRFToken', 'X-CSRF-Token']
@@ -334,7 +342,7 @@
334342
# Using PGPASS file
335343
# postgresql://username@host:port?options=-csearch_path=pgadmin
336344
##########################################################################
337-
CONFIG_DATABASE_URI = ''
345+
CONFIG_DATABASE_URI = ""
338346

339347
##########################################################################
340348
# User account and settings storage
@@ -584,7 +592,7 @@
584592
# Master password is used to encrypt/decrypt saved server passwords
585593
# Applicable for desktop mode only
586594
##########################################################################
587-
MASTER_PASSWORD_REQUIRED = True
595+
MASTER_PASSWORD_REQUIRED = truthy(os.getenv("MASTER_PASSWORD_REQUIRED"))
588596

589597
##########################################################################
590598

src/jupyter_pgadmin_proxy/__init__.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
import site
77

88
logging.basicConfig(level="INFO")
9-
logger = logging.getLogger("pgadmin")
9+
logger = logging.getLogger("pgAdmin4")
1010
logger.setLevel("INFO")
1111

1212

13+
TRUTHY = ("true", "1", "yes", "on", "y")
14+
15+
16+
def truthy(val):
17+
return str(val).strip('"').strip("'").lower() in TRUTHY
18+
19+
1320
def _get_env(port, base_url):
1421
"""
1522
Returns a dict containing environment settings to launch the Web App.
@@ -24,16 +31,21 @@ def _get_env(port, base_url):
2431
logger.info(f"pgAdmin ENV: {base_url}pgadmin4/")
2532

2633
default_email = os.getenv("PGADMIN_DEFAULT_EMAIL", "[email protected]")
27-
setup_email = os.getenv("PGADMIN_SETUP_EMAIL", "[email protected]")
34+
# setup_email = os.getenv("PGADMIN_SETUP_EMAIL", "[email protected]")
2835
return {
29-
"PGADMIN_SERVER_MODE": 'True',
36+
# "PGADMIN_SERVER_MODE": "True",
37+
# "PGADMIN_SETUP_EMAIL": setup_email,
38+
# "PGADMIN_SETUP_PASSWORD": ".",
3039
"PGADMIN_DEFAULT_EMAIL": default_email,
31-
"PGADMIN_SETUP_EMAIL": setup_email,
32-
"PGADMIN_SETUP_PASSWORD": "",
3340
"PGADMIN_LISTEN_PORT": str(port),
3441
"APPLICATION_ROOT": f"{base_url}pgadmin4/",
3542
"SCRIPT_NAME": f"{base_url}pgadmin4/",
3643
"REMOTE_USER": os.getenv("USER", os.getenv("NB_USER", "nobody")),
44+
"PGHOST": os.getenv("PGHOST"),
45+
"PGPORT": os.getenv("PGPORT"),
46+
"PGDATABASE": os.getenv("PGDATABASE"),
47+
"PGUSER": os.getenv("PGUSER"),
48+
"PGPASSWORD": os.getenv("PGPASSWORD"),
3749
}
3850

3951

@@ -43,7 +55,6 @@ def get_icon_path():
4355
)
4456

4557

46-
4758
def get_system_user():
4859
try:
4960
user = pwd.getpwuid(os.getuid())[0]
@@ -62,38 +73,35 @@ def run_app():
6273

6374
icon_path = get_icon_path()
6475
try:
65-
executable_name = shutil.which("pgadmin4")
76+
executable_name = shutil.which("gunicorn")
6677
except Exception:
67-
executable_name = "pgadmin4"
68-
host = "127.0.0.1"
78+
executable_name = "gunicorn"
6979
user = get_system_user()
7080
try:
7181
chdir_path = f"{site.getsitepackages()[0]}/pgadmin4"
7282
if not os.path.exists(chdir_path):
7383
chdir_path = os.path.dirname(os.path.abspath(__file__))
7484
except Exception:
7585
chdir_path = "/"
76-
logger.debug(f"[{user}] Icon_path: {icon_path}")
86+
logger.debug(f"[{user}] Icon path: {icon_path}")
7787
logger.debug(f"[{user}] Launch Command: {executable_name}")
88+
logger.debug(f"[{user}] pgAdmin path: {chdir_path}")
7889
return {
7990
"command": [
80-
# executable_name,
81-
"uwsgi",
82-
"--http-socket", "127.0.0.1:{port}",
83-
"--mount", "{base_url}pgadmin4/=pgAdmin4:app",
84-
"--chdir", chdir_path,
85-
"--manage-script-name",
86-
"--processes", "1",
87-
"--threads", "25",
88-
"--need-app",
91+
executable_name,
92+
'-b', '127.0.0.1:{port}',
93+
'-e', 'SCRIPT_NAME={base_url}pgadmin',
94+
'--chdir', chdir_path,
95+
'pgAdmin4:app',
8996
],
9097
"timeout": 300,
9198
"environment": _get_env,
9299
"absolute_url": True,
93100
# "rewrite_response": rewrite_netloc,
94-
# "request_headers_override": {"X-Script-Name": "{base_url}pgadmin4/"},
101+
# "request_headers_override": {"X-Script-Name": "{base_url}pgadmin"},
95102
"launcher_entry": {
96103
"title": "pgAdmin4",
97-
"icon_path": icon_path
104+
"icon_path": icon_path,
105+
"enabled": truthy(os.getenv("PGADMIN_ENABLED", "true")),
98106
},
99107
}

0 commit comments

Comments
 (0)