Skip to content

Commit

Permalink
re-enable sync function
Browse files Browse the repository at this point in the history
  • Loading branch information
shinebayar-g committed Nov 16, 2022
1 parent 384430b commit da9c35a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func main() {
go ufwhandler.CreateUfwRule(createChannel, trackedContainers)
go ufwhandler.DeleteUfwRule(deleteChannel, trackedContainers)
// go ufwhandler.Cleanup(client, ctx)
// go ufwhandler.Sync(createChannel, client, ctx)
go ufwhandler.Sync(createChannel, client, ctx)

messages, errors := streamEvents(ctx, client)
for {
Expand Down
10 changes: 7 additions & 3 deletions ufwhandler/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ import (
"log"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
)

func Sync(createChannel chan *types.ContainerJSON, client *client.Client, ctx *context.Context) {
containers, err := client.ContainerList(*ctx, types.ContainerListOptions{})
// Returns only running containers
filter := filters.NewArgs()
filter.Add("label", "UFW_MANAGED=TRUE")
containers, err := client.ContainerList(*ctx, types.ContainerListOptions{Filters: filter})
if err != nil {
log.Println(err)
log.Println("ufw-docker-automated: Couldn't retrieve existing containers:", err)
}

for _, c := range containers {
container, err := client.ContainerInspect(*ctx, c.ID)
if err != nil {
log.Println("ufw-docker-automated: Couldn't inspect container:", err)
log.Println("ufw-docker-automated: Couldn't inspect existing container:", err)
continue
}
createChannel <- &container
Expand Down

0 comments on commit da9c35a

Please sign in to comment.