Skip to content

Commit

Permalink
dev: Improve filter to match docker containers
Browse files Browse the repository at this point in the history
This will prevent that a given name, for instance `k3d-upstream`, will
cause container images named `k3d-upstream-2-server-x` to be deleted.
Instead, only container images with `k3d-upstream-{server,agent}-x` will
be targeted for deletion.
  • Loading branch information
p-se committed Jun 25, 2024
1 parent 01e1b79 commit 575afd0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
12 changes: 8 additions & 4 deletions dev/build-fleet
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ fi

export GOOS=linux

# The name of the container image created here is a potential source of conflict
# when fleet is set up simultaneously, as several scripts are calling
# build-fleet and it always creates a container image with the same name
# (`rancher/fleet`, rancher/fleet-agent`) and tag (`dev`). Conflicts can simply
# be avoided by making sure this script is not called sequentially, e.g. by
# creating multiple clusters on a single host sequentially rather than
# simultaneously.

# fleet
go build -gcflags='all=-N -l' -o "bin/fleet-linux-$GOARCH" ./cmd/fleetcli
go build -gcflags='all=-N -l' -o bin/fleetcontroller-linux-"$GOARCH" ./cmd/fleetcontroller
docker build -f package/Dockerfile -t rancher/fleet:dev --build-arg="ARCH=$GOARCH" .

# fleet agent
go build -gcflags='all=-N -l' -o "bin/fleetagent-linux-$GOARCH" ./cmd/fleetagent

# The name of the container image created here is a potential source of
# conflicts when the clusters are created simultaneously. It might be worth thinking about
# how to make the image name unique for each test run.
docker build -f package/Dockerfile.agent -t rancher/fleet-agent:dev --build-arg="ARCH=$GOARCH" .
19 changes: 11 additions & 8 deletions dev/k3d-act-clean
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ function docker-clean-by-name {
return
fi

ids=$(docker ps -a --filter name="$1" --format "{{.ID}}")
if [ -z "$ids" ]; then
return
fi

for id in $ids; do
docker stop "$id"
docker rm "$id"
# only delete `-server` and `-agent` suffixed containers.
for suffix in server agent; do
ids=$(docker ps -a --filter name="$1-$suffix" --format "{{.ID}}")
if [ -z "$ids" ]; then
continue
fi

for id in $ids; do
docker stop "$id"
docker rm "$id"
done
done
}

Expand Down

0 comments on commit 575afd0

Please sign in to comment.