Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git spec handling revamp #771

Merged
merged 4 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions hack/test-stirunimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ test_debug "s2i build with relative path without file://"
s2i build cakephp-ex openshift/php-55-centos7 test --loglevel=5 &> "${WORK_DIR}/s2i-rel-noproto.log"
check_result $? "${WORK_DIR}/s2i-rel-noproto.log"

test_debug "s2i build with relative path with file://"

s2i build file://./cakephp-ex openshift/php-55-centos7 test --loglevel=5 &> "${WORK_DIR}/s2i-rel-proto.log"
check_result $? "${WORK_DIR}/s2i-rel-proto.log"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a test for a relative path without file:// ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, under the section marked "s2i build with relative path without file://" :-)


test_debug "s2i build with volume options"
s2i build cakephp-ex openshift/php-55-centos7 test --volume "${WORK_DIR}:/home/:z" --loglevel=5 &> "${WORK_DIR}/s2i-volume-correct.log"
check_result $? "${WORK_DIR}/s2i-volume-correct.log"
Expand All @@ -95,7 +90,13 @@ popd

test_debug "s2i build with absolute path with file://"

s2i build "file://${S2I_WORK_DIR}/cakephp-ex" openshift/php-55-centos7 test --loglevel=5 &> "${WORK_DIR}/s2i-abs-proto.log"
if [[ "$OSTYPE" == "cygwin" ]]; then
S2I_WORK_DIR_URL="file:///${S2I_WORK_DIR//\\//}/cakephp-ex"
else
S2I_WORK_DIR_URL="file://${S2I_WORK_DIR}/cakephp-ex"
fi

s2i build "${S2I_WORK_DIR_URL}" openshift/php-55-centos7 test --loglevel=5 &> "${WORK_DIR}/s2i-abs-proto.log"
check_result $? "${WORK_DIR}/s2i-abs-proto.log"

test_debug "s2i build with absolute path without file://"
Expand Down
3 changes: 0 additions & 3 deletions pkg/api/describe/describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ func Config(client docker.Client, config *api.Config) string {
describeBuilderImage(client, config, config.BuilderImage, out)
describeRuntimeImage(config, out)
fmt.Fprintf(out, "Source:\t%s\n", config.Source)
if len(config.Ref) > 0 {
fmt.Fprintf(out, "Source Ref:\t%s\n", config.Ref)
}
if len(config.ContextDir) > 0 {
fmt.Fprintf(out, "Context Directory:\t%s\n", config.ContextDir)
}
Expand Down
59 changes: 3 additions & 56 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"
"time"

"github.com/openshift/source-to-image/pkg/scm/git"
utilglog "github.com/openshift/source-to-image/pkg/util/glog"

"github.com/openshift/source-to-image/pkg/util/user"
)

Expand Down Expand Up @@ -113,10 +113,7 @@ type Config struct {
IgnoreSubmodules bool

// Source URL describing the location of sources used to build the result image.
Source string

// Ref is a tag/branch to be used for build.
Ref string
Source *git.URL

// Tag is a result image tag name.
Tag string
Expand Down Expand Up @@ -236,7 +233,7 @@ type Config struct {

// SourceInfo provides the info about the source to be built rather than relying
// on the Downloader to retrieve it.
SourceInfo *SourceInfo
SourceInfo *git.SourceInfo
}

// EnvironmentSpec specifies a single environment variable.
Expand Down Expand Up @@ -461,56 +458,6 @@ type InstallResult struct {
FailedSources []string
}

// SourceInfo stores information about the source code
type SourceInfo struct {
// Ref represents a commit SHA-1, valid Git branch name or a Git tag
// The output image will contain this information as 'io.openshift.build.commit.ref' label.
Ref string

// CommitID represents an arbitrary extended object reference in Git as SHA-1
// The output image will contain this information as 'io.openshift.build.commit.id' label.
CommitID string

// Date contains a date when the committer created the commit.
// The output image will contain this information as 'io.openshift.build.commit.date' label.
Date string

// AuthorName contains the name of the author
// The output image will contain this information (along with AuthorEmail) as 'io.openshift.build.commit.author' label.
AuthorName string

// AuthorEmail contains the e-mail of the author
// The output image will contain this information (along with AuthorName) as 'io.openshift.build.commit.author' lablel.
AuthorEmail string

// CommitterName contains the name of the committer
CommitterName string

// CommitterEmail contains the e-mail of the committer
CommitterEmail string

// Message represents the first 80 characters from the commit message.
// The output image will contain this information as 'io.openshift.build.commit.message' label.
Message string

// Location contains a valid URL to the original repository.
// The output image will contain this information as 'io.openshift.build.source-location' label.
Location string

// ContextDir contains path inside the Location directory that
// contains the application source code.
// The output image will contain this information as 'io.openshift.build.source-context-dir'
// label.
ContextDir string
}

// CloneConfig specifies the options used when cloning the application source
// code.
type CloneConfig struct {
Recursive bool
Quiet bool
}

// DockerNetworkMode specifies the network mode setting for the docker container
type DockerNetworkMode string

Expand Down
17 changes: 9 additions & 8 deletions pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/scm/git"
)

func TestValidation(t *testing.T) {
Expand All @@ -14,7 +15,7 @@ func TestValidation(t *testing.T) {
}{
{
&api.Config{
Source: "http://github.com/openshift/source",
Source: git.MustParse("http://github.com/openshift/source"),
BuilderImage: "openshift/builder",
DockerConfig: &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
BuilderPullPolicy: api.DefaultBuilderPullPolicy,
Expand All @@ -23,7 +24,7 @@ func TestValidation(t *testing.T) {
},
{
&api.Config{
Source: "http://github.com/openshift/source",
Source: git.MustParse("http://github.com/openshift/source"),
BuilderImage: "openshift/builder",
DockerConfig: &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
DockerNetworkMode: "foobar",
Expand All @@ -33,7 +34,7 @@ func TestValidation(t *testing.T) {
},
{
&api.Config{
Source: "http://github.com/openshift/source",
Source: git.MustParse("http://github.com/openshift/source"),
BuilderImage: "openshift/builder",
DockerConfig: &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
DockerNetworkMode: api.NewDockerNetworkModeContainer("8d873e496bc3e80a1cb22e67f7de7be5b0633e27916b1144978d1419c0abfcdb"),
Expand All @@ -43,7 +44,7 @@ func TestValidation(t *testing.T) {
},
{
&api.Config{
Source: "",
Source: nil,
BuilderImage: "openshift/builder",
DockerConfig: &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
DockerNetworkMode: api.NewDockerNetworkModeContainer("8d873e496bc3e80a1cb22e67f7de7be5b0633e27916b1144978d1419c0abfcdb"),
Expand All @@ -53,7 +54,7 @@ func TestValidation(t *testing.T) {
},
{
&api.Config{
Source: "http://github.com/openshift/source",
Source: git.MustParse("http://github.com/openshift/source"),
BuilderImage: "openshift/builder",
DockerConfig: &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
BuilderPullPolicy: api.DefaultBuilderPullPolicy,
Expand All @@ -63,7 +64,7 @@ func TestValidation(t *testing.T) {
},
{
&api.Config{
Source: "http://github.com/openshift/source",
Source: git.MustParse("http://github.com/openshift/source"),
BuilderImage: "openshift/builder",
DockerConfig: &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
BuilderPullPolicy: api.DefaultBuilderPullPolicy,
Expand All @@ -73,7 +74,7 @@ func TestValidation(t *testing.T) {
},
{
&api.Config{
Source: "http://github.com/openshift/source",
Source: git.MustParse("http://github.com/openshift/source"),
BuilderImage: "openshift/builder",
DockerConfig: &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
BuilderPullPolicy: api.DefaultBuilderPullPolicy,
Expand All @@ -83,7 +84,7 @@ func TestValidation(t *testing.T) {
},
{
&api.Config{
Source: "http://github.com/openshift/source",
Source: git.MustParse("http://github.com/openshift/source"),
BuilderImage: "openshift/builder",
DockerConfig: &api.DockerConfig{Endpoint: "/var/run/docker.socket"},
BuilderPullPolicy: api.DefaultBuilderPullPolicy,
Expand Down
6 changes: 3 additions & 3 deletions pkg/build/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package build
import (
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/docker"
"github.com/openshift/source-to-image/pkg/util"
"github.com/openshift/source-to-image/pkg/util/fs"
utilglog "github.com/openshift/source-to-image/pkg/util/glog"
)

Expand All @@ -13,12 +13,12 @@ var glog = utilglog.StderrLog
// temporary directories created by STI build and it also cleans the temporary
// Docker images produced by LayeredBuild
type DefaultCleaner struct {
fs util.FileSystem
fs fs.FileSystem
docker docker.Docker
}

// NewDefaultCleaner creates a new instance of the default Cleaner implementation
func NewDefaultCleaner(fs util.FileSystem, docker docker.Docker) Cleaner {
func NewDefaultCleaner(fs fs.FileSystem, docker docker.Docker) Cleaner {
return &DefaultCleaner{
fs: fs,
docker: docker,
Expand Down
11 changes: 8 additions & 3 deletions pkg/build/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/docker"
"github.com/openshift/source-to-image/pkg/scm/git"
)

// GenerateConfigFromLabels generates the S2I Config struct from the Docker
Expand Down Expand Up @@ -41,13 +42,17 @@ func GenerateConfigFromLabels(config *api.Config, metadata *docker.PullResult) e
}

if repo, ok := labels[api.DefaultNamespace+"build.source-location"]; ok {
config.Source = repo
source, err := git.Parse(repo)
if err != nil {
return fmt.Errorf("couldn't parse label %q value %s: %v", api.DefaultNamespace+"build.source-location", repo, err)
}
config.Source = source
} else {
return fmt.Errorf("required label %q not found in image", api.DefaultNamespace+"source-location")
return fmt.Errorf("required label %q not found in image", api.DefaultNamespace+"build.source-location")
}

config.ContextDir = labels[api.DefaultNamespace+"build.source-context-dir"]
config.Ref = labels[api.DefaultNamespace+"build.commit.ref"]
config.Source.URL.Fragment = labels[api.DefaultNamespace+"build.commit.ref"]

return nil
}
7 changes: 5 additions & 2 deletions pkg/build/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package build

import "github.com/openshift/source-to-image/pkg/api"
import (
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/scm/git"
)

// Builder is the interface that provides basic methods all implementation
// should have.
Expand Down Expand Up @@ -38,7 +41,7 @@ type ScriptsHandler interface {

// Downloader provides methods for downloading the application source code
type Downloader interface {
Download(*api.Config) (*api.SourceInfo, error)
Download(*api.Config) (*git.SourceInfo, error)
}

// Ignorer provides ignore file processing on source tree
Expand Down
6 changes: 3 additions & 3 deletions pkg/build/strategies/layered/layered.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/openshift/source-to-image/pkg/docker"
s2ierr "github.com/openshift/source-to-image/pkg/errors"
"github.com/openshift/source-to-image/pkg/tar"
"github.com/openshift/source-to-image/pkg/util"
"github.com/openshift/source-to-image/pkg/util/fs"
utilglog "github.com/openshift/source-to-image/pkg/util/glog"
utilstatus "github.com/openshift/source-to-image/pkg/util/status"
)
Expand All @@ -34,14 +34,14 @@ const defaultDestination = "/tmp"
type Layered struct {
config *api.Config
docker docker.Docker
fs util.FileSystem
fs fs.FileSystem
tar tar.Tar
scripts build.ScriptsHandler
hasOnBuild bool
}

// New creates a Layered builder.
func New(client docker.Client, config *api.Config, fs util.FileSystem, scripts build.ScriptsHandler, overrides build.Overrides) (*Layered, error) {
func New(client docker.Client, config *api.Config, fs fs.FileSystem, scripts build.ScriptsHandler, overrides build.Overrides) (*Layered, error) {
excludePattern, err := regexp.Compile(config.ExcludeRegExp)
if err != nil {
return nil, err
Expand Down
7 changes: 4 additions & 3 deletions pkg/build/strategies/layered/layered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/openshift/source-to-image/pkg/build"
"github.com/openshift/source-to-image/pkg/docker"
"github.com/openshift/source-to-image/pkg/test"
testfs "github.com/openshift/source-to-image/pkg/test/fs"
)

type FakeExecutor struct{}
Expand All @@ -26,7 +27,7 @@ func newFakeLayered() *Layered {
return &Layered{
docker: &docker.FakeDocker{},
config: &api.Config{},
fs: &test.FakeFileSystem{},
fs: &testfs.FakeFileSystem{},
tar: &test.FakeTar{},
scripts: &FakeExecutor{},
}
Expand All @@ -36,7 +37,7 @@ func newFakeLayeredWithScripts(workDir string) *Layered {
return &Layered{
docker: &docker.FakeDocker{},
config: &api.Config{WorkingDir: workDir},
fs: &test.FakeFileSystem{},
fs: &testfs.FakeFileSystem{},
tar: &test.FakeTar{},
scripts: &FakeExecutor{},
}
Expand Down Expand Up @@ -143,7 +144,7 @@ func TestBuildNoScriptsProvided(t *testing.T) {
func TestBuildErrorWriteDockerfile(t *testing.T) {
l := newFakeLayered()
l.config.BuilderImage = "test/image"
l.fs.(*test.FakeFileSystem).WriteFileError = errors.New("WriteDockerfileError")
l.fs.(*testfs.FakeFileSystem).WriteFileError = errors.New("WriteDockerfileError")
_, err := l.Build(l.config)
if err == nil || err.Error() != "WriteDockerfileError" {
t.Errorf("An error was expected for WriteDockerfile, but got different: %v", err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/build/strategies/onbuild/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path/filepath"
"regexp"

"github.com/openshift/source-to-image/pkg/util"
"github.com/openshift/source-to-image/pkg/util/fs"
utilglog "github.com/openshift/source-to-image/pkg/util/glog"
)

Expand All @@ -20,7 +20,7 @@ var validEntrypoints = []*regexp.Regexp{

// GuessEntrypoint tries to guess the valid entrypoint from the source code
// repository. The valid entrypoints are defined above (run,start,exec,execute)
func GuessEntrypoint(fs util.FileSystem, sourceDir string) (string, error) {
func GuessEntrypoint(fs fs.FileSystem, sourceDir string) (string, error) {
files, err := fs.ReadDir(sourceDir)
if err != nil {
return "", err
Expand All @@ -40,7 +40,7 @@ func GuessEntrypoint(fs util.FileSystem, sourceDir string) (string, error) {
// isValidEntrypoint checks if the given file exists and if it is a regular
// file. Valid ENTRYPOINT must be an executable file, so the executable bit must
// be set.
func isValidEntrypoint(fs util.FileSystem, path string) bool {
func isValidEntrypoint(fs fs.FileSystem, path string) bool {
stat, err := fs.Stat(path)
if err != nil {
return false
Expand Down
Loading