Adding capability to get Dockerfile from URL. (#500)

* Changed to set http or https in Dockerfile path.

* Fixed return value when error.

* Fixed ineffectual error
This commit is contained in:
linuxshokunin 2019-01-03 16:42:15 +00:00 committed by dlorenc
parent e3bb8bc71a
commit c3afcc0c7d
2 changed files with 20 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"time"
@ -141,6 +142,9 @@ func cacheFlagsValid() error {
// resolveDockerfilePath resolves the Dockerfile path to an absolute path
func resolveDockerfilePath() error {
if match, _ := regexp.MatchString("^https?://", opts.DockerfilePath); match {
return nil
}
if util.FilepathExists(opts.DockerfilePath) {
abs, err := filepath.Abs(opts.DockerfilePath)
if err != nil {

View File

@ -20,6 +20,8 @@ import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"regexp"
"strconv"
"strings"
@ -32,10 +34,23 @@ import (
// Stages parses a Dockerfile and returns an array of KanikoStage
func Stages(opts *config.KanikoOptions) ([]config.KanikoStage, error) {
d, err := ioutil.ReadFile(opts.DockerfilePath)
var err error
var d []uint8
match, _ := regexp.MatchString("^https?://", opts.DockerfilePath)
if match {
response, e := http.Get(opts.DockerfilePath)
if e != nil {
return nil, e
}
d, err = ioutil.ReadAll(response.Body)
} else {
d, err = ioutil.ReadFile(opts.DockerfilePath)
}
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("reading dockerfile at path %s", opts.DockerfilePath))
}
stages, metaArgs, err := Parse(d)
if err != nil {
return nil, errors.Wrap(err, "parsing dockerfile")