Created github deploy functions
This commit is contained in:
parent
043769014d
commit
40ec488249
@ -1,6 +1,9 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import simpledialog
|
||||||
|
|
||||||
deployment_methods = {
|
deployment_methods = {
|
||||||
"server_deploy": {
|
"server_deploy": {
|
||||||
@ -11,20 +14,116 @@ deployment_methods = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def server_deploy():
|
def invokeDialogueBox(title, message, type):
|
||||||
data_location = f'{settings.BASE_DIR}/deploy/'
|
root = tk.Tk()
|
||||||
deploy_location = settings.DEPLOY_CONFIG["DEPLOY_LOCATION"]
|
root.withdraw()
|
||||||
|
|
||||||
|
input_data = None
|
||||||
|
if type == 'text':
|
||||||
|
input_data = simpledialog.askstring(title, message)
|
||||||
|
if type == 'password':
|
||||||
|
input_data = simpledialog.askstring(title, message, show='*')
|
||||||
|
|
||||||
|
root.destroy()
|
||||||
|
|
||||||
|
return input_data
|
||||||
|
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.")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(f'{deploy_location}/data')
|
if os.path.exists(f'{deploy_location}/data'):
|
||||||
|
shutil.rmtree(f'{deploy_location}/data')
|
||||||
|
else:
|
||||||
|
pass
|
||||||
shutil.copytree(data_location, deploy_location, dirs_exist_ok=True)
|
shutil.copytree(data_location, deploy_location, dirs_exist_ok=True)
|
||||||
print(f"Data successfully deployed")
|
print(f"Data successfully deployed")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error occurred: {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)
|
||||||
|
|
||||||
def github_deploy():
|
def github_deploy():
|
||||||
server_deploy()
|
|
||||||
print("Deploying via github")
|
print("Deploying via github")
|
||||||
|
git_commands = {}
|
||||||
|
git_commands["git_init"] = ['git', 'init']
|
||||||
|
git_commands["git_add"] = ['git', 'add', '.']
|
||||||
|
git_commands["git_commit"] = ['git', 'commit', '-m', '"Update website"']
|
||||||
|
git_commands["git_branch"] = ['git', 'branch', '-m', 'main']
|
||||||
|
git_commands["git_push"] = ['git', 'push', '-u', 'origin', 'main']
|
||||||
|
|
||||||
|
data_location = f'{settings.BASE_DIR}/deploy/'
|
||||||
|
deploy_location = settings.DEPLOY_CONFIG["DEPLOY_LOCATION"]+'/ghpages'
|
||||||
|
|
||||||
|
run_gh_build = ['npm', 'run', 'build:ghpages']
|
||||||
|
|
||||||
|
subprocess.run(run_gh_build, cwd=settings.DEPLOY_CONFIG["DEPLOY_LOCATION"].replace('/dist', ''), check=True, text=True, capture_output=True)
|
||||||
|
create_404_page(deploy_location)
|
||||||
|
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)
|
||||||
|
else:
|
||||||
|
gh_pages_deploy(deploy_location, git_commands)
|
||||||
|
|
||||||
|
def github_init(deploy_location, git_commands):
|
||||||
|
username = invokeDialogueBox('Github Deploy', 'Enter your username', 'text')
|
||||||
|
password = invokeDialogueBox('Github Deploy', 'Enter your password', 'password')
|
||||||
|
remote_url = f'https://{username}:{password}@github.com/{username}/{username}.github.io.git'
|
||||||
|
git_add_url = ['git', 'remote', 'add', 'origin', remote_url]
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.run(git_commands["git_init"], 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_add_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)}")
|
||||||
|
|
||||||
|
|
||||||
|
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)}"
|
||||||
|
|
||||||
|
|
||||||
|
def create_404_page(deploy_location):
|
||||||
|
html_content = """
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Single Page Apps for GitHub Pages</title>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var pathSegmentsToKeep = 0;
|
||||||
|
var l = window.location;
|
||||||
|
l.replace(
|
||||||
|
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
|
||||||
|
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
|
||||||
|
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
|
||||||
|
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
|
||||||
|
l.hash
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
with open(f'{deploy_location}/404.html', 'w') as file:
|
||||||
|
file.write(html_content)
|
||||||
|
|
||||||
|
print("404 page created successfully.")
|
||||||
@ -42,7 +42,7 @@ INSTALLED_APPS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
DEPLOY_CONFIG = {
|
DEPLOY_CONFIG = {
|
||||||
"DEPLOY_LOCATION": os.path.join(BASE_DIR, '../frontend-deploy/')
|
"DEPLOY_LOCATION": os.path.join(BASE_DIR, '../frontend/viewable-ui/dist')
|
||||||
}
|
}
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
|
|||||||
19
frontend/viewable-ui/package-lock.json
generated
19
frontend/viewable-ui/package-lock.json
generated
@ -40,6 +40,7 @@
|
|||||||
"@types/react": "^18.2.66",
|
"@types/react": "^18.2.66",
|
||||||
"@types/react-dom": "^18.2.22",
|
"@types/react-dom": "^18.2.22",
|
||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-react": "^7.34.1",
|
"eslint-plugin-react": "^7.34.1",
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
@ -2318,6 +2319,24 @@
|
|||||||
"integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==",
|
"integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==",
|
||||||
"peer": true
|
"peer": true
|
||||||
},
|
},
|
||||||
|
"node_modules/cross-env": {
|
||||||
|
"version": "7.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz",
|
||||||
|
"integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"cross-spawn": "^7.0.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"cross-env": "src/bin/cross-env.js",
|
||||||
|
"cross-env-shell": "src/bin/cross-env-shell.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.14",
|
||||||
|
"npm": ">=6",
|
||||||
|
"yarn": ">=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/cross-spawn": {
|
"node_modules/cross-spawn": {
|
||||||
"version": "7.0.3",
|
"version": "7.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
||||||
|
|||||||
@ -3,14 +3,13 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"proxy": "http://127.0.0.1:8000",
|
|
||||||
"homepage": "/",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite --host 0.0.0.0 --port 3000",
|
"dev": "vite --host 0.0.0.0 --port 3000",
|
||||||
"build": "vite build",
|
"build:server": "cross-env BUILD_ENV=server vite build",
|
||||||
|
"build:ghpages": "cross-env BUILD_ENV=ghpages cross-env vite build",
|
||||||
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"deploy": "gh-pages -d dist"
|
"ghdeploy": "gh-pages -d dist/ghpages -r"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.5.2",
|
"@fortawesome/fontawesome-svg-core": "^6.5.2",
|
||||||
@ -45,6 +44,7 @@
|
|||||||
"@types/react": "^18.2.66",
|
"@types/react": "^18.2.66",
|
||||||
"@types/react-dom": "^18.2.22",
|
"@types/react-dom": "^18.2.22",
|
||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-react": "^7.34.1",
|
"eslint-plugin-react": "^7.34.1",
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
|
|||||||
@ -61,7 +61,7 @@ function Blog(props) {
|
|||||||
if (GlobalTheme && ThemeConfig) {
|
if (GlobalTheme && ThemeConfig) {
|
||||||
return (
|
return (
|
||||||
<Container fluid className={`${ThemeConfig[GlobalTheme].background}`}>
|
<Container fluid className={`${ThemeConfig[GlobalTheme].background}`}>
|
||||||
<Col xs="3" className="d-none d-md-block"><Button color={ThemeConfig[GlobalTheme].buttonColor} onClick={() => navigate(`/categories/${blogData.parentCategory}`)} className="ms-5 mt-5" outline><FontAwesomeIcon icon={faLeftLong}/></Button></Col>
|
<Col xs="3" className="d-md-block"><Button color={ThemeConfig[GlobalTheme].buttonColor} onClick={() => navigate(`/categories/${blogData.parentCategory}`)} className="ms-5 mt-5" outline><FontAwesomeIcon icon={faLeftLong}/></Button></Col>
|
||||||
<CategoryBar currentPage={blogData.parentCategory} GlobalTheme={GlobalTheme} ThemeConfig={ThemeConfig}/>
|
<CategoryBar currentPage={blogData.parentCategory} GlobalTheme={GlobalTheme} ThemeConfig={ThemeConfig}/>
|
||||||
<Row className="mb-4">
|
<Row className="mb-4">
|
||||||
<Col className="p-0">
|
<Col className="p-0">
|
||||||
|
|||||||
@ -44,7 +44,7 @@ function HomePage(props) {
|
|||||||
</Row>
|
</Row>
|
||||||
<Row className={`mb-5 mt-2 ${ThemeConfig[GlobalTheme].textColor}`}>
|
<Row className={`mb-5 mt-2 ${ThemeConfig[GlobalTheme].textColor}`}>
|
||||||
<Col xs="3" className="d-none d-md-block"></Col>
|
<Col xs="3" className="d-none d-md-block"></Col>
|
||||||
<Col className="p-4 blogContent">
|
<Col className="blogContent">
|
||||||
<div className={`blogContent ${ThemeConfig[GlobalTheme].textColor}`}>{introContent}</div>
|
<div className={`blogContent ${ThemeConfig[GlobalTheme].textColor}`}>{introContent}</div>
|
||||||
</Col>
|
</Col>
|
||||||
<Col xs="3" className="d-none d-md-block"></Col>
|
<Col xs="3" className="d-none d-md-block"></Col>
|
||||||
|
|||||||
@ -1,10 +1,23 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
|
|
||||||
|
console.log(process.env.BUILD_ENV)
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [
|
||||||
server: {
|
react(),
|
||||||
historyApiFallback: true
|
process.env.BUILD_ENV === 'ghpages' ? {
|
||||||
},
|
name: 'inject-ghpages-fix',
|
||||||
|
transformIndexHtml(html) {
|
||||||
|
return html.replace(
|
||||||
|
'<div id="root"></div>',
|
||||||
|
"<div id='root'></div><script type='text/javascript'>(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))</script>"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} : ''
|
||||||
|
],
|
||||||
|
server: {},
|
||||||
|
build: {
|
||||||
|
outDir: 'dist/' + process.env.BUILD_ENV
|
||||||
|
}
|
||||||
})
|
})
|
||||||
Loading…
Reference in New Issue
Block a user