dockerise for push
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
name: Deploy to Server
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Copy files to server
|
||||||
|
uses: appleboy/scp-action@v0.1.6
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.SERVER_HOST }}
|
||||||
|
username: ${{ secrets.SSH_USER }}
|
||||||
|
password: ${{ secrets.SSH_PASSWORD }}
|
||||||
|
source: "."
|
||||||
|
target: "/root/hshop/"
|
||||||
|
|
||||||
|
- name: SSH command to build and start Docker
|
||||||
|
uses: appleboy/ssh-action@v0.1.6
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.SERVER_HOST }}
|
||||||
|
username: ${{ secrets.SSH_USER }}
|
||||||
|
password: ${{ secrets.SSH_PASSWORD }}
|
||||||
|
script: |
|
||||||
|
cd /root/hshop/
|
||||||
|
docker compose down
|
||||||
|
docker compose build
|
||||||
|
docker compose up -d
|
||||||
@@ -9,6 +9,7 @@ from drf_spectacular.utils import extend_schema, OpenApiParameter
|
|||||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from rest_framework_simplejwt.tokens import RefreshToken
|
from rest_framework_simplejwt.tokens import RefreshToken
|
||||||
|
import ghasedak_sms
|
||||||
class SendOTPView(APIView):
|
class SendOTPView(APIView):
|
||||||
permission_classes = [AllowAny]
|
permission_classes = [AllowAny]
|
||||||
@extend_schema(
|
@extend_schema(
|
||||||
@@ -24,18 +25,43 @@ class SendOTPView(APIView):
|
|||||||
)
|
)
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
phone = request.data.get('phone')
|
phone = request.data.get('phone')
|
||||||
|
if not phone:
|
||||||
|
return Response({'detail': 'Phone number is required'}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user, created = User.objects.get_or_create(phone=phone)
|
user, created = User.objects.get_or_create(phone=phone)
|
||||||
print(created)
|
otp = user.set_otp()
|
||||||
print(user.phone)
|
|
||||||
otp = user.set_otp()
|
|
||||||
message = f"کد یک بار مصرف : {otp}"
|
message = f"کد یک بار مصرف : {otp}"
|
||||||
print(message)
|
|
||||||
# send otp
|
|
||||||
return Response({'detail': 'OTP sent successfully'}, status=status.HTTP_200_OK)
|
sms_api = ghasedak_sms.Ghasedak(api_key="4dc844abd4409fe247ec73831aed2498ad3749c1945660cc252654371756b966vafe5d9LGgMbnfGn")
|
||||||
|
|
||||||
|
# response = sms_api.send_single_sms(ghasedak_sms.SendSingleSmsInput(message=message, receptor=phone, line_number='30005006006908', send_date='', client_reference_id=''))
|
||||||
|
# print(response)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
response = sms_api.send_single_sms(
|
||||||
|
ghasedak_sms.SendSingleSmsInput(
|
||||||
|
message=message,
|
||||||
|
receptor=phone,
|
||||||
|
line_number='90002930',
|
||||||
|
send_date='',
|
||||||
|
client_reference_id=''
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# response = sms_api.send_otp_sms(otp_input)
|
||||||
|
|
||||||
|
if response['statusCode'] == 200:
|
||||||
|
return Response({'detail': 'OTP sent successfully'}, status=status.HTTP_200_OK)
|
||||||
|
else:
|
||||||
|
return Response({'detail': response}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||||
|
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
return Response({'detail': 'User not found'}, status=status.HTTP_404_NOT_FOUND)
|
return Response({'detail': 'user not found'}, status=status.HTTP_404_NOT_FOUND)
|
||||||
|
except Exception as e:
|
||||||
|
return Response({'detail': f'An error occurred: {response}'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||||
|
|
||||||
|
|
||||||
class CustomTokenObtainPairView(TokenObtainPairView):
|
class CustomTokenObtainPairView(TokenObtainPairView):
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")
|
|||||||
DEFAULT_FROM_EMAIL = os.getenv("SECRET_KEY")
|
DEFAULT_FROM_EMAIL = os.getenv("SECRET_KEY")
|
||||||
|
|
||||||
SECRET_KEY = os.getenv("SECRET_KEY")
|
SECRET_KEY = os.getenv("SECRET_KEY")
|
||||||
DEBUG = os.getenv("DEBUG")
|
DEBUG = False
|
||||||
# in production lists of allowed hosts and allowed orgins will genrate
|
# in production lists of allowed hosts and allowed orgins will genrate
|
||||||
# in development every host and orgin will be true
|
# in development every host and orgin will be true
|
||||||
# in prodcution it will use the postgres info you enterd in .env.local
|
# in prodcution it will use the postgres info you enterd in .env.local
|
||||||
|
|||||||
+35
-1
@@ -13,4 +13,38 @@ sms_api = Ghasedak(api_key=os.getenv("SMS_API_KEY"))
|
|||||||
|
|
||||||
### ارسال پیام otp
|
### ارسال پیام otp
|
||||||
|
|
||||||
#response = sms_api.send_otp_sms(receptor='09359****', message='OTP message')
|
#response = sms_api.send_otp_sms(receptor='09359****', message='OTP message')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import ghasedak_sms
|
||||||
|
|
||||||
|
# Initialize the Ghasedak API client with your API key
|
||||||
|
sms_api = ghasedak_sms.Ghasedak(api_key="Your_API_KEY")
|
||||||
|
|
||||||
|
# Define the OTP code and the recipient's phone number
|
||||||
|
otp_code = "123456" # Replace with the generated OTP code
|
||||||
|
phone_number = "09xxxxxxxxx" # Replace with the recipient's phone number
|
||||||
|
|
||||||
|
# Create the OTP input object
|
||||||
|
otp_input = ghasedak_sms.SendOtpInput(
|
||||||
|
send_date=None, # Immediate send; use a specific datetime for scheduled send
|
||||||
|
receptors=[
|
||||||
|
ghasedak_sms.SendOtpReceptorDto(
|
||||||
|
mobile=phone_number,
|
||||||
|
# client_reference_id='optional_client_ref_id' # Optional: Add if you have a client reference ID
|
||||||
|
)
|
||||||
|
],
|
||||||
|
template_name="YourTemplateName", # Replace with your OTP template name
|
||||||
|
inputs=[
|
||||||
|
ghasedak_sms.SendOtpInput.OtpInput(param="Code", value=otp_code),
|
||||||
|
# Add more parameters if your template requires them
|
||||||
|
],
|
||||||
|
udh=False # Set to True if you need User Data Header; typically False for standard SMS
|
||||||
|
)
|
||||||
|
|
||||||
|
# Send the OTP SMS
|
||||||
|
response = sms_api.send_otp_sms(otp_input)
|
||||||
|
|
||||||
|
# Print the response to check the result
|
||||||
|
print(response)
|
||||||
+19
-11
@@ -1,11 +1,13 @@
|
|||||||
services:
|
services:
|
||||||
# frontend:
|
frontend:
|
||||||
# build:
|
build:
|
||||||
# context: ./frontend
|
context: ./frontend
|
||||||
# ports:
|
ports:
|
||||||
# - "80:3000"
|
- "80:3000"
|
||||||
# depends_on:
|
depends_on:
|
||||||
# - django
|
- django
|
||||||
|
networks:
|
||||||
|
- default
|
||||||
|
|
||||||
django:
|
django:
|
||||||
build:
|
build:
|
||||||
@@ -18,22 +20,28 @@ services:
|
|||||||
- ./backend:/app
|
- ./backend:/app
|
||||||
- media_data:/app/media
|
- media_data:/app/media
|
||||||
command: ["sh", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"]
|
command: ["sh", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"]
|
||||||
|
networks:
|
||||||
|
- default
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgres:16
|
image: postgres:16
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_DB: shop_db
|
POSTGRES_DB: hshop
|
||||||
POSTGRES_USER: byeto
|
POSTGRES_USER: byeto
|
||||||
POSTGRES_PASSWORD: vuhbyq-cypMu0-sirbon
|
POSTGRES_PASSWORD: vuhbyq-cypMu0-sirbon
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
ports:
|
ports:
|
||||||
- "5434:5432"
|
- "5434:5432"
|
||||||
|
networks:
|
||||||
|
- default
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
media_data:
|
media_data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
default:
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
FROM node:20-alpine as build-stage
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM node:20-alpine as production-stage
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=build-stage /app /app
|
||||||
|
EXPOSE 3000
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
CMD ["npm", "run", "start"]
|
||||||
Reference in New Issue
Block a user