16 Commits

Author SHA1 Message Date
OP (oppenheimer) f91fa71be0 Merge pull request #13 from drone-plugins/CI-18178
feat: [CI-18178]: Add tar save and load capability with Docker archive support for buildah plugin
2025-07-10 18:51:02 +05:30
Ompragash Viswanathan a84121e813 Updated docker.go 2025-07-10 09:58:44 +05:30
Ompragash Viswanathan 291f18b59e Updated docker.go 2025-07-09 20:37:24 +05:30
Ompragash Viswanathan cb9793f014 Updated docker.go 2025-07-09 18:19:53 +05:30
Ompragash Viswanathan f98d4c02f7 Updated docker.go 2025-07-09 17:02:57 +05:30
Ompragash Viswanathan 1b5c809703 Updated docker.go 2025-07-09 16:49:52 +05:30
Ompragash Viswanathan 5e1168c171 Updated docker.go 2025-07-09 13:39:05 +05:30
Ompragash Viswanathan 37d3008a9f Updated docker.go 2025-07-09 12:56:43 +05:30
Ompragash Viswanathan cd8c2ea2a5 Updated docker.go 2025-07-09 12:42:07 +05:30
Ompragash Viswanathan 1367829b3f update buildah save command to use push with oci-archive format 2025-07-07 21:21:38 +05:30
Ompragash Viswanathan c9f5cc5e37 feat: add push-only and tar path options for Docker image handling 2025-07-07 19:13:10 +05:30
OP (oppenheimer) 576fa63696 Merge pull request #11 from drone-plugins/CI-13848
CI-13848 - Fix "`GLIBC_2.34' not found" in buildah-docker
2024-08-22 23:18:02 +05:30
OP (oppenheimer) 0043db940d Update Dockerfile.linux.amd64 2024-08-22 23:09:31 +05:30
OP (oppenheimer) c99dbd8efa Update Dockerfile.linux.amd64 2024-08-22 22:41:06 +05:30
TP Honey 018dd9ef61 Merge pull request #8 from tphoney/harness_move
(maint) move to harness.drone.io
2022-12-07 14:01:27 +00:00
TP Honey a6e0171dd5 (maint) move to harness.drone.io 2022-12-07 13:58:28 +00:00
5 changed files with 196 additions and 53 deletions
+10 -2
View File
@@ -1,6 +1,12 @@
kind: pipeline
type: docker
name: default
type: vm
platform:
os: linux
arch: amd64
pool:
use: ubuntu
steps:
- name: build
@@ -96,12 +102,14 @@ steps:
---
kind: pipeline
type: docker
type: vm
name: notifications-docker
platform:
os: linux
arch: amd64
pool:
use: ubuntu
steps:
- name: manifest-docker
+21 -3
View File
@@ -29,7 +29,7 @@ func main() {
cli.BoolFlag{
Name: "dry-run",
Usage: "dry run disables docker push",
EnvVar: "PLUGIN_DRY_RUN",
EnvVar: "PLUGIN_DRY_RUN,PLUGIN_NO_PUSH",
},
cli.StringFlag{
Name: "remote.url",
@@ -222,6 +222,21 @@ func main() {
Usage: "User Layers",
EnvVar: "PLUGIN_LAYERS",
},
cli.BoolFlag{
Name: "push-only",
Usage: "Push existing Docker images without building",
EnvVar: "PLUGIN_PUSH_ONLY",
},
cli.StringFlag{
Name: "source-tar-path",
Usage: "Path to Docker image tar file to load and push",
EnvVar: "PLUGIN_SOURCE_TAR_PATH",
},
cli.StringFlag{
Name: "tar-path",
Usage: "Path to save Docker image as tar file",
EnvVar: "PLUGIN_TAR_PATH,PLUGIN_DESTINATION_TAR_PATH",
},
}
if err := app.Run(os.Args); err != nil {
@@ -231,8 +246,11 @@ func main() {
func run(c *cli.Context) error {
plugin := docker.Plugin{
Dryrun: c.Bool("dry-run"),
Cleanup: c.BoolT("docker.purge"),
Dryrun: c.Bool("dry-run"),
Cleanup: c.BoolT("docker.purge"),
PushOnly: c.Bool("push-only"),
SourceTarPath: c.String("source-tar-path"),
TarPath: c.String("tar-path"),
Login: docker.Login{
Registry: c.String("docker.registry"),
Username: c.String("docker.username"),
+158 -7
View File
@@ -57,10 +57,13 @@ type (
// Plugin defines the Docker plugin parameters.
Plugin struct {
Login Login // Docker login configuration
Build Build // Docker build configuration
Dryrun bool // Docker push is skipped
Cleanup bool // Docker purge is enabled
Login Login // Docker login configuration
Build Build // Docker build configuration
Dryrun bool // Docker push is skipped
Cleanup bool // Docker purge is enabled
PushOnly bool // Push only mode, skips build process
SourceTarPath string // Path to Docker image tar file to load and push
TarPath string // Path to save Docker image as tar file
}
)
@@ -105,6 +108,11 @@ func (p Plugin) Exec() error {
fmt.Println("Registry credentials or Docker config not provided. Guest mode enabled.")
}
// Check if we're in push-only mode
if p.PushOnly {
return p.pushOnly()
}
// add proxy build args
addProxyBuildArgs(&p.Build)
@@ -122,11 +130,23 @@ func (p Plugin) Exec() error {
for _, tag := range p.Build.Tags {
cmds = append(cmds, commandTag(p.Build, tag)) // docker tag
if p.Dryrun == false {
if !p.Dryrun {
cmds = append(cmds, commandPush(p.Build, tag)) // docker push
}
}
// If TarPath is specified and Dryrun is enabled, save the image to a tar file
if p.TarPath != "" && p.Dryrun && len(p.Build.Tags) > 0 {
// Ensure parent directories exist
if err := os.MkdirAll(filepath.Dir(p.TarPath), 0755); err != nil {
return fmt.Errorf("failed to create parent directories for tar path: %s", err)
}
imageToSave := fmt.Sprintf("%s:%s", p.Build.Repo, p.Build.Tags[0])
fmt.Println("Saving image to tar:", p.TarPath)
cmds = append(cmds, commandSaveTar(imageToSave, p.TarPath))
}
if p.Cleanup {
cmds = append(cmds, commandRmi(p.Build.Name)) // buildah rmi
}
@@ -184,14 +204,14 @@ func commandLoginEmail(login Login) *exec.Cmd {
)
}
// helper function to create the docker info command.
// helper function to create the docker version command.
func commandVersion() *exec.Cmd {
return exec.Command(buildahExe, "version")
}
// helper function to create the docker info command.
func commandInfo() *exec.Cmd {
return exec.Command(buildahExe, "info")
return exec.Command(buildahExe, "--storage-driver", "vfs", "info")
}
// helper function to create the docker build command.
@@ -365,3 +385,134 @@ func commandRmi(tag string) *exec.Cmd {
func trace(cmd *exec.Cmd) {
fmt.Fprintf(os.Stdout, "+ %s\n", strings.Join(cmd.Args, " "))
}
// pushOnly handles pushing images without building them
func (p Plugin) pushOnly() error {
// If source tar path is provided, load the image first
if p.SourceTarPath != "" {
fileInfo, err := os.Stat(p.SourceTarPath)
if err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("source image tar file %s does not exist", p.SourceTarPath)
}
return fmt.Errorf("failed to access source image tar file: %s", err)
}
if !fileInfo.Mode().IsRegular() {
return fmt.Errorf("source image tar %s is not a regular file", p.SourceTarPath)
}
fmt.Println("Loading image from tar:", p.SourceTarPath)
loadCmd := commandLoadTar(p.SourceTarPath)
loadCmd.Stdout = os.Stdout
loadCmd.Stderr = os.Stderr
trace(loadCmd)
if err := loadCmd.Run(); err != nil {
return fmt.Errorf("failed to load image from tar: %s", err)
}
}
// Check for required tags
if len(p.Build.Tags) == 0 {
return fmt.Errorf("no tags specified for push")
}
// Use the repository name as the source image name
sourceImageName := p.Build.Repo
sourceTags := p.Build.Tags
// For each source tag and target tag combination
taggedForPush := make(map[string]bool)
for _, sourceTag := range sourceTags {
sourceFullImageName := fmt.Sprintf("%s:%s", sourceImageName, sourceTag)
// Check if the source image exists in local storage
existsCmd := commandImageExists(sourceFullImageName)
existsCmd.Stdout = nil // suppress output, we only care about the exit code
existsCmd.Stderr = os.Stderr
trace(existsCmd)
if err := existsCmd.Run(); err != nil {
fmt.Printf("Warning: Source image %s not found\n", sourceFullImageName)
// Continue to the next source tag if available, otherwise return error
if len(sourceTags) > 1 {
continue
}
return fmt.Errorf("source image %s not found, cannot push", sourceFullImageName)
}
// For each target tag, tag and push
for _, targetTag := range p.Build.Tags {
targetFullImageName := fmt.Sprintf("%s:%s", p.Build.Repo, targetTag)
// Skip if source and target are identical
if sourceFullImageName == targetFullImageName {
fmt.Printf("Source and target image names are identical: %s\n", sourceFullImageName)
taggedForPush[targetFullImageName] = true
} else {
// Tag the source image with the target name
fmt.Printf("Tagging %s as %s\n", sourceFullImageName, targetFullImageName)
tagCmd := exec.Command(buildahExe, "--storage-driver", "vfs", "tag", sourceFullImageName, targetFullImageName)
tagCmd.Stdout = os.Stdout
tagCmd.Stderr = os.Stderr
trace(tagCmd)
if err := tagCmd.Run(); err == nil {
taggedForPush[targetFullImageName] = true
} else {
fmt.Printf("Warning: Failed to tag %s as %s: %s\n", sourceFullImageName, targetFullImageName, err)
}
}
}
}
// If no images were tagged or found, we can't proceed
if len(taggedForPush) == 0 {
return fmt.Errorf("no images found or tagged for repository %s, cannot push", p.Build.Repo)
}
var cmds []*exec.Cmd
// Push all tagged images
for tag := range taggedForPush {
// Extract tag from the full image name
_, tagOnly, found := strings.Cut(tag, ":")
if !found {
continue
}
// Push the image if not in dry-run mode
if !p.Dryrun {
cmds = append(cmds, commandPush(p.Build, tagOnly))
}
}
// Execute all commands
for _, cmd := range cmds {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
trace(cmd)
if err := cmd.Run(); err != nil {
return fmt.Errorf("command failed: %s", err)
}
}
return nil
}
// commandLoadTar creates a command to load an image from a tar file
func commandLoadTar(tarPath string) *exec.Cmd {
return exec.Command(buildahExe, "--storage-driver", "vfs", "pull", "docker-archive:"+tarPath)
}
// commandImageExists creates a command to check if an image exists
func commandImageExists(image string) *exec.Cmd {
return exec.Command(buildahExe, "inspect", "--storage-driver", "vfs", "--type", "image", image)
}
// commandSaveTar creates a command to save an image to a tar file
func commandSaveTar(image string, tarPath string) *exec.Cmd {
return exec.Command(buildahExe, "push", "--storage-driver", "vfs", image, "docker-archive:"+tarPath)
}
+7 -35
View File
@@ -1,40 +1,12 @@
FROM fedora
RUN dnf -y install \
make \
golang \
bats \
btrfs-progs-devel \
device-mapper-devel \
glib2-devel \
gpgme-devel \
libassuan-devel \
libseccomp-devel \
git \
bzip2 \
go-md2man \
runc \
containers-common \
skopeo-containers
# Workaround - the first install somehow leaves the golang in a bad state
RUN dnf -y install golang
RUN mkdir /root/buildah && \
cd /root/buildah && \
git clone https://github.com/harness/buildah.git ./src/github.com/containers/buildah
RUN cd /root/buildah/src/github.com/containers/buildah && make && sudo make install
FROM quay.io/buildah/stable:v1.23.0
FROM quay.io/buildah/stable:v1.36.0
# Set up the working directory
USER build
WORKDIR /home/build
RUN export STORAGE_DRIVER=vfs
# Add plugin binary
ADD release/linux/amd64/drone-docker /bin/
COPY --from=0 /root/buildah/src/github.com/containers/buildah/bin/. /bin/
ENTRYPOINT ["/bin/drone-docker"]
# Add the plugin binary
ADD release/linux/amd64/drone-docker /bin/
# Set the entrypoint to the plugin binary
ENTRYPOINT ["/bin/drone-docker"]
-6
View File
@@ -1,6 +0,0 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
]
}