Skip to content

Commit

Permalink
chore: buildah test update
Browse files Browse the repository at this point in the history
Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Mar 21, 2022
1 parent aa3aa4e commit 5850f98
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions cmd/buildah-test/main.go
Expand Up @@ -18,8 +18,8 @@ import (
)

var errUsage = errors.New(`
./buildah-test {auto|native|docker-with-fuse} { dockerfile DOCKERFILE_PATH [CONTEXT_PATH] |
stapel }
./buildah-test {auto|native|docker-with-fuse} { dockerfile DOCKERFILE_PATH [CONTEXT_PATH] |
stapel }
`)

func runStapel(ctx context.Context, mode buildah.Mode) error {
Expand All @@ -28,19 +28,26 @@ func runStapel(ctx context.Context, mode buildah.Mode) error {
return fmt.Errorf("unable to create buildah client: %s", err)
}

// TODO: get this working
// if _, err := b.FromCommand(ctx, "mycontainer", "ubuntu:20.04", buildah.FromCommandOpts{}); err != nil {
// return fmt.Errorf("unable to create mycontainer from ubuntu:20.04: %s", err)
// }
// TODO: b.Rm(ctx, "mycontainer", buildah.RmOpts{})

if _, err := b.FromCommand(ctx, "mycontainer", "ubuntu:20.04", buildah.FromCommandOpts{}); err != nil {
return fmt.Errorf("unable to create mycontainer from ubuntu:20.04: %s", err)
}

buildStageSh := `#!/bin/bash
echo HELLO > /FILE
echo START
id
ls -lah /
echo "HELLO FROM BUILD INSTRUCTION" > /root/HELLO
ls -lah /root
echo STOP
`

if err := os.WriteFile("/tmp/build_stage.sh", []byte(buildStageSh), os.ModePerm); err != nil {
return err
}
defer os.RemoveAll("/tmp/build_stage.sh")

if err := b.RunCommand(ctx, "mycontainer", []string{"/.werf/build_stage.sh"}, buildah.RunCommandOpts{
Mounts: []specs.Mount{
Expand All @@ -64,6 +71,8 @@ echo HELLO > /FILE
return fmt.Errorf("unable to write /FILE_FROM_GOLANG into %q: %s", containerRootDir, err)
}

// TODO: b.Commit(ctx, "mycontainer, "docker://ghcr.io/GROUP/NAME:TAG", buildah.CommitOpts{})

return nil
}

Expand Down

0 comments on commit 5850f98

Please sign in to comment.