nolint:gocyclo
(ctx context.Context, project *types.Project, service types.ServiceConfig, options api.BuildOptions)
| 119 | |
| 120 | //nolint:gocyclo |
| 121 | func (s *composeService) doBuildImage(ctx context.Context, project *types.Project, service types.ServiceConfig, options api.BuildOptions) (string, error) { |
| 122 | var ( |
| 123 | buildCtx io.ReadCloser |
| 124 | dockerfileCtx io.ReadCloser |
| 125 | contextDir string |
| 126 | relDockerfile string |
| 127 | ) |
| 128 | |
| 129 | if len(service.Build.Platforms) > 1 { |
| 130 | return "", fmt.Errorf("the classic builder doesn't support multi-arch build, set DOCKER_BUILDKIT=1 to use BuildKit") |
| 131 | } |
| 132 | if service.Build.Privileged { |
| 133 | return "", fmt.Errorf("the classic builder doesn't support privileged mode, set DOCKER_BUILDKIT=1 to use BuildKit") |
| 134 | } |
| 135 | if len(service.Build.AdditionalContexts) > 0 { |
| 136 | return "", fmt.Errorf("the classic builder doesn't support additional contexts, set DOCKER_BUILDKIT=1 to use BuildKit") |
| 137 | } |
| 138 | if len(service.Build.SSH) > 0 { |
| 139 | return "", fmt.Errorf("the classic builder doesn't support SSH keys, set DOCKER_BUILDKIT=1 to use BuildKit") |
| 140 | } |
| 141 | if len(service.Build.Secrets) > 0 { |
| 142 | return "", fmt.Errorf("the classic builder doesn't support secrets, set DOCKER_BUILDKIT=1 to use BuildKit") |
| 143 | } |
| 144 | |
| 145 | if service.Build.Labels == nil { |
| 146 | service.Build.Labels = make(map[string]string) |
| 147 | } |
| 148 | service.Build.Labels[api.ImageBuilderLabel] = "classic" |
| 149 | |
| 150 | dockerfileName := dockerFilePath(service.Build.Context, service.Build.Dockerfile) |
| 151 | specifiedContext := service.Build.Context |
| 152 | progBuff := s.stdout() |
| 153 | buildBuff := s.stdout() |
| 154 | |
| 155 | contextType, err := build.DetectContextType(specifiedContext) |
| 156 | if err != nil { |
| 157 | return "", err |
| 158 | } |
| 159 | |
| 160 | switch contextType { |
| 161 | case build.ContextTypeStdin: |
| 162 | return "", fmt.Errorf("building from STDIN is not supported") |
| 163 | case build.ContextTypeLocal: |
| 164 | contextDir, relDockerfile, err = build.GetContextFromLocalDir(specifiedContext, dockerfileName) |
| 165 | if err != nil { |
| 166 | return "", fmt.Errorf("unable to prepare context: %w", err) |
| 167 | } |
| 168 | if strings.HasPrefix(relDockerfile, ".."+string(filepath.Separator)) { |
| 169 | // Dockerfile is outside build-context; read the Dockerfile and pass it as dockerfileCtx |
| 170 | dockerfileCtx, err = os.Open(dockerfileName) |
| 171 | if err != nil { |
| 172 | return "", fmt.Errorf("unable to open Dockerfile: %w", err) |
| 173 | } |
| 174 | defer dockerfileCtx.Close() //nolint:errcheck |
| 175 | } |
| 176 | case build.ContextTypeGit: |
| 177 | var tempDir string |
| 178 | tempDir, relDockerfile, err = build.GetContextFromGitURL(specifiedContext, dockerfileName) |
no test coverage detected