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), deps=[src], labels=[name]) 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), deps=[f[0]], labels=[name] ) 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)], live_update=[sync("build/{name}".format(name=name), '/')] ) k8s_resource(name, resource_deps=resource_deps, labels=[name])