Add pipeline helper scripts
All checks were successful
Python tests (make) / test (push) Successful in 12s
All checks were successful
Python tests (make) / test (push) Successful in 12s
Created a python script to bundle the application and some bash scripts to pull and push packages from the registry.
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,3 +1,8 @@
|
|||||||
build
|
build
|
||||||
data
|
data
|
||||||
__pycache__
|
__pycache__
|
||||||
|
*.env
|
||||||
|
*.zip
|
||||||
|
*config*
|
||||||
|
*local*
|
||||||
|
package
|
||||||
63
deploy/bundle.py
Normal file
63
deploy/bundle.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
import fnmatch
|
||||||
|
import os
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
|
||||||
|
class Packager:
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name="chess",
|
||||||
|
include_dirs=None,
|
||||||
|
ignore_patterns=None
|
||||||
|
):
|
||||||
|
|
||||||
|
timestamp = datetime.now().strftime("%Y%m%d%H%M")
|
||||||
|
filename = f"{timestamp}.{name}.zip"
|
||||||
|
self.outfile = os.path.join("./deploy/package", filename)
|
||||||
|
self.include_dirs = include_dirs or []
|
||||||
|
self.ignore_patterns = ignore_patterns or []
|
||||||
|
|
||||||
|
|
||||||
|
def create_package(self):
|
||||||
|
with zipfile.ZipFile(self.outfile, "w", zipfile.ZIP_DEFLATED) as z:
|
||||||
|
for d in self.include_dirs:
|
||||||
|
if not os.path.exists(d):
|
||||||
|
raise FileNotFoundError(f"Missing directory {d}")
|
||||||
|
for root, _, files in os.walk(d):
|
||||||
|
for fname in files:
|
||||||
|
rel_path = os.path.relpath(
|
||||||
|
os.path.join(root, fname),
|
||||||
|
start=os.path.dirname(d)
|
||||||
|
)
|
||||||
|
if self._is_ignored(rel_path):
|
||||||
|
continue
|
||||||
|
z.write(os.path.join(root, fname), rel_path)
|
||||||
|
|
||||||
|
print(f"[+] Package created: {self.outfile}")
|
||||||
|
os.system(f"unzip -l {self.outfile}")
|
||||||
|
|
||||||
|
|
||||||
|
def _is_ignored(self, path):
|
||||||
|
for pat in self.ignore_patterns:
|
||||||
|
if fnmatch.fnmatch(path, pat):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
packager = Packager(
|
||||||
|
name="chess",
|
||||||
|
include_dirs=[
|
||||||
|
"build",
|
||||||
|
"scripts",
|
||||||
|
"binding",
|
||||||
|
],
|
||||||
|
ignore_patterns=[
|
||||||
|
"*.pyc",
|
||||||
|
"__pycache__/*",
|
||||||
|
"*env*",
|
||||||
|
"*config*",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
packager.create_package()
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# Load config if present else use environment.
|
|
||||||
CONFIG_FILE="$(dirname "$0")/local.env"
|
|
||||||
if [ -f "$CONFIG_FILE" ]; then
|
|
||||||
source "$CONFIG_FILE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
VERSION=$(date +%Y%m%d-%H%M%S)
|
|
||||||
|
|
||||||
OUTFILE="app-bundle-${VERSION}.zip"
|
|
||||||
|
|
||||||
echo "[*] Building $OUTFILE..."
|
|
||||||
git archive --format=zip HEAD -o "$OUTFILE"
|
|
||||||
|
|
||||||
echo "[*] Pushing to registry as $VERSION..."
|
|
||||||
curl -f -u "${REGISTRY_USER}:${REGISTRY_TOKEN}" \
|
|
||||||
--upload-file "$OUTFILE" \
|
|
||||||
"${REGISTRY_URL}/api/packages/projects/generic/chess/${VERSION}/$(basename "$OUTFILE")"
|
|
||||||
29
deploy/pull-package.sh
Executable file
29
deploy/pull-package.sh
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
CONFIG_FILE="$(dirname "$0")/local.env"
|
||||||
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
|
source "$CONFIG_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
VERSION="${VERSION:-${1:-latest}}"
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
echo "Usage: $0 <version>"
|
||||||
|
echo "Or set VERSION env var."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
OUTDIR="${DOWNLOAD_DIR:-downloads}"
|
||||||
|
mkdir -p "$OUTDIR"
|
||||||
|
|
||||||
|
FILENAME="${VERSION}.chess.zip"
|
||||||
|
URL="${REGISTRY_URL}/api/packages/projects/generic/chess/${VERSION}/chess.zip"
|
||||||
|
|
||||||
|
echo "${URL}"
|
||||||
|
|
||||||
|
echo "[*] Pulling package $FILENAME (version: $VERSION) from registry..."
|
||||||
|
curl -f -u "${REGISTRY_USER}:${REGISTRY_TOKEN}" \
|
||||||
|
-o "${OUTDIR}/${FILENAME}" \
|
||||||
|
"$URL"
|
||||||
|
|
||||||
|
echo "[+] Downloaded to ${OUTDIR}/${FILENAME}"
|
||||||
32
deploy/push-package.sh
Executable file
32
deploy/push-package.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Load config if present else use environment.
|
||||||
|
CONFIG_FILE="$(dirname "$0")/local.env"
|
||||||
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
|
source "$CONFIG_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Latest package.
|
||||||
|
OUTFILE=$(ls -1t ./deploy/package/* | head -n1 || true)
|
||||||
|
|
||||||
|
FILENAME="$(basename "$OUTFILE")"
|
||||||
|
VERSION="${FILENAME%%.*}"
|
||||||
|
|
||||||
|
|
||||||
|
echo "[*] Pushing ${VERSION} to registry."
|
||||||
|
curl -f -u "${REGISTRY_USER}:${REGISTRY_TOKEN}" \
|
||||||
|
--upload-file "$OUTFILE" \
|
||||||
|
"${REGISTRY_URL}/api/packages/projects/generic/chess/${VERSION}/chess.zip"
|
||||||
|
|
||||||
|
|
||||||
|
echo "[*] Deleting ${VERSION} latest to overwrite."
|
||||||
|
curl -f -u "${REGISTRY_USER}:${REGISTRY_TOKEN}" \
|
||||||
|
-X DELETE \
|
||||||
|
"${REGISTRY_URL}/api/packages/projects/generic/chess/latest/chess.zip" || true
|
||||||
|
|
||||||
|
|
||||||
|
echo "[*] Pushing ${VERSION} as latest to registry."
|
||||||
|
curl -f -u "${REGISTRY_USER}:${REGISTRY_TOKEN}" \
|
||||||
|
--upload-file "$OUTFILE" \
|
||||||
|
"${REGISTRY_URL}/api/packages/projects/generic/chess/latest/chess.zip" || true
|
||||||
Reference in New Issue
Block a user