Skip to content

Commit

Permalink
Merge pull request #207 from soltysh/issue205
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Jun 1, 2015
2 parents e2e4148 + fee5e48 commit 77e3b72
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 102 deletions.
31 changes: 27 additions & 4 deletions cmd/sti/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func newCmdVersion() *cobra.Command {

func newCmdBuild(cfg *api.Config) *cobra.Command {
useConfig := false
oldScriptsFlag := ""
oldDestination := ""

buildCmd := &cobra.Command{
Use: "build <source> <image> [<tag>]",
Expand Down Expand Up @@ -143,6 +145,15 @@ func newCmdBuild(cfg *api.Config) *cobra.Command {
cfg.Environment[k] = v
}

if len(oldScriptsFlag) != 0 {
glog.Warning("Flag --scripts is deprecated, use --scripts-url instead")
cfg.ScriptsURL = oldScriptsFlag
}
if len(oldDestination) != 0 {
glog.Warning("Flag --location is deprecated, use --destination instead")
cfg.Destination = oldDestination
}

if glog.V(2) {
fmt.Printf("\n%s\n", describe.DescribeConfig(cfg))
}
Expand All @@ -164,8 +175,10 @@ func newCmdBuild(cfg *api.Config) *cobra.Command {
buildCmd.Flags().StringP("env", "e", "", "Specify an environment var NAME=VALUE,NAME2=VALUE2,...")
buildCmd.Flags().StringVarP(&(cfg.Ref), "ref", "r", "", "Specify a ref to check-out")
buildCmd.Flags().StringVar(&(cfg.CallbackURL), "callback-url", "", "Specify a URL to invoke via HTTP POST upon build completion")
buildCmd.Flags().StringVarP(&(cfg.ScriptsURL), "scripts", "s", "", "Specify a URL for the assemble and run scripts")
buildCmd.Flags().StringVarP(&(cfg.Location), "location", "l", "", "Specify a destination location for untar operation")
buildCmd.Flags().StringVarP(&(cfg.ScriptsURL), "scripts-url", "s", "", "Specify a URL for the assemble and run scripts")
buildCmd.Flags().StringVar(&(oldScriptsFlag), "scripts", "", "Specify a URL for the assemble and run scripts")
buildCmd.Flags().StringVarP(&(oldDestination), "location", "l", "", "Specify a destination location for untar operation")
buildCmd.Flags().StringVarP(&(cfg.Destination), "destination", "d", "", "Specify a destination location for untar operation")
buildCmd.Flags().BoolVar(&(cfg.ForcePull), "force-pull", true, "Always pull the builder image even if it is present locally")
buildCmd.Flags().BoolVar(&(cfg.PreserveWorkingDir), "save-temp-dir", false, "Save the temporary directory used by STI instead of deleting it")
buildCmd.Flags().BoolVar(&(useConfig), "use-config", false, "Store command line options to .stifile")
Expand Down Expand Up @@ -195,6 +208,9 @@ func newCmdCreate() *cobra.Command {
}

func newCmdUsage(cfg *api.Config) *cobra.Command {
oldScriptsFlag := ""
oldDestination := ""

usageCmd := &cobra.Command{
Use: "usage <image>",
Short: "Print usage of the assemble script associated with the image",
Expand All @@ -210,17 +226,24 @@ func newCmdUsage(cfg *api.Config) *cobra.Command {
checkErr(err)
cfg.Environment = envs

if len(oldScriptsFlag) != 0 {
glog.Warning("Flag --scripts is deprecated, use --scripts-url instead")
cfg.ScriptsURL = oldScriptsFlag
}

uh, err := sti.NewUsage(cfg)
checkErr(err)
err = uh.Show()
checkErr(err)
},
}
usageCmd.Flags().StringP("env", "e", "", "Specify an environment var NAME=VALUE,NAME2=VALUE2,...")
usageCmd.Flags().StringVarP(&(cfg.ScriptsURL), "scripts", "s", "", "Specify a URL for the assemble and run scripts")
usageCmd.Flags().StringVarP(&(cfg.ScriptsURL), "scripts-url", "s", "", "Specify a URL for the assemble and run scripts")
usageCmd.Flags().StringVar(&(oldScriptsFlag), "scripts", "", "Specify a URL for the assemble and run scripts")
usageCmd.Flags().BoolVar(&(cfg.ForcePull), "force-pull", true, "Always pull the builder image even if it is present locally")
usageCmd.Flags().BoolVar(&(cfg.PreserveWorkingDir), "save-temp-dir", false, "Save the temporary directory used by STI instead of deleting it")
usageCmd.Flags().StringVarP(&(cfg.Location), "location", "l", "", "Specify a destination location for untar operation")
usageCmd.Flags().StringVarP(&(oldDestination), "location", "l", "", "Specify a destination location for untar operation")
usageCmd.Flags().StringVarP(&(cfg.Destination), "destination", "d", "", "Specify a destination location for untar operation")
return usageCmd
}

Expand Down
6 changes: 3 additions & 3 deletions docs/builder_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ final docker image, the three are: sources, scripts and builder image. During th
build process sti must place sources and scripts inside that builder image. To do
so sti creates a tar file containing the two and then streams that file into the
builder image. Before executing `assemble` script, sti untars that file and places
its contents into the location specified with `--location` flag or `io.openshift.sti.location`
label from the builder image (default location is `/tmp`). For this
its contents into the destination specified with `--destination` flag or `io.s2i.destination`
label from the builder image (default destination is `/tmp`). For this
to happen your image must supply tar archiving utility (command `tar` available in `$PATH`)
and command line interpreter (command `/bin/sh`). Doing so will allow your image to
use the fastest possible build path, because in all other cases when either
Expand Down Expand Up @@ -55,7 +55,7 @@ and place them into appropriate directories inside the image. The workflow for `

1. Restore build artifacts (in case you want to support incremental builds, make sure
to define [save-artifacts](#save-artifacts)) as well.
1. Place the application source in desired location.
1. Place the application source in desired destination.
1. Build application artifacts.
1. Install the artifacts into locations appropriate for running.

Expand Down
30 changes: 15 additions & 15 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ that image and add them to the tar streamed to the container into `/artifacts`.
| Name | Description |
|:-------------------------- |:--------------------------------------------------------|
| `--callback-url` | URL to be invoked after successful build (see [Callback URL](#callback-url)) |
| `-d (--destination)` | Location where the scripts and sources will be placed prior doing build (see [STI Scripts](#sti-scripts))|
| `--dockercfg-path` | Specify the path to the Docker configuration file |
| `--incremental` | Try performing an incremental build |
| `-e (--env)` | Environment variables passed to the builder eg. `NAME=VALUE,NAME2=VALUE2,...` |
| `--force-pull` | Always pull the builder image, even if it is present locally |
| `-l (--location)` | Location where the scripts and sources will be placed prior doing build (see [STI Scripts](#sti-scripts))|
| `-r (--ref)` | A branch/tag from which the build should happen (applies only to GIT source) |
| `--rm` | Remove previous image during incremental build |
| `--save-temp-dir` | Save the working directory used for fetching scripts and sources |
| `--context-dir` | Allow to specify directory name with your application |
| `-s (--scripts)` | URL of STI scripts (see [STI Scripts](#sti-scripts)) |
| `-s (--scripts-url)` | URL of STI scripts (see [STI Scripts](#sti-scripts)) |
| `-q (--quiet)` | Operate quietly, suppressing all non-error output |

#### Context directory
Expand Down Expand Up @@ -103,25 +103,25 @@ Example data posted will be of the form:
STI supports multiple options providing `assemble`/`run`/`save-artifacts` scripts.
All of these locations are checked on each build in the following order:

1. A script found at the `--scripts` URL
1. A script found at the `--scripts-url` URL
1. A script found in the application source `.sti/bin` directory
1. A script found at the default image URL (`io.openshift.sti.scripts-url` label)
1. A script found at the default image URL (`io.s2i.scripts-url` label)

Both `io.openshift.sti.scripts-url` label specified in the image and `--scripts` flag
Both `io.s2i.scripts-url` label specified in the image and `--scripts-url` flag
can take one of the following form:

* `image://path_to_scripts_dir` - absolute path inside the image to a directory where the STI scripts are located
* `file://path_to_scripts_dir` - relative or absolute path to a directory on the host where the STI scripts are located
* `http(s)://path_to_scripts_dir` - URL to a directory where the STI scripts are located

Additionally we allow specifying the location of both scripts and sources inside the image
prior executing the `assemble` script with `--location` flag or `io.openshift.sti.location`
prior executing the `assemble` script with `--destination` flag or `io.s2i.destination`
label set inside the image. The expected value of this flag is absolute and existing path
inside the image, if none is specified the default value of `/tmp` is being used.
In case of both of these specified the `--location` flag takes precedence over the environment variable.
In case of both of these specified the `--destination` flag takes precedence over the environment variable.

**NOTE**: In case where the scripts are already placed inside the image (using `--scripts`
or `io.openshift.sti.scripts-url` with value `image:///path/in/image`) then this value applies only to
**NOTE**: In case where the scripts are already placed inside the image (using `--scripts-url`
or `io.s2i.scripts-url` with value `image:///path/in/image`) then this value applies only to
sources and artifacts.

#### Example Usage
Expand All @@ -145,7 +145,7 @@ builder image but overriding the scripts URL from local directory, the resulting
image will be named `java-app`:

```
$ sti build --scripts=file://stiscripts git://github.com/bparees/openshift-jee-sample openshift/wildfly-8-centos java-app
$ sti build --scripts-url=file://stiscripts git://github.com/bparees/openshift-jee-sample openshift/wildfly-8-centos java-app
```

Build a ruby application from a GIT source, specifying `ref`, using the official
Expand All @@ -161,7 +161,7 @@ Build a ruby application from a GIT source, overriding the scripts URL from a lo
and forcing the scripts and sources to be placed in `/opt` directory:

```
$ sti build --scripts=file://stiscripts --location=/opt git://github.com/mfojtik/sinatra-app-example openshift/ruby-20-centos7 ruby-app
$ sti build --scripts-url=file://stiscripts --destination=/opt git://github.com/mfojtik/sinatra-app-example openshift/ruby-20-centos7 ruby-app
```


Expand All @@ -175,11 +175,11 @@ the only parameter.

| Name | Description |
|:-------------------------- |:--------------------------------------------------------|
| `-d (--destination)` | Location where the scripts and sources will be placed prior invoking usage (see [STI Scripts](#sti-scripts))|
| `-e (--env)` | Environment variables passed to the builder eg. `NAME=VALUE,NAME2=VALUE2,...`) |
| `--force-pull` | Always pull the builder image, even if it is present locally |
| `-l (--location)` | Location where the scripts and sources will be placed prior invoking usage (see [STI Scripts](#sti-scripts))|
| `--save-temp-dir` | Save the working directory used for fetching scripts and sources |
| `-s (--scripts)` | URL of STI scripts (see [Scripts URL](#scripts-url))|
| `--force-pull` | Always pull the builder image, even if it is present locally |
| `--save-temp-dir` | Save the working directory used for fetching scripts and sources |
| `-s (--scripts-url)` | URL of STI scripts (see [Scripts URL](#scripts-url))|

#### Example Usage

Expand Down
6 changes: 3 additions & 3 deletions pkg/api/describe/describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func DescribeConfig(config *api.Config) string {
fmt.Fprintf(out, "Remove Old Build:\t%s\n", printBool(config.RemovePreviousImage))
fmt.Fprintf(out, "Force Pull:\t%s\n", printBool(config.ForcePull))
fmt.Fprintf(out, "Quiet:\t%s\n", printBool(config.Quiet))
// fmt.Fprintf(out, "Layered Build:\t%s\n", printBool(config.LayeredBuild))
if len(config.Location) > 0 {
fmt.Fprintf(out, "Artifacts Location:\t%s\n", config.Location)
fmt.Fprintf(out, "Layered Build:\t%s\n", printBool(config.LayeredBuild))
if len(config.Destination) > 0 {
fmt.Fprintf(out, "Artifacts Destination:\t%s\n", config.Destination)
}
if len(config.CallbackURL) > 0 {
fmt.Fprintf(out, "Callback URL:\t%s\n", config.CallbackURL)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
const (
// UserScripts is the location of scripts downloaded from user provided URL (-s flag).
UserScripts = "downloads/scripts"
// DefaultScripts is the location of scripts downloaded from default location (io.openshift.sti.scripts-url label).
// DefaultScripts is the location of scripts downloaded from default location (io.s2i.scripts-url label).
DefaultScripts = "downloads/defaultScripts"
// SourceScripts is the location of scripts downloaded with application sources.
SourceScripts = "upload/src/.sti/bin"
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ type Config struct {
// ScriptsURL is a URL describing the localization of STI scripts used during build process.
ScriptsURL string

// Location specifies a location where the untar operation will place its artifacts.
Location string
// Destination specifies a location where the untar operation will place its artifacts.
Destination string

// ForcePull describes if the builder should pull the images from registry prior to building.
ForcePull bool
Expand Down
18 changes: 9 additions & 9 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/util"
)

const defaultLocation = "/tmp"
const defaultDestination = "/tmp"

type Layered struct {
config *api.Config
Expand All @@ -41,12 +41,12 @@ func New(config *api.Config, scripts build.ScriptsHandler) (*Layered, error) {
}, nil
}

func getLocation(config *api.Config) string {
location := config.Location
if len(location) == 0 {
location = defaultLocation
func getDestination(config *api.Config) string {
destination := config.Destination
if len(destination) == 0 {
destination = defaultDestination
}
return location
return destination
}

func (b *Layered) CreateDockerfile(config *api.Config) error {
Expand All @@ -58,8 +58,8 @@ func (b *Layered) CreateDockerfile(config *api.Config) error {
}

locations := []string{
filepath.Join(getLocation(config), "scripts"),
filepath.Join(getLocation(config), "src"),
filepath.Join(getDestination(config), "scripts"),
filepath.Join(getDestination(config), "src"),
}

buffer.WriteString(fmt.Sprintf("FROM %s\n", b.config.BuilderImage))
Expand Down Expand Up @@ -140,7 +140,7 @@ func (b *Layered) Build(config *api.Config) (*api.Result, error) {
// new image name
b.config.BuilderImage = newBuilderImage
// the scripts are inside the image
b.config.ScriptsURL = "image://" + filepath.Join(getLocation(config), "scripts")
b.config.ScriptsURL = "image://" + filepath.Join(getDestination(config), "scripts")

glog.V(2).Infof("Building %s using sti-enabled image", b.config.Tag)
if err := b.scripts.Execute(api.Assemble, b.config); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/build/strategies/layered/layered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestBuildOK(t *testing.T) {
if l.config.ScriptsURL != "image:///tmp/scripts" {
t.Error("Expected ScriptsURL image:///tmp/scripts, but got %s", l.config.ScriptsURL)
}
if len(l.config.Location) != 0 {
t.Errorf("Unexpected Location %s", l.config.Location)
if len(l.config.Destination) != 0 {
t.Errorf("Unexpected Destination %s", l.config.Destination)
}
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/build/strategies/sti/sti.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
const (
// maxErrorOutput is the maximum length of the error output saved for processing
maxErrorOutput = 1024
// defaultLocation is the default location of the scripts and sources in image
defaultLocation = "/tmp"
)

var (
Expand Down Expand Up @@ -307,7 +305,7 @@ func (b *STI) Save(config *api.Config) (err error) {
Image: image,
ExternalScripts: b.externalScripts[api.SaveArtifacts],
ScriptsURL: config.ScriptsURL,
Location: config.Location,
Destination: config.Destination,
Command: api.SaveArtifacts,
Stdout: outWriter,
Stderr: errWriter,
Expand Down Expand Up @@ -365,7 +363,7 @@ func (b *STI) Execute(command string, config *api.Config) error {
PullImage: config.ForcePull,
ExternalScripts: externalScripts,
ScriptsURL: config.ScriptsURL,
Location: config.Location,
Destination: config.Destination,
Command: command,
Env: buildEnv,
PostExec: b.postExecutor,
Expand Down
10 changes: 5 additions & 5 deletions pkg/build/strategies/sti/sti_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type FakeSTI struct {
ExpectedError bool
LayeredBuildCalled bool
LayeredBuildError error
PostExecuteLocation string
PostExecuteDestination string
PostExecuteContainerID string
PostExecuteError error
}
Expand Down Expand Up @@ -114,9 +114,9 @@ func (f *FakeSTI) wasExpectedError(text string) bool {
return f.ExpectedError
}

func (f *FakeSTI) PostExecute(id, location string) error {
func (f *FakeSTI) PostExecute(id, destination string) error {
f.PostExecuteContainerID = id
f.PostExecuteLocation = location
f.PostExecuteDestination = destination
return f.PostExecuteError
}

Expand Down Expand Up @@ -681,8 +681,8 @@ func TestExecuteOK(t *testing.T) {
t.Errorf("PostExecutor not called with expected ID: %s",
pe.PostExecuteContainerID)
}
if !reflect.DeepEqual(pe.PostExecuteLocation, "test-command") {
t.Errorf("PostExecutor not called with expected command: %s", pe.PostExecuteLocation)
if !reflect.DeepEqual(pe.PostExecuteDestination, "test-command") {
t.Errorf("PostExecutor not called with expected command: %s", pe.PostExecuteDestination)
}
}

Expand Down
Loading

0 comments on commit 77e3b72

Please sign in to comment.