Skip to content

Commit

Permalink
migrate to docker compose v2 in integration tests (#25465)
Browse files Browse the repository at this point in the history
Co-authored-by: sblumenthal <steven.blumenthal@datadoghq.com>
Co-authored-by: spencergilbert <spencer.gilbert@datadoghq.com>
  • Loading branch information
3 people committed May 9, 2024
1 parent 3b65821 commit 6d305d8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
5 changes: 4 additions & 1 deletion tasks/docker_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ def dockerize_test(ctx, binary, skip_cleanup=False):

with open(f"{temp_folder}/Dockerfile", 'w') as stream:
stream.write(
"""FROM docker/compose:debian-1.29.2
"""FROM ubuntu:20.04
COPY --from=docker/compose-bin:v2.26.1 /docker-compose /usr/bin/compose
COPY --from=docker:26.1-cli /usr/local/bin/docker /usr/bin/docker
ENV DOCKER_DD_AGENT=yes
RUN apt-get update && apt-get install -y ca-certificates
WORKDIR /
CMD /test.bin
COPY test.bin /test.bin
Expand Down
2 changes: 1 addition & 1 deletion test/integration/corechecks/docker/basemetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {

func TestContainerMetricsTagging(t *testing.T) {
expectedTags := []string{
"container_name:basemetrics_redis_1", // Container name
"container_name:basemetrics-redis-1", // Container name
"docker_image:datadog/docker-library:redis_3_2_11-alpine",
"image_name:datadog/docker-library",
"short_image:docker-library",
Expand Down
6 changes: 3 additions & 3 deletions test/integration/corechecks/docker/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func TestEvents(t *testing.T) {
"image_name:datadog/docker-library",
"short_image:docker-library",
"image_tag:busybox_1_28_0",
"container_name:events_recordingevent0_1",
"container_name:events_recordingevent1_1",
"container_name:events-recordingevent0-1",
"container_name:events-recordingevent1-1",
}...),
AggregationKey: "docker:datadog/docker-library:busybox_1_28_0",
SourceTypeName: "docker",
Expand All @@ -60,7 +60,7 @@ func TestEvents(t *testing.T) {
"image_name:datadog/docker-library",
"short_image:docker-library",
"image_tag:redis_3_2_11-alpine",
"container_name:events_recordingevent2_1",
"container_name:events-recordingevent2-1",
}...),
AggregationKey: "docker:datadog/docker-library:redis_3_2_11-alpine",
SourceTypeName: "docker",
Expand Down
6 changes: 3 additions & 3 deletions test/integration/corechecks/docker/exitcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestContainerExit(t *testing.T) {
"highcardenvtag:exithighenv",
"lowcardenvtag:exitlowenv",
}
sender.AssertServiceCheck(t, "docker.exit", servicecheck.ServiceCheckOK, "", append(expectedTags, "container_name:exitcode_exit0_1"), "Container exitcode_exit0_1 exited with 0")
sender.AssertServiceCheck(t, "docker.exit", servicecheck.ServiceCheckCritical, "", append(expectedTags, "container_name:exitcode_exit1_1"), "Container exitcode_exit1_1 exited with 1")
sender.AssertServiceCheck(t, "docker.exit", servicecheck.ServiceCheckCritical, "", append(expectedTags, "container_name:exitcode_exit54_1"), "Container exitcode_exit54_1 exited with 54")
sender.AssertServiceCheck(t, "docker.exit", servicecheck.ServiceCheckOK, "", append(expectedTags, "container_name:exitcode-exit0-1"), "Container exitcode-exit0-1 exited with 0")
sender.AssertServiceCheck(t, "docker.exit", servicecheck.ServiceCheckCritical, "", append(expectedTags, "container_name:exitcode-exit1-1"), "Container exitcode-exit1-1 exited with 1")
sender.AssertServiceCheck(t, "docker.exit", servicecheck.ServiceCheckCritical, "", append(expectedTags, "container_name:exitcode-exit54-1"), "Container exitcode-exit54-1 exited with 54")
}
16 changes: 11 additions & 5 deletions test/integration/utils/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c *ComposeConf) Start() ([]byte, error) {
"--project-name", c.ProjectName,
"--file", c.FilePath,
}
pullCmd := exec.Command("docker-compose", append(args, "pull", "--parallel")...)
pullCmd := exec.Command("compose", append(args, "pull", "--parallel")...)
pullCmd.Env = customEnv
output, err := pullCmd.CombinedOutput()
if err != nil {
Expand All @@ -70,7 +70,7 @@ func (c *ComposeConf) Start() ([]byte, error) {
*/
log.Infof("retrying pull...")
// We need to rebuild a new command because the file-descriptors of stdout/err are already set
retryPull := exec.Command("docker-compose", append(args, "pull", "--parallel")...)
retryPull := exec.Command("compose", append(args, "pull", "--parallel")...)
retryPull.Env = customEnv
output, err = retryPull.CombinedOutput()
if err != nil {
Expand All @@ -82,7 +82,7 @@ func (c *ComposeConf) Start() ([]byte, error) {
if c.RemoveRebuildImages {
args = append(args, "--build")
}
runCmd := exec.Command("docker-compose", args...)
runCmd := exec.Command("compose", args...)
runCmd.Env = customEnv

return runCmd.CombinedOutput()
Expand All @@ -98,17 +98,23 @@ func (c *ComposeConf) Stop() ([]byte, error) {
if c.RemoveRebuildImages {
args = append(args, "--rmi", "all")
}
runCmd := exec.Command("docker-compose", args...)
runCmd := exec.Command("compose", args...)
return runCmd.CombinedOutput()
}

// ListContainers lists the running container IDs
func (c *ComposeConf) ListContainers() ([]string, error) {
customEnv := os.Environ()
for k, v := range c.Variables {
customEnv = append(customEnv, fmt.Sprintf("%s=%s", k, v))
}

runCmd := exec.Command(
"docker-compose",
"compose",
"--project-name", c.ProjectName,
"--file", c.FilePath,
"ps", "-q")
runCmd.Env = customEnv

out, err := runCmd.Output()
if err != nil {
Expand Down

0 comments on commit 6d305d8

Please sign in to comment.