This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding docker swarm service support. (#12)
- Loading branch information
1 parent
4f11556
commit be1bb96
Showing
5 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package docker | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/calvinbui/homer-docker-service-discovery/internal/entry" | ||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/api/types/swarm" | ||
"github.com/docker/docker/client" | ||
) | ||
|
||
func ListRunningServices(ctx context.Context, docker client.APIClient) ([]swarm.Service, error) { | ||
if ctx == nil { | ||
ctx = context.Background() | ||
} | ||
|
||
services, err := docker.ServiceList(ctx, types.ServiceListOptions{Status: true}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return services, nil | ||
} | ||
|
||
func ParseService(ctx context.Context, docker client.APIClient, service swarm.Service) (entry.RawEntry, error) { | ||
i, _, err := docker.ServiceInspectWithRaw(ctx, service.ID, types.ServiceInspectOptions{}) | ||
|
||
if err != nil { | ||
return entry.RawEntry{}, err | ||
} | ||
|
||
s := entry.RawEntry{ | ||
Name: i.Spec.Annotations.Name, | ||
} | ||
|
||
if i.Spec.Labels != nil { | ||
s.Labels = i.Spec.Annotations.Labels | ||
} | ||
|
||
return s, nil | ||
} |