Skip to content

Commit

Permalink
Merge pull request #1201 from hongil0316/docker_compose_buildkit_support
Browse files Browse the repository at this point in the history
support buildkit for dockcer-compose
  • Loading branch information
Andrew Ellison committed Nov 17, 2022
2 parents 57feb6b + 3310bc8 commit 3f5f355
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
13 changes: 13 additions & 0 deletions modules/docker/docker_compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
type Options struct {
WorkingDir string
EnvVars map[string]string

// Whether ot not to enable buildkit. You can find more information about buildkit here https://docs.docker.com/build/buildkit/#getting-started.
EnableBuildKit bool

// Set a logger that should be used. See the logger package for more info.
Logger *logger.Logger
}
Expand Down Expand Up @@ -46,6 +50,15 @@ func runDockerComposeE(t testing.TestingT, stdout bool, options *Options, args .

result := icmd.RunCmd(dockerComposeVersionCmd)

if options.EnableBuildKit {
if options.EnvVars == nil {
options.EnvVars = make(map[string]string)
}

options.EnvVars["DOCKER_BUILDKIT"] = "1"
options.EnvVars["COMPOSE_DOCKER_CLI_BUILD"] = "1"
}

if result.ExitCode == 0 {
cmd = shell.Command{
Command: "docker",
Expand Down
26 changes: 26 additions & 0 deletions modules/docker/docker_compose_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package docker

import (
"github.com/stretchr/testify/require"
"testing"
)

func TestDockerComposeWithBuildKit(t *testing.T) {
t.Parallel()

testToken := "testToken"
dockerOptions := &Options{
// Directory where docker-compose.yml lives
WorkingDir: "../../test/fixtures/docker-compose-with-buildkit",

// Configure the port the web app will listen on and the text it will return using environment variables
EnvVars: map[string]string{
"GITHUB_OAUTH_TOKEN": testToken,
},
EnableBuildKit: true,
}
out := RunDockerCompose(t, dockerOptions, "build", "--no-cache")
out = RunDockerCompose(t, dockerOptions, "up")

require.Contains(t, out, testToken)
}
5 changes: 5 additions & 0 deletions test/fixtures/docker-compose-with-buildkit/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# A "Hello, World" Docker image used in automated tests for the docker.Build command.
FROM ubuntu:20.04 as with-secrets

RUN --mount=type=secret,id=github-token echo "$(cat /run/secrets/github-token)" > text.txt
COPY ./bash_script.sh /usr/local/bin/bash_script.sh
4 changes: 4 additions & 0 deletions test/fixtures/docker-compose-with-buildkit/bash_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e

cat text.txt
11 changes: 11 additions & 0 deletions test/fixtures/docker-compose-with-buildkit/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
test-docker-image:
build:
context: .
secrets:
- github-token
entrypoint: bash_script.sh

secrets:
github-token:
environment: GITHUB_OAUTH_TOKEN

0 comments on commit 3f5f355

Please sign in to comment.