mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-30 15:33:18 -05:00
727d95b477
- Save logs from control(headscale) on every run to tmp - Upgrade nix-actions - Cancel builds if new commit is pushed - Fix a sorting bug in user command test Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
69 lines
1.1 KiB
Go
69 lines
1.1 KiB
Go
package dockertestutil
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
|
|
"github.com/ory/dockertest/v3"
|
|
"github.com/ory/dockertest/v3/docker"
|
|
)
|
|
|
|
const filePerm = 0o644
|
|
|
|
func SaveLog(
|
|
pool *dockertest.Pool,
|
|
resource *dockertest.Resource,
|
|
basePath string,
|
|
) error {
|
|
err := os.MkdirAll(basePath, os.ModePerm)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var stdout bytes.Buffer
|
|
var stderr bytes.Buffer
|
|
|
|
err = pool.Client.Logs(
|
|
docker.LogsOptions{
|
|
Context: context.TODO(),
|
|
Container: resource.Container.ID,
|
|
OutputStream: &stdout,
|
|
ErrorStream: &stderr,
|
|
Tail: "all",
|
|
RawTerminal: false,
|
|
Stdout: true,
|
|
Stderr: true,
|
|
Follow: false,
|
|
Timestamps: false,
|
|
},
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Printf("Saving logs for %s to %s\n", resource.Container.Name, basePath)
|
|
|
|
err = os.WriteFile(
|
|
path.Join(basePath, resource.Container.Name+".stdout.log"),
|
|
stdout.Bytes(),
|
|
filePerm,
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = os.WriteFile(
|
|
path.Join(basePath, resource.Container.Name+".stderr.log"),
|
|
stderr.Bytes(),
|
|
filePerm,
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|