feat: initialize Django payment service project structure, configurations, and CI/CD workflow
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 45s

This commit is contained in:
vickytechkey 2026-10-18 20:55:45 +05:30
parent c843bcae99
commit 30576a9c6e
18 changed files with 349 additions and 54 deletions

View file

@ -33,23 +33,24 @@ jobs:
"logs_collected": { "logs_collected": {
"files": { "files": {
"collect_list": [ "collect_list": [
{ "file_path": "/home/ubuntu/searchengine/logs/app.log", "log_group_name": "/searchengine/app", "log_stream_name": "{instance_id}", "retention_in_days": 30 }, { "file_path": "/home/ubuntu/paymentservice/logs/app.log", "log_group_name": "/paymentservice/app", "log_stream_name": "{instance_id}", "retention_in_days": 30 },
{ "file_path": "/home/ubuntu/searchengine/logs/error.log", "log_group_name": "/searchengine/error", "log_stream_name": "{instance_id}", "retention_in_days": 30 }, { "file_path": "/home/ubuntu/paymentservice/logs/error.log", "log_group_name": "/paymentservice/error", "log_stream_name": "{instance_id}", "retention_in_days": 30 },
{ "file_path": "/home/ubuntu/searchengine/logs/requests.log", "log_group_name": "/searchengine/requests", "log_stream_name": "{instance_id}", "retention_in_days": 30 }, { "file_path": "/home/ubuntu/paymentservice/logs/requests.log", "log_group_name": "/paymentservice/requests", "log_stream_name": "{instance_id}", "retention_in_days": 30 },
{ "file_path": "/home/ubuntu/searchengine/logs/gunicorn-access.log", "log_group_name": "/searchengine/gunicorn-access", "log_stream_name": "{instance_id}", "retention_in_days": 30 }, { "file_path": "/home/ubuntu/paymentservice/logs/gunicorn-access.log", "log_group_name": "/paymentservice/gunicorn-access", "log_stream_name": "{instance_id}", "retention_in_days": 30 },
{ "file_path": "/home/ubuntu/searchengine/logs/gunicorn-error.log", "log_group_name": "/searchengine/gunicorn-error", "log_stream_name": "{instance_id}", "retention_in_days": 30 } { "file_path": "/home/ubuntu/paymentservice/logs/gunicorn-error.log", "log_group_name": "/paymentservice/gunicorn-error", "log_stream_name": "{instance_id}", "retention_in_days": 30 }
] ]
} }
} }
} }
} }
EOF EOF
cat << 'EOF' > tmp/nginx-proxy.conf cat << 'EOF' > tmp/nginx-proxy.conf
server { server {
server_name betasearch-api.tradhox.com search-api.tradhox.com; server_name betapayments.tradhox.com;
location / { location / {
proxy_pass http://127.0.0.1:8087; proxy_pass http://127.0.0.1:8088;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@ -57,15 +58,15 @@ jobs:
} }
listen 443 ssl; listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/betapartner-api.tradhox.com/fullchain.pem; ssl_certificate /etc/letsencrypt/live/betapayments.tradhox.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/betapartner-api.tradhox.com/privkey.pem; ssl_certificate_key /etc/letsencrypt/live/betapayments.tradhox.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf; include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
} }
server { server {
listen 80; listen 80;
server_name betasearch-api.tradhox.com search-api.tradhox.com; server_name betapayments.tradhox.com;
return 301 https://$host$request_uri; return 301 https://$host$request_uri;
} }
EOF EOF
@ -82,7 +83,7 @@ jobs:
chmod 600 ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa
# Copy app archive and configuration files # Copy app archive and configuration files
scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa app.tar.gz tmp/amazon-cloudwatch-agent.json tmp/nginx-proxy.conf searchengine.service ${{ secrets.BETA_EC2_USERNAME }}@${{ secrets.BETA_EC2_HOST }}:/tmp/ scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa app.tar.gz tmp/amazon-cloudwatch-agent.json tmp/nginx-proxy.conf paymentservice.service ${{ secrets.BETA_EC2_USERNAME }}@${{ secrets.BETA_EC2_HOST }}:/tmp/
# Execute deployment commands on remote server # Execute deployment commands on remote server
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.BETA_EC2_USERNAME }}@${{ secrets.BETA_EC2_HOST }} << 'EOF' ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.BETA_EC2_USERNAME }}@${{ secrets.BETA_EC2_HOST }} << 'EOF'
@ -90,61 +91,50 @@ jobs:
# ── 1. Install Host Dependencies ────────────────────────────── # ── 1. Install Host Dependencies ──────────────────────────────
sudo apt-get update sudo apt-get update
sudo apt-get install -y python3-pip python3-venv python3-dev pkg-config libpq-dev build-essential nginx sudo apt-get install -y python3-pip python3-venv python3-dev pkg-config libpq-dev build-essential nginx certbot python3-certbot-nginx
# ── 2. Install Typesense Server Binary (Arch Detected) ───────── # ── 2. Extract codebase to target directory ───────────────────
if ! command -v typesense-server &> /dev/null; then sudo mkdir -p /home/ubuntu/paymentservice
ARCH=$(dpkg --print-architecture) sudo chown -R ubuntu:ubuntu /home/ubuntu/paymentservice
echo "Installing Typesense Server v27.1 for architecture: ${ARCH}..." tar -xzf /tmp/app.tar.gz -C /home/ubuntu/paymentservice
curl -O https://dl.typesense.org/releases/27.1/typesense-server-27.1-${ARCH}.deb mkdir -p /home/ubuntu/paymentservice/logs
sudo dpkg -i typesense-server-27.1-${ARCH}.deb sudo chown -R ubuntu:ubuntu /home/ubuntu/paymentservice/logs
rm -f typesense-server-27.1-${ARCH}.deb
fi
# Ensure Typesense directory & config exists # ── 3. Set up python virtual environment & dependencies ────────
sudo mkdir -p /var/lib/typesense cd /home/ubuntu/paymentservice
cat << 'TYPESENSE_CONF' | sudo tee /etc/typesense/typesense-server.ini
api-key = vignesh_typesense_master_key_2026
data-dir = /var/lib/typesense
log-dir = /var/log/typesense
api-port = 8108
listen-address = 127.0.0.1
TYPESENSE_CONF
sudo systemctl enable typesense-server
sudo systemctl restart typesense-server || true
# ── 3. Extract codebase to target directory ───────────────────
sudo mkdir -p /home/ubuntu/searchengine
sudo chown -R ubuntu:ubuntu /home/ubuntu/searchengine
tar -xzf /tmp/app.tar.gz -C /home/ubuntu/searchengine
mkdir -p /home/ubuntu/searchengine/logs
sudo chown -R ubuntu:ubuntu /home/ubuntu/searchengine/logs
# ── 4. Set up python virtual environment & dependencies ────────
cd /home/ubuntu/searchengine
python3 -m venv venv python3 -m venv venv
source venv/bin/activate source venv/bin/activate
pip install --upgrade pip pip install --upgrade pip
pip install -r requirements.txt pip install -r requirements.txt
python manage.py migrate --noinput python manage.py migrate --noinput
# ── 5. Systemd Service Deployment ────────────────────────────── # ── 4. Systemd Service Deployment ──────────────────────────────
sudo cp /tmp/searchengine.service /etc/systemd/system/searchengine.service sudo cp /tmp/paymentservice.service /etc/systemd/system/paymentservice.service
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable searchengine.service sudo systemctl enable paymentservice.service
sudo systemctl restart searchengine.service || { sudo systemctl restart paymentservice.service || {
echo "searchengine.service failed to restart! Checking journalctl:" echo "paymentservice.service failed to restart! Checking journalctl:"
sudo journalctl -u searchengine.service -n 50 --no-pager sudo journalctl -u paymentservice.service -n 50 --no-pager
exit 1 exit 1
} }
# ── 6. Nginx Config ─────────────────────────────────────────── # ── 5. Ensure SSL Certificate Exists for betapayments.tradhox.com ─
if [ -f "/etc/letsencrypt/live/betasearch-api.tradhox.com/fullchain.pem" ]; then if [ ! -d "/etc/letsencrypt/live/betapayments.tradhox.com" ]; then
sed -i 's|/etc/letsencrypt/live/betapartner-api.tradhox.com|/etc/letsencrypt/live/betasearch-api.tradhox.com|g' /tmp/nginx-proxy.conf echo "Requesting SSL certificate for betapayments.tradhox.com..."
sudo systemctl stop nginx || true
sudo certbot certonly --standalone -d betapayments.tradhox.com --non-interactive --agree-tos --register-unsafely-without-email || true
sudo systemctl start nginx || true
fi fi
sudo cp /tmp/nginx-proxy.conf /etc/nginx/sites-available/searchengine
sudo ln -sf /etc/nginx/sites-available/searchengine /etc/nginx/sites-enabled/searchengine # Fallback if certificate was not created
if [ ! -f "/etc/letsencrypt/live/betapayments.tradhox.com/fullchain.pem" ]; then
echo "Warning: betapayments.tradhox.com cert not present, falling back to existing partner cert temporarily..."
sed -i 's|/etc/letsencrypt/live/betapayments.tradhox.com|/etc/letsencrypt/live/betapartner-api.tradhox.com|g' /tmp/nginx-proxy.conf
fi
# ── 6. Nginx Config ───────────────────────────────────────────
sudo cp /tmp/nginx-proxy.conf /etc/nginx/sites-available/paymentservice
sudo ln -sf /etc/nginx/sites-available/paymentservice /etc/nginx/sites-enabled/paymentservice
sudo nginx -t && sudo systemctl reload nginx sudo nginx -t && sudo systemctl reload nginx
# ── 7. CloudWatch Agent Config ──────────────────────────────── # ── 7. CloudWatch Agent Config ────────────────────────────────
@ -152,5 +142,5 @@ jobs:
sudo cp /tmp/amazon-cloudwatch-agent.json /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json sudo cp /tmp/amazon-cloudwatch-agent.json /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
sudo systemctl restart amazon-cloudwatch-agent || true sudo systemctl restart amazon-cloudwatch-agent || true
echo "searchengine microservice successfully deployed!" echo "paymentservice microservice successfully deployed for betapayments.tradhox.com!"
EOF EOF

33
.gitignore vendored Normal file
View file

@ -0,0 +1,33 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
ENV/
env.bak/
venv.bak/
# Django
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
media/
staticfiles/
# Environment variables
.env
.env.local
# IDE & Editor
.idea/
.vscode/
*.swp
*.swo
# OS
.DS_Store
Thumbs.db

0
config/__init__.py Normal file
View file

16
config/asgi.py Normal file
View file

@ -0,0 +1,16 @@
"""
ASGI config for config project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/6.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
application = get_asgi_application()

150
config/settings.py Normal file
View file

@ -0,0 +1,150 @@
"""
Django settings for config project.
Generated by 'django-admin startproject' using Django 6.1.
For more information on this file, see
https://docs.djangoproject.com/en/6.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/6.1/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/6.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-!&om-o4k1p3t76*ordcwf9tuqo6j69jtt2r-u6jp$^@6h0$!kh'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
import os
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', '*').split(',') if os.environ.get('ALLOWED_HOSTS') else ['*']
CORS_ALLOW_ALL_ORIGINS = True
CSRF_TRUSTED_ORIGINS = [
'https://betapayments.tradhox.com',
'http://localhost',
'http://127.0.0.1',
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'payments',
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'config.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'config.wsgi.application'
# Database Configuration (PostgreSQL)
# https://docs.djangoproject.com/en/6.1/ref/settings/#databases
db_host = os.environ.get('DB_HOST', '16.113.106.152')
db_port = os.environ.get('DB_PORT', '5432')
db_user = os.environ.get('DB_USER', 'vignesh')
db_pass = os.environ.get('DB_PASSWORD', 'vignesh_secret_pass_2026')
db_name = os.environ.get('DB_NAME', 'payments_beta')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': db_name,
'USER': db_user,
'PASSWORD': db_pass,
'HOST': db_host,
'PORT': str(db_port),
}
}
# Password validation
# https://docs.djangoproject.com/en/6.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/6.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/6.1/howto/static-files/
STATIC_URL = 'static/'
# Email
# https://docs.djangoproject.com/en/6.1/topics/email/#topic-email-configuration
MAILERS = {
'default': {
'BACKEND': 'django.core.mail.backends.console.EmailBackend',
},
}

23
config/urls.py Normal file
View file

@ -0,0 +1,23 @@
"""
URL configuration for config project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/6.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/payments/', include('payments.urls')),
]

16
config/wsgi.py Normal file
View file

@ -0,0 +1,16 @@
"""
WSGI config for config project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/6.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
application = get_wsgi_application()

22
manage.py Normal file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

0
payments/__init__.py Normal file
View file

3
payments/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
payments/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class PaymentsConfig(AppConfig):
name = 'payments'

View file

3
payments/models.py Normal file
View file

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
payments/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

5
payments/urls.py Normal file
View file

@ -0,0 +1,5 @@
from django.urls import path
urlpatterns = [
# Payment service endpoints
]

3
payments/views.py Normal file
View file

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

16
paymentservice.service Normal file
View file

@ -0,0 +1,16 @@
[Unit]
Description=Tradhox Payment Service Microservice Daemon
After=network.target
[Service]
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/paymentservice
ExecStart=/home/ubuntu/paymentservice/venv/bin/gunicorn --workers 3 --bind 0.0.0.0:8088 config.wsgi:application
Restart=always
RestartSec=5
StandardOutput=append:/home/ubuntu/paymentservice/logs/gunicorn-access.log
StandardError=append:/home/ubuntu/paymentservice/logs/gunicorn-error.log
[Install]
WantedBy=multi-user.target

7
requirements.txt Normal file
View file

@ -0,0 +1,7 @@
Django>=5.1,<7.0
djangorestframework>=3.15.0
django-cors-headers>=4.3.0
psycopg2-binary>=2.9.9
python-dotenv>=1.0.0
gunicorn>=22.0.0
requests>=2.31.0