From 89021ea018deed7306d30add5d53bd0556a8d58f Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Sun, 5 May 2024 14:44:02 -0300 Subject: [PATCH 01/15] feat: gitea workflow with Uploader check is runing, plus in server.py is checker too --- .gitea/workflows/main.yml | 12 +++++++++++- .gitignore | 2 ++ dokku_config | 35 ----------------------------------- nginx.conf.sigil | 10 ++++++++++ server.py | 27 ++++++++++++++++++--------- 5 files changed, 41 insertions(+), 45 deletions(-) delete mode 100644 dokku_config diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index 2acf65ba..c78d66b9 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -25,8 +25,18 @@ jobs: git_remote_url: 'ssh://dokku@v2.discours.io:22/discoursio-api' ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + - name: Check UPLOADER is running + id: check_container + uses: appleboy/ssh-action@master + with: + host: staging.discours.io + username: dokku + key: ${{ secrets.SSH_PRIVATE_KEY }} + script: docker ps | grep 'uploader' + continue-on-error: true + - name: Push to dokku for dev branch - if: github.ref == 'refs/heads/dev' + if: github.ref == 'refs/heads/dev' && steps.check_container.outcome == 'success' uses: dokku/github-action@master with: branch: 'dev' diff --git a/.gitignore b/.gitignore index 9041a096..6cb12890 100644 --- a/.gitignore +++ b/.gitignore @@ -151,3 +151,5 @@ poetry.lock .ruff_cache .jj .zed + +dokku_config diff --git a/dokku_config b/dokku_config deleted file mode 100644 index a9095b30..00000000 --- a/dokku_config +++ /dev/null @@ -1,35 +0,0 @@ -root@v2:~/robo_script# dokku config:show discoursio-api -=====> discoursio-api env vars -ACKEE_TOKEN: f69b4a62-79db-49f5-b8a1-4e157d4079b8 -BACKEND_URL: https://v2.discours.io -CDN_DOMAIN: cdn.discours.io -COOKIE_DOMAIN: .discours.io -DATABASE_URL: postgresql://postgres:ea4a46965ec298f75e4a28bb2057823e@172.17.0.9:5432/discoursio_db_2024_04_21 -DOKKU_APP_RESTORE: 1 -DOKKU_APP_TYPE: dockerfile -DOKKU_DOCKERFILE_PORTS: 8080 -DOKKU_PROXY_PORT: 80 -DOKKU_PROXY_SSL_PORT: 443 -FACEBOOK_OAUTH_ID: 1140141389943829 -FACEBOOK_OAUTH_KEY: 4e9db2db988151b403a43a554065d23b -FRONTEND_URL: https://discoursio-webapp-git-feature-googleoauth-discoursio.vercel.app/ -GITHUB_OAUTH_ID: b285bf5ed53a2bceb899 -GITHUB_OAUTH_KEY: b374027774e439123179265314aabf646fea1a55 -GIT_REV: fbd0e03a3396ec5d1e8c5a0cc658467cec566a6c -GOOGLE_OAUTH_ID: 648983473866-2hd6v2eqqk6hhqabfhuqq2slb2fkfvve.apps.googleusercontent.com -GOOGLE_OAUTH_KEY: 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 -JWT_SECRET_KEY: 03vntirucmw309p4p8tvuca0w4 -MAILGUN_API_KEY: key-ab6609e797cf6bea695c39079d5e1dba -MAILGUN_DOMAIN: discours.io -OAUTH_CALLBACK_URL: https://new.discours.io/confirm -OAUTH_REDIRECT_URL: https://v2.discours.io/oauth-authorize -REDIS_URL: redis://:a932edc3ec57b3df7bc3120473774b500c0ec6174e08654434986ec3f77b3e49@dokku-redis-discoursio-redis:6379 -SENTRY_DSN: https://b537b9504258427dae86502e2bb9c4ce@glitchtip.discours.io/2 -SENTRY_ID: 393bd0b9713245089fb2c1df0e45cbfc -SESSION_SECRET_KEY: PwMhr8e5ZneKuNe5 -STORJ_ACCESS_KEY: jwroxpcugy4x2t7f2zghgsqnwvaq -STORJ_BUCKET_NAME: discours-io -STORJ_END_POINT: https://gateway.storjshare.io -STORJ_SECRET_KEY: jyo6b2xc3bd65u3vw7x3gm3f3gcu4khmdrtaz2sxaez44wsd2zyum -VK_OAUTH_ID: 55L7N3U8SilJWaE1kEwr -VK_OAUTH_KEY: 782c7cce782c7cce782c7cce337b3df5447782c782c7cce1b549757d0c219fb895bde1d \ No newline at end of file diff --git a/nginx.conf.sigil b/nginx.conf.sigil index 696b9696..a05dacc5 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -64,6 +64,16 @@ server { proxy_cache_lock on; } + # Custom location block for /upload + location /connect/ { + http://upload-8080/; + {{ $proxy_settings }} + {{ $gzip_settings }} + {{ $cors_headers_options }} + {{ $cors_headers_post }} + {{ $cors_headers_get }} + } + location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 30d; # This means that the client can cache these resources for 30 days. add_header Cache-Control "public, no-transform"; diff --git a/server.py b/server.py index da1ad6b0..ebeb388e 100644 --- a/server.py +++ b/server.py @@ -1,18 +1,27 @@ +import subprocess from granian.constants import Interfaces from granian.server import Granian from services.logger import root_logger as logger from settings import PORT +def is_docker_container_running(name): + cmd = ['docker', 'ps', '-f', f'name={name}'] + output = subprocess.run(cmd, capture_output=True, text=True).stdout + return name in output + if __name__ == "__main__": logger.info("started") - granian_instance = Granian( - "main:app", - address="0.0.0.0", # noqa S104 - port=PORT, - threads=4, - websockets=False, - interface=Interfaces.ASGI, - ) - granian_instance.serve() + if is_docker_container_running('uploader'): + granian_instance = Granian( + "main:app", + address="0.0.0.0", # noqa S104 + port=PORT, + threads=4, + websockets=False, + interface=Interfaces.ASGI, + ) + granian_instance.serve() + else: + logger.info("'uploader' is not running. But very needed !!! \(^.^'\)") \ No newline at end of file From d26f8c4903f2822931fcdefe781d5bca0d14a02b Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Sun, 5 May 2024 14:51:33 -0300 Subject: [PATCH 02/15] feat: gitea workflow if uploader then stop installer --- .gitea/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index c78d66b9..d3a741a4 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -33,7 +33,6 @@ jobs: username: dokku key: ${{ secrets.SSH_PRIVATE_KEY }} script: docker ps | grep 'uploader' - continue-on-error: true - name: Push to dokku for dev branch if: github.ref == 'refs/heads/dev' && steps.check_container.outcome == 'success' From e6f88ffff0f8af75edf44f0a2be8d0ffb5595c3c Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Sun, 5 May 2024 16:40:33 -0300 Subject: [PATCH 03/15] feat: run check with dokku not cocker for find uploader --- .gitea/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index d3a741a4..058d7f5a 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -32,7 +32,7 @@ jobs: host: staging.discours.io username: dokku key: ${{ secrets.SSH_PRIVATE_KEY }} - script: docker ps | grep 'uploader' + script: dokku ps:report uploader | grep 'Processes:' | awk '{print $2}' | grep '^1$' - name: Push to dokku for dev branch if: github.ref == 'refs/heads/dev' && steps.check_container.outcome == 'success' From 98d7c522fb84ad4b5480e0ac52a0192c2b75cb11 Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Sun, 5 May 2024 16:41:39 -0300 Subject: [PATCH 04/15] debug: run check with dokku not cocker for find uploader --- .gitea/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index 058d7f5a..3fae250f 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -32,7 +32,7 @@ jobs: host: staging.discours.io username: dokku key: ${{ secrets.SSH_PRIVATE_KEY }} - script: dokku ps:report uploader | grep 'Processes:' | awk '{print $2}' | grep '^1$' + script: ps:report uploader | grep 'Processes:' | awk '{print $2}' | grep '^1$' - name: Push to dokku for dev branch if: github.ref == 'refs/heads/dev' && steps.check_container.outcome == 'success' From e4d83d35ebf58532869ef265028243eea93ea6ba Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Sun, 5 May 2024 16:44:09 -0300 Subject: [PATCH 05/15] debug: without check uploader in server.py --- server.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/server.py b/server.py index ebeb388e..f25f2982 100644 --- a/server.py +++ b/server.py @@ -1,4 +1,3 @@ -import subprocess from granian.constants import Interfaces from granian.server import Granian @@ -13,15 +12,12 @@ def is_docker_container_running(name): if __name__ == "__main__": logger.info("started") - if is_docker_container_running('uploader'): - granian_instance = Granian( - "main:app", - address="0.0.0.0", # noqa S104 - port=PORT, - threads=4, - websockets=False, - interface=Interfaces.ASGI, - ) - granian_instance.serve() - else: - logger.info("'uploader' is not running. But very needed !!! \(^.^'\)") \ No newline at end of file + granian_instance = Granian( + "main:app", + address="0.0.0.0", # noqa S104 + port=PORT, + threads=4, + websockets=False, + interface=Interfaces.ASGI, + ) + granian_instance.serve() \ No newline at end of file From 2fb21847c38e380ad78f2f8dcd058c91d9d40443 Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Sun, 5 May 2024 16:48:11 -0300 Subject: [PATCH 06/15] debug: nginx.conf.sigil right names --- nginx.conf.sigil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.conf.sigil b/nginx.conf.sigil index a05dacc5..ef1dde1f 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -66,7 +66,7 @@ server { # Custom location block for /upload location /connect/ { - http://upload-8080/; + http://uploader-8080/; {{ $proxy_settings }} {{ $gzip_settings }} {{ $cors_headers_options }} From fc033734f5fda6f9760df3e39c179fba68cf1318 Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Sun, 5 May 2024 16:55:21 -0300 Subject: [PATCH 07/15] debug: with proxy-pass in nginx to uploader --- nginx.conf.sigil | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nginx.conf.sigil b/nginx.conf.sigil index ef1dde1f..a2298880 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -65,8 +65,8 @@ server { } # Custom location block for /upload - location /connect/ { - http://uploader-8080/; + location /upload/ { + proxy_pass http://uploader-8080/; {{ $proxy_settings }} {{ $gzip_settings }} {{ $cors_headers_options }} From b3caccb78603a3d814ad50ab61ed0d84625285b2 Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Sun, 5 May 2024 23:11:31 -0300 Subject: [PATCH 08/15] debug: sv - sigil style for uploader without / on the end of the proxy_pass --- nginx.conf.sigil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.conf.sigil b/nginx.conf.sigil index a2298880..bb9a700f 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -66,7 +66,7 @@ server { # Custom location block for /upload location /upload/ { - proxy_pass http://uploader-8080/; + proxy_pass http://uploader-8080; {{ $proxy_settings }} {{ $gzip_settings }} {{ $cors_headers_options }} From 4c274eee2e2037cf99d41814bd4d45f9c8c43a2b Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Mon, 6 May 2024 02:04:55 -0300 Subject: [PATCH 09/15] debug: /upload instead of /upload/ in sigil --- nginx.conf.sigil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.conf.sigil b/nginx.conf.sigil index bb9a700f..50b623b4 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -65,7 +65,7 @@ server { } # Custom location block for /upload - location /upload/ { + location /upload { proxy_pass http://uploader-8080; {{ $proxy_settings }} {{ $gzip_settings }} From 22106ad65769ba0db875e7e84ce749643a99af40 Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Mon, 6 May 2024 02:54:58 -0300 Subject: [PATCH 10/15] debug: sv - trying different configs in nginx.sigil --- nginx.conf.sigil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.conf.sigil b/nginx.conf.sigil index 50b623b4..c86696a4 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -66,7 +66,7 @@ server { # Custom location block for /upload location /upload { - proxy_pass http://uploader-8080; + proxy_pass http://uploader:8080; {{ $proxy_settings }} {{ $gzip_settings }} {{ $cors_headers_options }} From 449f63f5409cab115a39c12d4a900bef7aaa45e1 Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Mon, 6 May 2024 02:56:40 -0300 Subject: [PATCH 11/15] debug: sv - back configs in nginx.sigil --- nginx.conf.sigil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.conf.sigil b/nginx.conf.sigil index c86696a4..50b623b4 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -66,7 +66,7 @@ server { # Custom location block for /upload location /upload { - proxy_pass http://uploader:8080; + proxy_pass http://uploader-8080; {{ $proxy_settings }} {{ $gzip_settings }} {{ $cors_headers_options }} From e38df1f9d5a5a9c98274e8056ba197d69c9b5b5f Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Mon, 6 May 2024 03:28:31 -0300 Subject: [PATCH 12/15] debug: sv - nginx sigil old fasch alot of /// around all --- nginx.conf.sigil | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nginx.conf.sigil b/nginx.conf.sigil index 50b623b4..a2298880 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -65,8 +65,8 @@ server { } # Custom location block for /upload - location /upload { - proxy_pass http://uploader-8080; + location /upload/ { + proxy_pass http://uploader-8080/; {{ $proxy_settings }} {{ $gzip_settings }} {{ $cors_headers_options }} From bf9e571cd8a090897e9c4cdbd11e55e480772805 Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Mon, 6 May 2024 04:07:07 -0300 Subject: [PATCH 13/15] feat: sv - nginx sigil with /upload --- nginx.conf.sigil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.conf.sigil b/nginx.conf.sigil index a2298880..941b5652 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -65,7 +65,7 @@ server { } # Custom location block for /upload - location /upload/ { + location /upload { proxy_pass http://uploader-8080/; {{ $proxy_settings }} {{ $gzip_settings }} From ab6dcde170fc82f7092373eeaf02c44c66fe5eff Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Mon, 6 May 2024 04:18:24 -0300 Subject: [PATCH 14/15] feat: sv - nginx sigil with /upload and now / on the end of proxy-pass --- nginx.conf.sigil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.conf.sigil b/nginx.conf.sigil index 941b5652..50b623b4 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -66,7 +66,7 @@ server { # Custom location block for /upload location /upload { - proxy_pass http://uploader-8080/; + proxy_pass http://uploader-8080; {{ $proxy_settings }} {{ $gzip_settings }} {{ $cors_headers_options }} From 2a08e6204e63e4d218f70f9bb21eb19765e457c9 Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Mon, 6 May 2024 04:20:18 -0300 Subject: [PATCH 15/15] feat: sv - nginx sigil with /upload --- nginx.conf.sigil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.conf.sigil b/nginx.conf.sigil index 50b623b4..941b5652 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -66,7 +66,7 @@ server { # Custom location block for /upload location /upload { - proxy_pass http://uploader-8080; + proxy_pass http://uploader-8080/; {{ $proxy_settings }} {{ $gzip_settings }} {{ $cors_headers_options }}