Skip to content

Commit

Permalink
fix: remove existing deployment before creating a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Apr 11, 2024
1 parent 148affb commit 170e59c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions operate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ async def _build_service_locally(request: Request) -> JSONResponse:
)
.deployment
)
deployment.build()
deployment.build(force=False)
return JSONResponse(content=deployment.json)

@app.post("/api/services/{service}/deployment/start")
Expand All @@ -450,7 +450,7 @@ async def _start_service_locally(request: Request) -> JSONResponse:
)
.deployment
)
deployment.build()
deployment.build(force=False)
operate.service_manager().fund_service(hash=request.path_params["service"])
deployment.start()
return JSONResponse(content=deployment.json)
Expand Down
2 changes: 1 addition & 1 deletion operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def fund_service(self, hash: str) -> None:
chain_type=service.ledger_config.chain,
)

def deploy_service_locally(self, hash: str, force: bool = False) -> Deployment:
def deploy_service_locally(self, hash: str, force: bool = True) -> Deployment:
"""
Deploy service locally
Expand Down
11 changes: 9 additions & 2 deletions operate/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,22 @@ def mkdirs(build_dir: Path) -> None:
continue


def remove_service_network(service_name: str) -> None:
def remove_service_network(service_name: str, force: bool = True) -> None:
"""Remove service network cache."""
client = from_env()
network_names = (
f"deployment_service_{service_name}_localnet",
f"abci_build_service_{service_name}_localnet",
)
for network in client.networks.list():
for network in client.networks.list(greedy=True):
if network.attrs["Name"] not in network_names:
continue

if force:
for container in network.attrs["Containers"]:
print(f"Killing {container}")
client.api.kill(container=container)

print("Deleting network: " + network.attrs["Name"])
client.api.remove_network(net_id=network.attrs["Id"])

Expand Down Expand Up @@ -216,6 +222,7 @@ def build(self, force: bool = True) -> None:
# if the service is still running so we can do an early exit
remove_service_network(
service_name=service.helper.config.name,
force=force,
)

build = self.path / DEPLOYMENT
Expand Down

0 comments on commit 170e59c

Please sign in to comment.