mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
* feat(jobs): add job service interface * feat(jobs): create job execution api * style(jobs): remove comment * feat(jobs): add bindings * feat(jobs): validate payload different cases * refactor(jobs): rename endpointJob method * refactor(jobs): return original error * feat(jobs): pull image before creating container * feat(jobs): run jobs with sh * style(jobs): remove comment * refactor(jobs): change error names * feat(jobs): sync pull image * fix(jobs): close image reader after error check * style(jobs): remove comment and add docs * refactor(jobs): inline script command * fix(jobs): handle pul image error * refactor(jobs): handle image pull output * fix(docker): set http client timeout to 100s * fix(client): remove timeout from http client
36 lines
723 B
Go
36 lines
723 B
Go
package archive
|
|
|
|
import (
|
|
"archive/tar"
|
|
"bytes"
|
|
)
|
|
|
|
// TarFileInBuffer will create a tar archive containing a single file named via fileName and using the content
|
|
// specified in fileContent. Returns the archive as a byte array.
|
|
func TarFileInBuffer(fileContent []byte, fileName string, mode int64) ([]byte, error) {
|
|
var buffer bytes.Buffer
|
|
tarWriter := tar.NewWriter(&buffer)
|
|
|
|
header := &tar.Header{
|
|
Name: fileName,
|
|
Mode: mode,
|
|
Size: int64(len(fileContent)),
|
|
}
|
|
|
|
err := tarWriter.WriteHeader(header)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
_, err = tarWriter.Write(fileContent)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = tarWriter.Close()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return buffer.Bytes(), nil
|
|
}
|