forked from GoogleContainerTools/kaniko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.py.bk
43 lines (33 loc) · 1.71 KB
/
handler.py.bk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import runpod
import subprocess
import os
import shutil
import tarfile
def build_image(job):
# inputs
job_input = job["input"]
dockerfile_path = job_input["dockerfile_path"]
cloudflare_destination = job_input["cloudflare_destination"]
destination = job_input["destination"]
uuid = job_input["uuid"]
git_repository = job_input["git_repository"]
repo_dir = f"/runpod-volume/{uuid}/repo"
clone_command = f"git clone {git_repository} {repo_dir}"
subprocess.run(clone_command, shell=True, check=True)
build_context = f"dir:///{repo_dir}"
envs = os.environ.copy()
install_command = "curl -fsSL https://bun.sh/install | bash"
subprocess.run(install_command, shell=True, executable="/bin/bash", env=envs)
bun_bin_dir = os.path.expanduser("~/.bun/bin")
envs["PATH"] = f"{bun_bin_dir}:{envs['PATH']}"
subprocess.run("mkdir -p /runpod-volume/{}".format(uuid), shell=True, env=envs)
tarPath = "/runpod-volume/{uuid}/image.tar".format(uuid=uuid)
subprocess.run(["/kaniko/executor", "--context={}".format(build_context), "--dockerfile={}".format(dockerfile_path), "--destination={}".format(destination), "--no-push", "--tar-path={}".format(tarPath)])
envs["USERNAME_REGISTRY"] = "pierre-bastola"
envs["TAR_PATH"] = tarPath
envs["UUID"] = uuid
subprocess.run("bun install", cwd="/kaniko/serverless-registry/push", env=envs, shell=True, executable="/bin/bash")
run_command = "echo Innovator81@ | USERNAME_REGISTRY=pierre bun run index.ts {}".format(cloudflare_destination)
subprocess.run(run_command, cwd="/kaniko/serverless-registry/push", env=envs, shell=True, executable="/bin/bash")
return True
runpod.serverless.start({"handler": build_image})