feature/create-working-docker-images #68
@ -1,162 +0,0 @@
 | 
				
			|||||||
#!/usr/bin/python3
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Usage: ./deploy-to-multiple-worktrees.py REPO_PATH WORKTREE_DEVELOPMENT_PATH WORKTREE_PRODUCTION_PATH
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import sys
 | 
					 | 
				
			||||||
import os
 | 
					 | 
				
			||||||
import subprocess
 | 
					 | 
				
			||||||
import re
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
WORKTREE_REGEX = r"^worktree (.*)\nHEAD ([a-f0-9]*)\n(?:branch refs\/heads\/(.*)|detached)$"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if len(sys.argv) < 4:
 | 
					 | 
				
			||||||
    print("Usage: ./deploy-to-multiple-worktrees.py REPO_PATH WORKTREE_DEVELOPMENT_PATH WORKTREE_PRODUCTION_PATH")
 | 
					 | 
				
			||||||
    exit(1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
REPO = os.path.abspath(sys.argv[1])
 | 
					 | 
				
			||||||
WORKTREE_DEVELOPMENT = os.path.abspath(sys.argv[2])
 | 
					 | 
				
			||||||
WORKTREE_PRODUCTION = os.path.abspath(sys.argv[3])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Worktree:
 | 
					 | 
				
			||||||
    def __init__(self, path, branch, revision, version):
 | 
					 | 
				
			||||||
        self.path = path
 | 
					 | 
				
			||||||
        self.branch = branch
 | 
					 | 
				
			||||||
        self.revision = revision
 | 
					 | 
				
			||||||
        self.version = version
 | 
					 | 
				
			||||||
        self.newRevision = None
 | 
					 | 
				
			||||||
        self.newVersion = None
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def getDataForWorktrees():
 | 
					 | 
				
			||||||
    ret = subprocess.check_output(["git", "worktree", "list", "--porcelain"], cwd=REPO).decode().strip()
 | 
					 | 
				
			||||||
    blocks = ret.split("\n\n")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    worktrees = []
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for block in blocks:
 | 
					 | 
				
			||||||
        matches = re.search(WORKTREE_REGEX, block)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if matches:
 | 
					 | 
				
			||||||
            path = matches.group(1)
 | 
					 | 
				
			||||||
            revision = matches.group(2)
 | 
					 | 
				
			||||||
            branch = matches.group(3)
 | 
					 | 
				
			||||||
            version = getVersion(revision)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            worktrees.append(Worktree(path, branch, revision, version))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return worktrees
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def findWorktree(path):
 | 
					 | 
				
			||||||
    for worktree in worktrees:
 | 
					 | 
				
			||||||
        if worktree.path == path:
 | 
					 | 
				
			||||||
            return worktree
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return None
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def getVersion(branch):
 | 
					 | 
				
			||||||
    return subprocess.check_output(["git", "describe", "--tags", "--always", "--match", "Release_*", branch], cwd=REPO).decode().strip()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def getRevisionForRef(ref):
 | 
					 | 
				
			||||||
    return subprocess.check_output(["git", "rev-list", "-1", ref], cwd=REPO).decode().strip()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def getLatestReleaseTag():
 | 
					 | 
				
			||||||
    process = subprocess.Popen(["git", "for-each-ref", "refs/tags/Release*", "--sort=-creatordate", "--format=%(refname:short)"], stdout=subprocess.PIPE, cwd=REPO)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for line in process.stdout:
 | 
					 | 
				
			||||||
        tag = line.decode().rstrip()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if isTagVerified(tag):
 | 
					 | 
				
			||||||
            return tag
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        print(f"[WARNING] Tag '{tag}' is not verified, skipping.")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    raise Exception("No verified 'Release*' tag found!")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def isTagVerified(tag):
 | 
					 | 
				
			||||||
    process = subprocess.run(["git", "tag", "--verify", tag], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=REPO)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return process.returncode == 0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def updateRepoFromRemote():
 | 
					 | 
				
			||||||
    subprocess.call(["git", "fetch", "origin", "--prune", "--prune-tags"], cwd=REPO)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def checkoutWorktree(worktreePath, ref):
 | 
					 | 
				
			||||||
    subprocess.call(["git", "checkout", "-f", ref], cwd=worktreePath)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def cleanWorktree(worktreePath):
 | 
					 | 
				
			||||||
    subprocess.call(["git", "clean", "-f", "-d"], cwd=worktreePath)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def updateAppInWorktree(worktreePath):
 | 
					 | 
				
			||||||
    subprocess.call([worktreePath + "/scripts/update.sh"], cwd=worktreePath)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def updateAppVersionInWorktree(worktreePath):
 | 
					 | 
				
			||||||
    subprocess.call([worktreePath + "/scripts/update-version.sh"], cwd=worktreePath)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
worktrees = getDataForWorktrees()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
updateRepoFromRemote()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("Repo is updated from origin")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("----------------------------------------------")
 | 
					 | 
				
			||||||
print("----------------------------------------------")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
developmentWorktree = findWorktree(WORKTREE_DEVELOPMENT)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
developmentWorktree.newRevision = getRevisionForRef(developmentWorktree.branch)
 | 
					 | 
				
			||||||
developmentWorktree.newVersion = getVersion(developmentWorktree.revision)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("DEVELOPMENT (" + developmentWorktree.path + ") is on branch " + developmentWorktree.branch)
 | 
					 | 
				
			||||||
print(developmentWorktree.revision + " = " + developmentWorktree.branch + " (" + developmentWorktree.version + ")")
 | 
					 | 
				
			||||||
print(developmentWorktree.newRevision + " = origin/" + developmentWorktree.branch + " (" + developmentWorktree.newVersion + ")")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if developmentWorktree.revision != developmentWorktree.newRevision:
 | 
					 | 
				
			||||||
    print("-> DEVELOPMENT (" + developmentWorktree.path + ") will be UPDATED")
 | 
					 | 
				
			||||||
    print("----------------------------------------------")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    checkoutWorktree(developmentWorktree.path, developmentWorktree.branch)
 | 
					 | 
				
			||||||
    cleanWorktree(developmentWorktree.path)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    print(developmentWorktree.path + " is checked out to " + developmentWorktree.branch + " and cleaned")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    updateAppInWorktree(developmentWorktree.path)
 | 
					 | 
				
			||||||
    updateAppVersionInWorktree(developmentWorktree.path)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    print("RVR is updated in " + developmentWorktree.path)
 | 
					 | 
				
			||||||
elif developmentWorktree.version != developmentWorktree.newVersion:
 | 
					 | 
				
			||||||
    print("-> DEVELOPMENT " + developmentWorktree.path + "'s version info will be UPDATED")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    updateAppVersionInWorktree(developmentWorktree.path)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    print("RVR version is updated in " + developmentWorktree.path)
 | 
					 | 
				
			||||||
else:
 | 
					 | 
				
			||||||
    print("-> DEVELOPMENT (" + developmentWorktree.path + ") WON'T be updated")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("----------------------------------------------")
 | 
					 | 
				
			||||||
print("----------------------------------------------")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
productionWorktree = findWorktree(WORKTREE_PRODUCTION)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
productionWorktree.newVersion = getLatestReleaseTag()
 | 
					 | 
				
			||||||
productionWorktree.newRevision = getRevisionForRef(productionWorktree.newVersion)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("PRODUCTION (" + productionWorktree.path + ")")
 | 
					 | 
				
			||||||
print(productionWorktree.revision + " = " + productionWorktree.version)
 | 
					 | 
				
			||||||
print(productionWorktree.newRevision + " = " + productionWorktree.newVersion)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if productionWorktree.revision != productionWorktree.newRevision:
 | 
					 | 
				
			||||||
    print("-> PRODUCTION (" + productionWorktree.path + ") will be UPDATED")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    checkoutWorktree(productionWorktree.path, productionWorktree.newRevision)
 | 
					 | 
				
			||||||
    cleanWorktree(productionWorktree.path)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    print(productionWorktree.path + " is checked out to " + productionWorktree.newRevision + " and cleaned")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    updateAppInWorktree(productionWorktree.path)
 | 
					 | 
				
			||||||
    updateAppVersionInWorktree(productionWorktree.path)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    print("RVR is updated in " + productionWorktree.path)
 | 
					 | 
				
			||||||
else:
 | 
					 | 
				
			||||||
    print("-> PRODUCTION (" + productionWorktree.path + ") WON'T be updated")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("----------------------------------------------")
 | 
					 | 
				
			||||||
print("----------------------------------------------")
 | 
					 | 
				
			||||||
@ -1,32 +0,0 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ROOT_DIR=$(dirname $(readlink -f "$0"))/..
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
. ${ROOT_DIR}/.env
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if [ -f ${ROOT_DIR}/installed ]; then
 | 
					 | 
				
			||||||
    echo "RVR is already installed! To force reinstall, delete file 'installed' from the root directory!"
 | 
					 | 
				
			||||||
    exit 1
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Installing Yarn packages..."
 | 
					 | 
				
			||||||
(cd ${ROOT_DIR}/public/static && yarn install)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Installing RVR DB..."
 | 
					 | 
				
			||||||
mysql --host=${DB_HOST} --user=${DB_USER} --password=${DB_PASSWORD} ${DB_NAME} < ${ROOT_DIR}/database/rvr.sql
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Migrating DB..."
 | 
					 | 
				
			||||||
(cd ${ROOT_DIR} && ./rvr db:migrate)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if [ -z "${DEV}" ] || [ "${DEV}" -eq "0" ]; then
 | 
					 | 
				
			||||||
    echo "Minifying JS, CSS and SVG files..."
 | 
					 | 
				
			||||||
    ${ROOT_DIR}/scripts/minify.sh
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    echo "Linking view files..."
 | 
					 | 
				
			||||||
    (cd ${ROOT_DIR} && ./rvr view:link)
 | 
					 | 
				
			||||||
else
 | 
					 | 
				
			||||||
    echo "Creating the first user..."
 | 
					 | 
				
			||||||
    (cd ${ROOT_DIR} && ./rvr user:add rvr@rvr.dev 123456 admin)
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
touch ${ROOT_DIR}/installed
 | 
					 | 
				
			||||||
@ -1,11 +0,0 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ROOT_DIR=$(dirname $(readlink -f "$0"))/..
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
. ${ROOT_DIR}/.env
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
find ${ROOT_DIR}/public/static/js -type f -iname '*.js' -exec uglifyjs {} -c -m -o {} \;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
find ${ROOT_DIR}/public/static/css -type f -iname '*.css' -exec cleancss {} -o {} \;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
find ${ROOT_DIR}/public/static/img -type f -iname '*.svg' -exec svgo {} -o {} \;
 | 
					 | 
				
			||||||
@ -1,17 +0,0 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ROOT_DIR=$(dirname $(readlink -f "$0"))/..
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
. ${ROOT_DIR}/.env
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
cd ${ROOT_DIR}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Updating version info..."
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
VERSION=$(git describe --tags --always --match "Release_*" HEAD)
 | 
					 | 
				
			||||||
REVISION=$(git rev-parse --short HEAD)
 | 
					 | 
				
			||||||
REVISION_DATE=$(git show -s --format=%aI HEAD)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
sed -i -E "s/const VERSION = '(.*)';/const VERSION = '${VERSION}';/" app.php
 | 
					 | 
				
			||||||
sed -i -E "s/const REVISION = '(.*)';/const REVISION = '${REVISION}';/" app.php
 | 
					 | 
				
			||||||
sed -i -E "s/const REVISION_DATE = '(.*)';/const REVISION_DATE = '${REVISION_DATE}';/" app.php
 | 
					 | 
				
			||||||
@ -1,26 +0,0 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ROOT_DIR=$(dirname $(readlink -f "$0"))/..
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
. ${ROOT_DIR}/.env
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Installing Composer packages..."
 | 
					 | 
				
			||||||
if [ -z "${DEV}" ] || [ "${DEV}" -eq "0" ]; then
 | 
					 | 
				
			||||||
    (cd ${ROOT_DIR} && composer install --no-dev)
 | 
					 | 
				
			||||||
else
 | 
					 | 
				
			||||||
    (cd ${ROOT_DIR} && composer install --dev)
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Installing Yarn packages..."
 | 
					 | 
				
			||||||
(cd ${ROOT_DIR}/public/static && yarn install)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Migrating DB..."
 | 
					 | 
				
			||||||
(cd ${ROOT_DIR} && ./rvr db:migrate)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if [ -z "${DEV}" ] || [ "${DEV}" -eq "0" ]; then
 | 
					 | 
				
			||||||
    echo "Minifying JS, CSS and SVG files..."
 | 
					 | 
				
			||||||
    ${ROOT_DIR}/scripts/minify.sh
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    echo "Linking view files..."
 | 
					 | 
				
			||||||
    (cd ${ROOT_DIR} && ./rvr view:link)
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user