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:
parent
e3bb8bc71a
commit
c3afcc0c7d
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -141,6 +142,9 @@ func cacheFlagsValid() error {
|
||||||
|
|
||||||
// resolveDockerfilePath resolves the Dockerfile path to an absolute path
|
// resolveDockerfilePath resolves the Dockerfile path to an absolute path
|
||||||
func resolveDockerfilePath() error {
|
func resolveDockerfilePath() error {
|
||||||
|
if match, _ := regexp.MatchString("^https?://", opts.DockerfilePath); match {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if util.FilepathExists(opts.DockerfilePath) {
|
if util.FilepathExists(opts.DockerfilePath) {
|
||||||
abs, err := filepath.Abs(opts.DockerfilePath)
|
abs, err := filepath.Abs(opts.DockerfilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
@ -32,10 +34,23 @@ import (
|
||||||
|
|
||||||
// Stages parses a Dockerfile and returns an array of KanikoStage
|
// Stages parses a Dockerfile and returns an array of KanikoStage
|
||||||
func Stages(opts *config.KanikoOptions) ([]config.KanikoStage, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, fmt.Sprintf("reading dockerfile at path %s", opts.DockerfilePath))
|
return nil, errors.Wrap(err, fmt.Sprintf("reading dockerfile at path %s", opts.DockerfilePath))
|
||||||
}
|
}
|
||||||
|
|
||||||
stages, metaArgs, err := Parse(d)
|
stages, metaArgs, err := Parse(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "parsing dockerfile")
|
return nil, errors.Wrap(err, "parsing dockerfile")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue