dev-environment/libs/go/Tiltfile

43 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2024-11-04 00:22:29 +00:00
load('ext://restart_process', 'docker_build_with_restart')
def deploy_go(name, src, image, sync_folders = []):
compile_cmd = "CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -C {src} -o {currentPath}/build/{name}/server .".format(src=src, name= name, currentPath=os.getcwd())
local_resource(
"{name}-compile".format(name=name),
compile_cmd,
ignore="build/".format(src=src),
2024-11-04 08:15:08 +00:00
deps=[src],
labels=[name])
2024-11-04 00:22:29 +00:00
i = 0
resource_deps=["{name}-compile".format(name=name)]
for f in sync_folders:
new_resource_dep = "{name}-static-{i}".format(name=name, i = i)
local_resource(
new_resource_dep,
"mkdir -p build/{name}/{targetPath} && rsync -av {localPath}/ build/{name}/{targetPath}/".format(localPath=f[0], targetPath=f[1], name=name),
2024-11-04 08:15:08 +00:00
deps=[f[0]],
labels=[name]
2024-11-04 00:22:29 +00:00
)
resource_deps.append(new_resource_dep)
i = i+1
dockerfile_contents = """FROM alpine
WORKDIR /
RUN apk add tzdata
ADD build/{name} .
ENTRYPOINT /server""".format(name = name)
docker_build_with_restart(
image,
'.',
entrypoint=['/server'],
dockerfile_contents=dockerfile_contents,
only=["build/{name}/".format(name = name)],
2024-11-04 08:15:08 +00:00
live_update=[sync("build/{name}".format(name=name), '/')]
2024-11-04 00:22:29 +00:00
)
2024-11-04 08:15:08 +00:00
k8s_resource(name, resource_deps=resource_deps, labels=[name])