mirror of
https://github.com/containers/podman
synced 2024-10-20 17:23:30 +00:00
Add Artifacts directory to containers
Create an artifacts directory in the container's static directory so store container information coming from outside of libpod to specified files An example is to hold data from user specified flags in kpod run/create such as --cap-add, --ipcMode, etc... Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #108 Approved by: mheon
This commit is contained in:
parent
4d02d99c27
commit
8d31ec2ad7
|
@ -50,6 +50,8 @@ const (
|
|||
ContainerStateStopped ContainerState = iota
|
||||
// ContainerStatePaused indicates that the container has been paused
|
||||
ContainerStatePaused ContainerState = iota
|
||||
// name of the directory holding the artifacts
|
||||
artifactsDir = "artifacts"
|
||||
)
|
||||
|
||||
// Container is a single OCI container
|
||||
|
@ -383,6 +385,11 @@ func (c *Container) setupStorage() error {
|
|||
c.config.StaticDir = containerInfo.Dir
|
||||
c.state.RunDir = containerInfo.RunDir
|
||||
|
||||
artifacts := filepath.Join(c.config.StaticDir, artifactsDir)
|
||||
if err := os.MkdirAll(artifacts, 0755); err != nil {
|
||||
return errors.Wrapf(err, "error creating artifacts directory %q", artifacts)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -396,6 +403,11 @@ func (c *Container) teardownStorage() error {
|
|||
return errors.Wrapf(ErrCtrStateInvalid, "cannot remove storage for container %s as it is running or paused", c.ID())
|
||||
}
|
||||
|
||||
artifacts := filepath.Join(c.config.StaticDir, artifactsDir)
|
||||
if err := os.RemoveAll(artifacts); err != nil {
|
||||
return errors.Wrapf(err, "error removing artifacts %q", artifacts)
|
||||
}
|
||||
|
||||
if err := c.cleanupStorage(); err != nil {
|
||||
return errors.Wrapf(err, "failed to cleanup container %s storage", c.ID())
|
||||
}
|
||||
|
@ -718,6 +730,25 @@ func (c *Container) Export(path string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// AddArtifact creates and writes to an artifact file for the container
|
||||
func (c *Container) AddArtifact(name string, data []byte) error {
|
||||
return ioutil.WriteFile(c.getArtifactPath(name), data, 0740)
|
||||
}
|
||||
|
||||
// GetArtifact reads the specified artifact file from the container
|
||||
func (c *Container) GetArtifact(name string) ([]byte, error) {
|
||||
return ioutil.ReadFile(c.getArtifactPath(name))
|
||||
}
|
||||
|
||||
// RemoveArtifact deletes the specified artifacts file
|
||||
func (c *Container) RemoveArtifact(name string) error {
|
||||
return os.Remove(c.getArtifactPath(name))
|
||||
}
|
||||
|
||||
func (c *Container) getArtifactPath(name string) string {
|
||||
return filepath.Join(c.config.StaticDir, artifactsDir, name)
|
||||
}
|
||||
|
||||
// Commit commits the changes between a container and its image, creating a new
|
||||
// image
|
||||
func (c *Container) Commit() (*storage.Image, error) {
|
||||
|
|
Loading…
Reference in a new issue