add more functionality to git deploy, frontend changes
This commit is contained in:
parent
60beb4d387
commit
018fe37782
@ -3,7 +3,10 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
from rest_framework import status
|
||||||
from tkinter import simpledialog
|
from tkinter import simpledialog
|
||||||
|
from tkinter import messagebox
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
deployment_methods = {
|
deployment_methods = {
|
||||||
"server_deploy": {
|
"server_deploy": {
|
||||||
@ -23,10 +26,12 @@ def invokeDialogueBox(title, message, type):
|
|||||||
input_data = simpledialog.askstring(title, message)
|
input_data = simpledialog.askstring(title, message)
|
||||||
if type == 'password':
|
if type == 'password':
|
||||||
input_data = simpledialog.askstring(title, message, show='*')
|
input_data = simpledialog.askstring(title, message, show='*')
|
||||||
|
if type == 'message':
|
||||||
|
messagebox.showinfo(title, message)
|
||||||
|
|
||||||
root.destroy()
|
root.destroy()
|
||||||
|
|
||||||
return input_data
|
return input_data
|
||||||
|
|
||||||
def copyData(data_location, deploy_location):
|
def copyData(data_location, deploy_location):
|
||||||
if not os.path.exists(data_location):
|
if not os.path.exists(data_location):
|
||||||
print("The source directory does not exist.")
|
print("The source directory does not exist.")
|
||||||
@ -41,9 +46,14 @@ def copyData(data_location, deploy_location):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error occurred: {e}")
|
print(f"Error occurred: {e}")
|
||||||
def server_deploy():
|
def server_deploy():
|
||||||
data_location = f'{settings.BASE_DIR}/deploy/'
|
try:
|
||||||
deploy_location = settings.DEPLOY_CONFIG["DEPLOY_LOCATION"]+'/server'
|
data_location = f'{settings.BASE_DIR}/deploy/'
|
||||||
copyData(data_location, deploy_location)
|
deploy_location = settings.DEPLOY_CONFIG["DEPLOY_LOCATION"]+'/server'
|
||||||
|
copyData(data_location, deploy_location)
|
||||||
|
return {'message': 'Server deployment successful', 'status': status.HTTP_200_OK}
|
||||||
|
except Exception as e:
|
||||||
|
print (f"An error occurred: {str(e)}")
|
||||||
|
return {'message': str(e), 'status': status.HTTP_500_INTERNAL_SERVER_ERROR}
|
||||||
|
|
||||||
def github_deploy():
|
def github_deploy():
|
||||||
print("Deploying via github")
|
print("Deploying via github")
|
||||||
@ -55,6 +65,8 @@ def github_deploy():
|
|||||||
git_commands["git_config_name"] = ['git', 'config', '--local', 'user.name']
|
git_commands["git_config_name"] = ['git', 'config', '--local', 'user.name']
|
||||||
git_commands["git_commit"] = ['git', 'commit', '-m', 'Update website']
|
git_commands["git_commit"] = ['git', 'commit', '-m', 'Update website']
|
||||||
git_commands["git_branch"] = ['git', 'branch', '-m', 'main']
|
git_commands["git_branch"] = ['git', 'branch', '-m', 'main']
|
||||||
|
git_commands["git_get_origin_url"] = ['git', 'remote', 'get-url', 'origin']
|
||||||
|
git_commands["git_set_origin_url"] = ['git', 'remote', 'set-url', 'origin']
|
||||||
git_commands["git_add_url"] = ['git', 'remote', 'add', 'origin']
|
git_commands["git_add_url"] = ['git', 'remote', 'add', 'origin']
|
||||||
git_commands["git_push"] = ['git', 'push', '-u', 'origin', 'main']
|
git_commands["git_push"] = ['git', 'push', '-u', 'origin', 'main']
|
||||||
|
|
||||||
@ -65,42 +77,54 @@ def github_deploy():
|
|||||||
copyData(data_location, deploy_location)
|
copyData(data_location, deploy_location)
|
||||||
|
|
||||||
if not os.path.exists(f'{deploy_location}/.git'):
|
if not os.path.exists(f'{deploy_location}/.git'):
|
||||||
github_init(deploy_location, git_commands)
|
try:
|
||||||
gh_pages_deploy(deploy_location, git_commands)
|
github_init(deploy_location, git_commands)
|
||||||
|
gh_pages_deploy(deploy_location, git_commands)
|
||||||
|
return {'message': 'Github deployment successful', 'status': status.HTTP_200_OK}
|
||||||
|
except Exception as e:
|
||||||
|
print (f"An error occurred: {str(e)}")
|
||||||
|
return {'message': str(e), 'status': status.HTTP_500_INTERNAL_SERVER_ERROR}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
gh_pages_deploy(deploy_location, git_commands)
|
try:
|
||||||
|
gh_pages_deploy(deploy_location, git_commands)
|
||||||
|
return {'message': 'Github deployment successful', 'status': status.HTTP_200_OK}
|
||||||
|
except Exception as e:
|
||||||
|
print (f"An error occurred: {str(e)}")
|
||||||
|
return {'message': str(e), 'status': status.HTTP_500_INTERNAL_SERVER_ERROR}
|
||||||
|
|
||||||
|
|
||||||
def github_init(deploy_location, git_commands):
|
def github_init(deploy_location, git_commands):
|
||||||
email = invokeDialogueBox('Github Deploy', 'Enter your github email', 'text')
|
email = invokeDialogueBox('Github Deploy', 'Enter your github email', 'text')
|
||||||
name = invokeDialogueBox('Github Deploy', 'Enter your name', 'text')
|
name = invokeDialogueBox('Github Deploy', 'Enter your name', 'text')
|
||||||
username = invokeDialogueBox('Github Deploy', 'Enter your username', 'text')
|
username = invokeDialogueBox('Github Deploy', 'Enter your username', 'text')
|
||||||
password = invokeDialogueBox('Github Deploy', 'Enter your github token', 'password')
|
password = invokeDialogueBox('Github Deploy', 'Enter your github token', 'password')
|
||||||
remote_url = f'https://{username}:{password}@github.com/{username}/{username}.github.io.git'
|
remote_url = f'https://{username}:{password}@github.com/{username}/{username}.github.io.git'
|
||||||
|
|
||||||
try:
|
subprocess.run(git_commands["git_init"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
subprocess.run(git_commands["git_init"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
subprocess.run((git_commands["git_config_email"]).append(email), cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
subprocess.run((git_commands["git_config_email"]).append(email), cwd=deploy_location, check=True, text=True, capture_output=True)
|
subprocess.run((git_commands["git_config_name"]).append(name), cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
subprocess.run((git_commands["git_config_name"]).append(name), cwd=deploy_location, check=True, text=True, capture_output=True)
|
subprocess.run(git_commands["git_add"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
subprocess.run(git_commands["git_add"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
subprocess.run(git_commands["git_commit"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
subprocess.run(git_commands["git_commit"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
subprocess.run(git_commands["git_branch"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
subprocess.run(git_commands["git_branch"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
subprocess.run((git_commands["git_add_url"]).append(remote_url), cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
subprocess.run((git_commands["git_add_url"]).append(remote_url), cwd=deploy_location, check=True, text=True, capture_output=True)
|
subprocess.run(git_commands["git_push"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
subprocess.run(git_commands["git_push"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print (f"Failed to add remote: {e.stderr}")
|
|
||||||
except Exception as e:
|
|
||||||
print (f"An error occurred: {str(e)}")
|
|
||||||
|
|
||||||
|
|
||||||
def gh_pages_deploy(deploy_location, git_commands):
|
def gh_pages_deploy(deploy_location, git_commands):
|
||||||
try:
|
subprocess.run(git_commands["git_pull"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
subprocess.run(git_commands["git_add"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
origin_url_subprocess = subprocess.run(git_commands["git_get_origin_url"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
subprocess.run(git_commands["git_commit"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
origin_url = origin_url_subprocess.stdout.strip()
|
||||||
subprocess.run(git_commands["git_push"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
parsed_url = urllib.parse.urlparse(origin_url)
|
||||||
except subprocess.CalledProcessError as e:
|
if not '@' in parsed_url.netloc:
|
||||||
return f"Failed to add remote: {e.stderr}"
|
username = invokeDialogueBox('Github Deploy', 'Enter your username', 'text')
|
||||||
except Exception as e:
|
password = invokeDialogueBox('Github Deploy', 'Enter your github token', 'password')
|
||||||
return f"An error occurred: {str(e)}"
|
netloc = f"{username}:{password}@{parsed_url.hostname}"
|
||||||
|
new_url = urllib.parse.urlunparse(parsed_url._replace(netloc=netloc))
|
||||||
|
subprocess.run(git_commands["git_set_origin_url"] + [new_url], cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
|
subprocess.run(git_commands["git_add"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
|
subprocess.run(git_commands["git_commit"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
|
subprocess.run(git_commands["git_push"], cwd=deploy_location, check=True, text=True, capture_output=True)
|
||||||
|
|
||||||
|
|
||||||
def create_404_page(deploy_location):
|
def create_404_page(deploy_location):
|
||||||
|
|||||||
@ -34,8 +34,8 @@ class Publish(APIView):
|
|||||||
storage = CustomStorage()
|
storage = CustomStorage()
|
||||||
self.delete_old_data()
|
self.delete_old_data()
|
||||||
self.create_json(storage)
|
self.create_json(storage)
|
||||||
self.execute_deploy(deploy_type)
|
response = self.execute_deploy(deploy_type)
|
||||||
return Response({"deploy_type": deploy_type}, status=status.HTTP_200_OK)
|
return Response(response['message'], response['status'])
|
||||||
|
|
||||||
|
|
||||||
def delete_old_data(self):
|
def delete_old_data(self):
|
||||||
@ -152,7 +152,14 @@ class Publish(APIView):
|
|||||||
|
|
||||||
|
|
||||||
def execute_deploy(self, deploy_type):
|
def execute_deploy(self, deploy_type):
|
||||||
|
response = {
|
||||||
|
'message': 'Something failed',
|
||||||
|
'status': status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||||
|
}
|
||||||
|
|
||||||
if deploy_type == "server_deploy":
|
if deploy_type == "server_deploy":
|
||||||
server_deploy()
|
response = server_deploy()
|
||||||
if deploy_type == "github_deploy":
|
if deploy_type == "github_deploy":
|
||||||
github_deploy()
|
response = github_deploy()
|
||||||
|
|
||||||
|
return response
|
||||||
|
|||||||
@ -131,6 +131,7 @@ function BlogList(props) {
|
|||||||
textColor={ThemeConfig[GlobalTheme].textColor}
|
textColor={ThemeConfig[GlobalTheme].textColor}
|
||||||
bgColor={ThemeConfig[GlobalTheme].background}
|
bgColor={ThemeConfig[GlobalTheme].background}
|
||||||
borderColor={ThemeConfig[GlobalTheme].borderColor}
|
borderColor={ThemeConfig[GlobalTheme].borderColor}
|
||||||
|
buttonColor={ThemeConfig[GlobalTheme].buttonColor}
|
||||||
itemObject={item}
|
itemObject={item}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -111,7 +111,9 @@ function CardListViewer(props) {
|
|||||||
</CardText>
|
</CardText>
|
||||||
<CardText>
|
<CardText>
|
||||||
<Link className={`${props.textColor}`} to={`/${props.resourceType}/${itemObject.id}`}>
|
<Link className={`${props.textColor}`} to={`/${props.resourceType}/${itemObject.id}`}>
|
||||||
Open this resource
|
<Button color='success'>
|
||||||
|
Open this resource
|
||||||
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<Button color='danger' onClick={() => showModal()} className='m-2'>Delete Category</Button>
|
<Button color='danger' onClick={() => showModal()} className='m-2'>Delete Category</Button>
|
||||||
</CardText>
|
</CardText>
|
||||||
@ -138,21 +140,26 @@ function CardListViewer(props) {
|
|||||||
</CardText>
|
</CardText>
|
||||||
</Link>
|
</Link>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
<ButtonGroup>
|
{
|
||||||
<Button
|
itemObject.id === props.featuredBlog ?
|
||||||
outline
|
<ButtonGroup>
|
||||||
active={itemObject.id === props.featuredBlog}
|
<Button
|
||||||
onClick={() => props.updateFeaturedBlog(itemObject.id)}
|
outline
|
||||||
>
|
active={itemObject.id === props.featuredBlog}
|
||||||
Set this as featured
|
color={props.buttonColor}
|
||||||
</Button>
|
onClick={() => props.updateFeaturedBlog(itemObject.id)}
|
||||||
<Button
|
>
|
||||||
outline
|
Set this as featured
|
||||||
onClick={() => props.updateFeaturedBlog('')}
|
</Button>
|
||||||
>
|
<Button
|
||||||
Unset featured blog
|
outline
|
||||||
</Button>
|
color={props.buttonColor}
|
||||||
</ButtonGroup>
|
onClick={() => props.updateFeaturedBlog('')}
|
||||||
|
>
|
||||||
|
Unset featured blog
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup> : ''
|
||||||
|
}
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,17 +11,8 @@ a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.blogContent a{
|
.blogContent a{
|
||||||
border-radius: 5px;
|
color: blue !important;
|
||||||
padding-left: 5px;
|
text-decoration: underline !important;
|
||||||
padding-right: 5px;
|
|
||||||
transition-duration: 0.1s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.blogContent a:hover{
|
|
||||||
border-radius: 5px;
|
|
||||||
padding-left: 15px;
|
|
||||||
padding-right: 15px;
|
|
||||||
transition-duration: 0.1s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.blogContent{
|
.blogContent{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user