-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from priyawadhwa/run
Run command
- Loading branch information
Showing
18 changed files
with
350 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2018 Google, Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM gcr.io/google-appengine/debian9 | ||
RUN echo "hey" > /etc/foo | ||
RUN apt-get update && apt-get install -y \ | ||
bzr \ | ||
cvs \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2018 Google, Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Test to make sure the executor builds an image correctly | ||
# when no files are changed | ||
|
||
FROM gcr.io/google-appengine/debian9 | ||
RUN echo "hey" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[ | ||
{ | ||
"Image1": "gcr.io/kbuild-test/docker-test-run:latest", | ||
"Image2": "gcr.io/kbuild-test/kbuild-test-run:latest", | ||
"DiffType": "File", | ||
"Diff": { | ||
"Adds": null, | ||
"Dels": null, | ||
"Mods": [ | ||
{ | ||
"Name": "/var/log/dpkg.log", | ||
"Size1": 57425, | ||
"Size2": 57425 | ||
}, | ||
{ | ||
"Name": "/var/log/apt/term.log", | ||
"Size1": 24400, | ||
"Size2": 24400 | ||
}, | ||
{ | ||
"Name": "/var/cache/ldconfig/aux-cache", | ||
"Size1": 8057, | ||
"Size2": 8057 | ||
}, | ||
{ | ||
"Name": "/var/log/apt/history.log", | ||
"Size1": 5089, | ||
"Size2": 5089 | ||
}, | ||
{ | ||
"Name": "/var/log/alternatives.log", | ||
"Size1": 2579, | ||
"Size2": 2579 | ||
}, | ||
{ | ||
"Name": "/usr/lib/python2.7/dist-packages/keyrings/__init__.pyc", | ||
"Size1": 140, | ||
"Size2": 140 | ||
}, | ||
{ | ||
"Name": "/usr/lib/python2.7/dist-packages/lazr/__init__.pyc", | ||
"Size1": 136, | ||
"Size2": 136 | ||
} | ||
] | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"Image1": "gcr.io/kbuild-test/docker-test-run-2:latest", | ||
"Image2": "gcr.io/kbuild-test/kbuild-test-run-2:latest", | ||
"DiffType": "File", | ||
"Diff": { | ||
"Adds": null, | ||
"Dels": null, | ||
"Mods": null | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright 2018 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package commands | ||
|
||
import ( | ||
"github.com/containers/image/manifest" | ||
"github.com/docker/docker/builder/dockerfile/instructions" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type DockerCommand interface { | ||
// ExecuteCommand is responsible for: | ||
// 1. Making required changes to the filesystem (ex. copying files for ADD/COPY or setting ENV variables) | ||
// 2. Updating metadata fields in the config | ||
// It should not change the config history. | ||
ExecuteCommand(*manifest.Schema2Config) error | ||
// The config history has a "created by" field, should return information about the command | ||
CreatedBy() string | ||
// A list of files to snapshot, empty for metadata commands or nil if we don't know | ||
FilesToSnapshot() []string | ||
} | ||
|
||
func GetCommand(cmd instructions.Command) (DockerCommand, error) { | ||
switch c := cmd.(type) { | ||
case *instructions.RunCommand: | ||
return &RunCommand{cmd: c}, nil | ||
} | ||
return nil, errors.Errorf("%s is not a supported command", cmd.Name()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2018 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package commands | ||
|
||
import ( | ||
"github.com/containers/image/manifest" | ||
"github.com/docker/docker/builder/dockerfile/instructions" | ||
"github.com/sirupsen/logrus" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
type RunCommand struct { | ||
cmd *instructions.RunCommand | ||
} | ||
|
||
func (r *RunCommand) ExecuteCommand(config *manifest.Schema2Config) error { | ||
var newCommand []string | ||
if r.cmd.PrependShell { | ||
// This is the default shell on Linux | ||
// TODO: Support shell command here | ||
shell := []string{"/bin/sh", "-c"} | ||
newCommand = append(shell, strings.Join(r.cmd.CmdLine, " ")) | ||
} else { | ||
newCommand = r.cmd.CmdLine | ||
} | ||
|
||
logrus.Infof("cmd: %s", newCommand[0]) | ||
logrus.Infof("args: %s", newCommand[1:]) | ||
|
||
cmd := exec.Command(newCommand[0], newCommand[1:]...) | ||
cmd.Stdout = os.Stdout | ||
return cmd.Run() | ||
} | ||
|
||
// FilesToSnapshot returns nil for this command because we don't know which files | ||
// have changed, so we snapshot the entire system. | ||
func (r *RunCommand) FilesToSnapshot() []string { | ||
return nil | ||
} | ||
|
||
// Author returns some information about the command for the image config | ||
func (r *RunCommand) CreatedBy() string { | ||
cmdLine := strings.Join(r.cmd.CmdLine, " ") | ||
if r.cmd.PrependShell { | ||
// TODO: Support shell command here | ||
shell := []string{"/bin/sh", "-c"} | ||
return strings.Join(append(shell, cmdLine), " ") | ||
} | ||
return cmdLine | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,6 @@ const ( | |
WorkspaceDir = "/workspace" | ||
|
||
WhitelistPath = "/proc/self/mountinfo" | ||
|
||
Author = "kbuild" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.