Compare commits

...

10 commits

Author SHA1 Message Date
baalajimaestro 0f6201ab84
Remove stricthostchecking
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
2023-06-18 19:39:22 +05:30
baalajimaestro 906e948b6c
Update trigger to use ssh as well
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
2023-06-18 19:21:27 +05:30
baalajimaestro 415d1a8a2f
Set ssh keys manually on git
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
2023-06-18 19:14:49 +05:30
baalajimaestro 0bacbf7241
Simplify CI config by using ssh deploy keys
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
2023-06-18 18:11:08 +05:30
baalajimaestro 0391609c77
Remove enc_path if it exists
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
2023-06-11 21:36:43 +05:30
baalajimaestro fb16a97bcf
Dont create tags anymore for triggering new builds
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
2023-02-24 22:34:13 +05:30
baalajimaestro c6a24f1e53
Cleanup once its pushed
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
2022-12-09 20:14:57 +05:30
baalajimaestro 33fa9ecbe5
Termux trigger isnt anymore useful
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
2022-10-25 21:01:31 +05:30
baalajimaestro 5ff34f764f
Be a bit more generic on repo namespace
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
2022-10-25 21:01:05 +05:30
baalajimaestro 9ff2a76479
Document the termux_trigger script
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
2022-10-09 19:03:50 +05:30
3 changed files with 19 additions and 12 deletions

View file

@ -10,3 +10,5 @@ The scripts also assume that your parent directory has git set up properly, and
`encrypt.py` - Encrypts the entire obsidian repo, with ChaCha20, retaining folder structure, with the given keys, supplied via env vars, and pushes it to a backup git facility.
`trigger.py` - This is more like a personal script, but all it does is, create a git tag in the current obsidian repo, push it ahead, and trigger a CI pipeline on another repo.
~~`termux_trigger.sh` - Script to sync all your obsidian repos, into your mobile. Works only with Termux. Fully automatic once you fill in the necessary variables, functions as a very dumb replacement to Obsidian Git Plugin. Hook it with Tasker to trigger it on a schedule/by another triggers.~~

View file

@ -7,11 +7,12 @@
# Imports
from git import Repo
import os
from shutil import copytree
from shutil import copytree, rmtree
from pathlib import Path
from glob import glob
import subprocess
from time import time
from shutil import rmtree
cwd = os.getcwd()
path = Path(cwd)
@ -29,12 +30,15 @@ BLACKLIST = [
# Env vars to handle creds
enc_path = os.environ.get("ENCRYPTED_PATH")
enc_repo = os.environ.get("ENCRYPTED_REPO")
enc_repo_user = os.environ.get("ENCRYPTED_REPO_USERNAME")
enc_repo_pass = os.environ.get("ENCRYPTED_REPO_PASSWORD")
enc_key = os.environ.get("ENCRYPTION_KEY")
ssh_key = os.environ.get("SSH_SECRET_KEY")
git_ssh_cmd = f"ssh -i {ssh_key}"
# Create our encrypted directory base
current_time = str(int(time()))
if os.path.exists(enc_path):
rmtree(enc_path)
os.mkdir(enc_path)
os.chdir(enc_path)
@ -42,7 +46,7 @@ os.chdir(enc_path)
repo = Repo.init(enc_path)
repo.create_remote(
"origin",
f"https://{enc_repo_user}:{enc_repo_pass}@github.com/baalajimaestro/{enc_repo}.git",
f"ssh://git@github.com/{enc_repo}.git",
)
# Glob the file list of "." starting files and non "." starting files
@ -91,4 +95,7 @@ for i in file_list:
# Add, commit and push it all
repo.git.add(".")
repo.index.commit(f"Commit as of {current_time}")
repo.git.push("origin", "master", force=True)
repo.git.push("origin", "master", force=True, env=dict(GIT_SSH_COMMAND=git_ssh_cmd))
# Cleanup once you are done
rmtree(enc_path)

View file

@ -8,24 +8,22 @@
from git import Repo
import subprocess
import os
from time import time
from requests import post
from pathlib import Path
# Environment variables for creds
base_repo_user = os.environ.get("BASE_REPO_USERNAME")
base_repo_pass = os.environ.get("BASE_REPO_PASSWORD")
content_repo_git = os.environ.get("CONTENT_REPO_GIT")
content_repo_id = os.environ.get("CONTENT_REPO_ID")
gitlab_token = os.environ.get("GITLAB_TOKEN")
ssh_key = os.environ.get("SSH_SECRET_KEY")
git_ssh_cmd = f"ssh -i {ssh_key}"
# Get the time and create a tag of epoch
cwd = os.getcwd()
path = Path(cwd)
base_dir = str(path.parent.absolute())
current_time = str(int(time()))
repo = Repo(base_dir)
repo.create_tag(current_time)
# Nuke the remote if it existed
try:
@ -35,11 +33,11 @@ except ValueError:
pass
repo.create_remote(
"pushback",
f"https://{base_repo_user}:{base_repo_pass}@git.baalajimaestro.me/baalajimaestro/{content_repo_git}.git",
f"ssh://git@git.baalajimaestro.me:29999/{content_repo_git}.git",
)
# Push the newly created tag
repo.git.push("pushback", current_time)
repo.git.push("pushback", "HEAD:prod", force=True, env=dict(GIT_SSH_COMMAND=git_ssh_cmd))
# Trigger site rebuild
data = {"token": gitlab_token, "ref": "source"}