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