Compare commits
13 Commits
0.9.0-beta
...
main
Author | SHA1 | Date |
---|---|---|
Moritz | 0590c1824d | |
Moritz | 459abecfa5 | |
Moritz | 183ad8f576 | |
decentral1se | 03f94da2d8 | |
f | 766f69b0fd | |
decentral1se | 004cd70aed | |
decentral1se | a4de446f58 | |
Rich M | d21c35965d | |
Mayel de Borniol | 63ea58ffaa | |
decentral1se | 2ecace3e90 | |
p4u1 | d5ac3958a4 | |
3wc | 72c20e0039 | |
decentral1se | 575f9905f1 |
|
@ -29,6 +29,8 @@ builds:
|
||||||
ldflags:
|
ldflags:
|
||||||
- "-X 'main.Commit={{ .Commit }}'"
|
- "-X 'main.Commit={{ .Commit }}'"
|
||||||
- "-X 'main.Version={{ .Version }}'"
|
- "-X 'main.Version={{ .Version }}'"
|
||||||
|
- "-s"
|
||||||
|
- "-w"
|
||||||
|
|
||||||
- id: kadabra
|
- id: kadabra
|
||||||
binary: kadabra
|
binary: kadabra
|
||||||
|
@ -50,6 +52,8 @@ builds:
|
||||||
ldflags:
|
ldflags:
|
||||||
- "-X 'main.Commit={{ .Commit }}'"
|
- "-X 'main.Commit={{ .Commit }}'"
|
||||||
- "-X 'main.Version={{ .Version }}'"
|
- "-X 'main.Version={{ .Version }}'"
|
||||||
|
- "-s"
|
||||||
|
- "-w"
|
||||||
|
|
||||||
checksum:
|
checksum:
|
||||||
name_template: "checksums.txt"
|
name_template: "checksums.txt"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
- cassowary
|
- cassowary
|
||||||
- codegod100
|
- codegod100
|
||||||
- decentral1se
|
- decentral1se
|
||||||
|
- fauno
|
||||||
- frando
|
- frando
|
||||||
- kawaiipunk
|
- kawaiipunk
|
||||||
- knoflook
|
- knoflook
|
||||||
|
|
14
Dockerfile
14
Dockerfile
|
@ -1,23 +1,29 @@
|
||||||
|
# Build image
|
||||||
FROM golang:1.21-alpine AS build
|
FROM golang:1.21-alpine AS build
|
||||||
|
|
||||||
ENV GOPRIVATE coopcloud.tech
|
ENV GOPRIVATE coopcloud.tech
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
ca-certificates \
|
|
||||||
gcc \
|
gcc \
|
||||||
git \
|
git \
|
||||||
make \
|
make \
|
||||||
musl-dev
|
musl-dev
|
||||||
|
|
||||||
RUN update-ca-certificates
|
|
||||||
|
|
||||||
COPY . /app
|
COPY . /app
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 make build
|
RUN CGO_ENABLED=0 make build
|
||||||
|
|
||||||
FROM scratch
|
# Release image ("slim")
|
||||||
|
FROM alpine:3.19.1
|
||||||
|
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
ca-certificates \
|
||||||
|
git \
|
||||||
|
openssh
|
||||||
|
|
||||||
|
RUN update-ca-certificates
|
||||||
|
|
||||||
COPY --from=build /app/abra /abra
|
COPY --from=build /app/abra /abra
|
||||||
|
|
||||||
|
|
|
@ -1,414 +1,296 @@
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/pkg/autocomplete"
|
"coopcloud.tech/abra/pkg/autocomplete"
|
||||||
"coopcloud.tech/abra/pkg/client"
|
"coopcloud.tech/abra/pkg/client"
|
||||||
"coopcloud.tech/abra/pkg/config"
|
"coopcloud.tech/abra/pkg/recipe"
|
||||||
containerPkg "coopcloud.tech/abra/pkg/container"
|
|
||||||
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
|
||||||
"coopcloud.tech/abra/pkg/upstream/container"
|
|
||||||
"github.com/docker/cli/cli/command"
|
|
||||||
"github.com/docker/docker/api/types"
|
|
||||||
"github.com/docker/docker/api/types/filters"
|
|
||||||
dockerClient "github.com/docker/docker/client"
|
|
||||||
"github.com/docker/docker/pkg/archive"
|
|
||||||
"github.com/klauspost/pgzip"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
type backupConfig struct {
|
var snapshot string
|
||||||
preHookCmd string
|
var snapshotFlag = &cli.StringFlag{
|
||||||
postHookCmd string
|
Name: "snapshot, s",
|
||||||
backupPaths []string
|
Usage: "Lists specific snapshot",
|
||||||
|
Destination: &snapshot,
|
||||||
}
|
}
|
||||||
|
|
||||||
var appBackupCommand = cli.Command{
|
var includePath string
|
||||||
Name: "backup",
|
var includePathFlag = &cli.StringFlag{
|
||||||
Aliases: []string{"bk"},
|
Name: "path, p",
|
||||||
Usage: "Run app backup",
|
Usage: "Include path",
|
||||||
ArgsUsage: "<domain> [<service>]",
|
Destination: &includePath,
|
||||||
|
}
|
||||||
|
|
||||||
|
var resticRepo string
|
||||||
|
var resticRepoFlag = &cli.StringFlag{
|
||||||
|
Name: "repo, r",
|
||||||
|
Usage: "Restic repository",
|
||||||
|
Destination: &resticRepo,
|
||||||
|
}
|
||||||
|
|
||||||
|
var appBackupListCommand = cli.Command{
|
||||||
|
Name: "list",
|
||||||
|
Aliases: []string{"ls"},
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
internal.DebugFlag,
|
internal.DebugFlag,
|
||||||
internal.OfflineFlag,
|
internal.OfflineFlag,
|
||||||
internal.ChaosFlag,
|
snapshotFlag,
|
||||||
|
includePathFlag,
|
||||||
},
|
},
|
||||||
Before: internal.SubCommandBefore,
|
Before: internal.SubCommandBefore,
|
||||||
|
Usage: "List all backups",
|
||||||
BashComplete: autocomplete.AppNameComplete,
|
BashComplete: autocomplete.AppNameComplete,
|
||||||
Description: `
|
|
||||||
Run an app backup.
|
|
||||||
|
|
||||||
A backup command and pre/post hook commands are defined in the recipe
|
|
||||||
configuration. Abra reads this configuration and run the comands in the context
|
|
||||||
of the deployed services. Pass <service> if you only want to back up a single
|
|
||||||
service. All backups are placed in the ~/.abra/backups directory.
|
|
||||||
|
|
||||||
A single backup file is produced for all backup paths specified for a service.
|
|
||||||
If we have the following backup configuration:
|
|
||||||
|
|
||||||
- "backupbot.backup.path=/var/lib/foo,/var/lib/bar"
|
|
||||||
|
|
||||||
And we run "abra app backup example.com app", Abra will produce a file that
|
|
||||||
looks like:
|
|
||||||
|
|
||||||
~/.abra/backups/example_com_app_609341138.tar.gz
|
|
||||||
|
|
||||||
This file is a compressed archive which contains all backup paths. To see paths, run:
|
|
||||||
|
|
||||||
tar -tf ~/.abra/backups/example_com_app_609341138.tar.gz
|
|
||||||
|
|
||||||
(Make sure to change the name of the backup file)
|
|
||||||
|
|
||||||
This single file can be used to restore your app. See "abra app restore" for more.
|
|
||||||
`,
|
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
|
|
||||||
recipe, err := recipePkg.Get(app.Recipe, internal.Offline)
|
if err := recipe.EnsureExists(app.Recipe); err != nil {
|
||||||
if err != nil {
|
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !internal.Chaos {
|
if !internal.Chaos {
|
||||||
if err := recipePkg.EnsureIsClean(app.Recipe); err != nil {
|
if err := recipe.EnsureIsClean(app.Recipe); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !internal.Offline {
|
if !internal.Offline {
|
||||||
if err := recipePkg.EnsureUpToDate(app.Recipe); err != nil {
|
if err := recipe.EnsureUpToDate(app.Recipe); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := recipePkg.EnsureLatest(app.Recipe); err != nil {
|
if err := recipe.EnsureLatest(app.Recipe); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
backupConfigs := make(map[string]backupConfig)
|
|
||||||
for _, service := range recipe.Config.Services {
|
|
||||||
if backupsEnabled, ok := service.Deploy.Labels["backupbot.backup"]; ok {
|
|
||||||
if backupsEnabled == "true" {
|
|
||||||
fullServiceName := fmt.Sprintf("%s_%s", app.StackName(), service.Name)
|
|
||||||
bkConfig := backupConfig{}
|
|
||||||
|
|
||||||
logrus.Debugf("backup config detected for %s", fullServiceName)
|
|
||||||
|
|
||||||
if paths, ok := service.Deploy.Labels["backupbot.backup.path"]; ok {
|
|
||||||
logrus.Debugf("detected backup paths for %s: %s", fullServiceName, paths)
|
|
||||||
bkConfig.backupPaths = strings.Split(paths, ",")
|
|
||||||
}
|
|
||||||
|
|
||||||
if preHookCmd, ok := service.Deploy.Labels["backupbot.backup.pre-hook"]; ok {
|
|
||||||
logrus.Debugf("detected pre-hook command for %s: %s", fullServiceName, preHookCmd)
|
|
||||||
bkConfig.preHookCmd = preHookCmd
|
|
||||||
}
|
|
||||||
|
|
||||||
if postHookCmd, ok := service.Deploy.Labels["backupbot.backup.post-hook"]; ok {
|
|
||||||
logrus.Debugf("detected post-hook command for %s: %s", fullServiceName, postHookCmd)
|
|
||||||
bkConfig.postHookCmd = postHookCmd
|
|
||||||
}
|
|
||||||
|
|
||||||
backupConfigs[service.Name] = bkConfig
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cl, err := client.New(app.Server)
|
cl, err := client.New(app.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceName := c.Args().Get(1)
|
targetContainer, err := internal.RetrieveBackupBotContainer(cl)
|
||||||
if serviceName != "" {
|
if err != nil {
|
||||||
backupConfig, ok := backupConfigs[serviceName]
|
logrus.Fatal(err)
|
||||||
if !ok {
|
}
|
||||||
logrus.Fatalf("no backup config for %s? does %s exist?", serviceName, serviceName)
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Infof("running backup for the %s service", serviceName)
|
execEnv := []string{fmt.Sprintf("SERVICE=%s", app.Domain)}
|
||||||
|
if snapshot != "" {
|
||||||
|
logrus.Debugf("including SNAPSHOT=%s in backupbot exec invocation", snapshot)
|
||||||
|
execEnv = append(execEnv, fmt.Sprintf("SNAPSHOT=%s", snapshot))
|
||||||
|
}
|
||||||
|
if includePath != "" {
|
||||||
|
logrus.Debugf("including INCLUDE_PATH=%s in backupbot exec invocation", includePath)
|
||||||
|
execEnv = append(execEnv, fmt.Sprintf("INCLUDE_PATH=%s", includePath))
|
||||||
|
}
|
||||||
|
|
||||||
if err := runBackup(cl, app, serviceName, backupConfig); err != nil {
|
if err := internal.RunBackupCmdRemote(cl, "ls", targetContainer.ID, execEnv); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if len(backupConfigs) == 0 {
|
|
||||||
logrus.Fatalf("no backup configs discovered for %s?", app.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
for serviceName, backupConfig := range backupConfigs {
|
|
||||||
logrus.Infof("running backup for the %s service", serviceName)
|
|
||||||
|
|
||||||
if err := runBackup(cl, app, serviceName, backupConfig); err != nil {
|
|
||||||
logrus.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimeStamp generates a file name friendly timestamp.
|
var appBackupDownloadCommand = cli.Command{
|
||||||
func TimeStamp() string {
|
Name: "download",
|
||||||
ts := time.Now().UTC().Format(time.RFC3339)
|
Aliases: []string{"d"},
|
||||||
return strings.Replace(ts, ":", "-", -1)
|
Flags: []cli.Flag{
|
||||||
}
|
internal.DebugFlag,
|
||||||
|
internal.OfflineFlag,
|
||||||
|
snapshotFlag,
|
||||||
|
includePathFlag,
|
||||||
|
},
|
||||||
|
Before: internal.SubCommandBefore,
|
||||||
|
Usage: "Download a backup",
|
||||||
|
BashComplete: autocomplete.AppNameComplete,
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
app := internal.ValidateApp(c)
|
||||||
|
|
||||||
// runBackup does the actual backup logic.
|
if err := recipe.EnsureExists(app.Recipe); err != nil {
|
||||||
func runBackup(cl *dockerClient.Client, app config.App, serviceName string, bkConfig backupConfig) error {
|
logrus.Fatal(err)
|
||||||
if len(bkConfig.backupPaths) == 0 {
|
|
||||||
return fmt.Errorf("backup paths are empty for %s?", serviceName)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: avoid instantiating a new CLI
|
|
||||||
dcli, err := command.NewDockerCli()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
filters := filters.NewArgs()
|
|
||||||
filters.Add("name", fmt.Sprintf("^%s_%s", app.StackName(), serviceName))
|
|
||||||
|
|
||||||
targetContainer, err := containerPkg.GetContainer(context.Background(), cl, filters, true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fullServiceName := fmt.Sprintf("%s_%s", app.StackName(), serviceName)
|
|
||||||
if bkConfig.preHookCmd != "" {
|
|
||||||
splitCmd := internal.SafeSplit(bkConfig.preHookCmd)
|
|
||||||
|
|
||||||
logrus.Debugf("split pre-hook command for %s into %s", fullServiceName, splitCmd)
|
|
||||||
|
|
||||||
preHookExecOpts := types.ExecConfig{
|
|
||||||
AttachStderr: true,
|
|
||||||
AttachStdin: true,
|
|
||||||
AttachStdout: true,
|
|
||||||
Cmd: splitCmd,
|
|
||||||
Detach: false,
|
|
||||||
Tty: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := container.RunExec(dcli, cl, targetContainer.ID, &preHookExecOpts); err != nil {
|
if !internal.Chaos {
|
||||||
return fmt.Errorf("failed to run %s on %s: %s", bkConfig.preHookCmd, targetContainer.ID, err.Error())
|
if err := recipe.EnsureIsClean(app.Recipe); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !internal.Offline {
|
||||||
|
if err := recipe.EnsureUpToDate(app.Recipe); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := recipe.EnsureLatest(app.Recipe); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("succesfully ran %s pre-hook command: %s", fullServiceName, bkConfig.preHookCmd)
|
cl, err := client.New(app.Server)
|
||||||
}
|
|
||||||
|
|
||||||
var tempBackupPaths []string
|
|
||||||
for _, remoteBackupPath := range bkConfig.backupPaths {
|
|
||||||
sanitisedPath := strings.ReplaceAll(remoteBackupPath, "/", "_")
|
|
||||||
localBackupPath := filepath.Join(config.BACKUP_DIR, fmt.Sprintf("%s%s_%s.tar.gz", fullServiceName, sanitisedPath, TimeStamp()))
|
|
||||||
logrus.Debugf("temporarily backing up %s:%s to %s", fullServiceName, remoteBackupPath, localBackupPath)
|
|
||||||
|
|
||||||
logrus.Infof("backing up %s:%s", fullServiceName, remoteBackupPath)
|
|
||||||
|
|
||||||
content, _, err := cl.CopyFromContainer(context.Background(), targetContainer.ID, remoteBackupPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("failed to copy %s from container: %s", remoteBackupPath, err.Error())
|
logrus.Fatal(err)
|
||||||
if err := cleanupTempArchives(tempBackupPaths); err != nil {
|
}
|
||||||
return fmt.Errorf("failed to clean up temporary archives: %s", err.Error())
|
|
||||||
|
targetContainer, err := internal.RetrieveBackupBotContainer(cl)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
execEnv := []string{fmt.Sprintf("SERVICE=%s", app.Domain)}
|
||||||
|
if snapshot != "" {
|
||||||
|
logrus.Debugf("including SNAPSHOT=%s in backupbot exec invocation", snapshot)
|
||||||
|
execEnv = append(execEnv, fmt.Sprintf("SNAPSHOT=%s", snapshot))
|
||||||
|
}
|
||||||
|
if includePath != "" {
|
||||||
|
logrus.Debugf("including INCLUDE_PATH=%s in backupbot exec invocation", includePath)
|
||||||
|
execEnv = append(execEnv, fmt.Sprintf("INCLUDE_PATH=%s", includePath))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := internal.RunBackupCmdRemote(cl, "download", targetContainer.ID, execEnv); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteBackupDir := "/tmp/backup.tar.gz"
|
||||||
|
currentWorkingDir := "."
|
||||||
|
if err = CopyFromContainer(cl, targetContainer.ID, remoteBackupDir, currentWorkingDir); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("backup successfully downloaded to current working directory")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var appBackupCreateCommand = cli.Command{
|
||||||
|
Name: "create",
|
||||||
|
Aliases: []string{"c"},
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
internal.DebugFlag,
|
||||||
|
internal.OfflineFlag,
|
||||||
|
resticRepoFlag,
|
||||||
|
},
|
||||||
|
Before: internal.SubCommandBefore,
|
||||||
|
Usage: "Create a new backup",
|
||||||
|
BashComplete: autocomplete.AppNameComplete,
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
app := internal.ValidateApp(c)
|
||||||
|
|
||||||
|
if err := recipe.EnsureExists(app.Recipe); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !internal.Chaos {
|
||||||
|
if err := recipe.EnsureIsClean(app.Recipe); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to copy %s from container: %s", remoteBackupPath, err.Error())
|
|
||||||
}
|
|
||||||
defer content.Close()
|
|
||||||
|
|
||||||
_, srcBase := archive.SplitPathDirEntry(remoteBackupPath)
|
if !internal.Offline {
|
||||||
preArchive := archive.RebaseArchiveEntries(content, srcBase, remoteBackupPath)
|
if err := recipe.EnsureUpToDate(app.Recipe); err != nil {
|
||||||
if err := copyToFile(localBackupPath, preArchive); err != nil {
|
logrus.Fatal(err)
|
||||||
logrus.Debugf("failed to create tar archive (%s): %s", localBackupPath, err.Error())
|
}
|
||||||
if err := cleanupTempArchives(tempBackupPaths); err != nil {
|
|
||||||
return fmt.Errorf("failed to clean up temporary archives: %s", err.Error())
|
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to create tar archive (%s): %s", localBackupPath, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
tempBackupPaths = append(tempBackupPaths, localBackupPath)
|
if err := recipe.EnsureLatest(app.Recipe); err != nil {
|
||||||
}
|
logrus.Fatal(err)
|
||||||
|
|
||||||
logrus.Infof("compressing and merging archives...")
|
|
||||||
|
|
||||||
if err := mergeArchives(tempBackupPaths, fullServiceName); err != nil {
|
|
||||||
logrus.Debugf("failed to merge archive files: %s", err.Error())
|
|
||||||
if err := cleanupTempArchives(tempBackupPaths); err != nil {
|
|
||||||
return fmt.Errorf("failed to clean up temporary archives: %s", err.Error())
|
|
||||||
}
|
|
||||||
return fmt.Errorf("failed to merge archive files: %s", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cleanupTempArchives(tempBackupPaths); err != nil {
|
|
||||||
return fmt.Errorf("failed to clean up temporary archives: %s", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if bkConfig.postHookCmd != "" {
|
|
||||||
splitCmd := internal.SafeSplit(bkConfig.postHookCmd)
|
|
||||||
|
|
||||||
logrus.Debugf("split post-hook command for %s into %s", fullServiceName, splitCmd)
|
|
||||||
|
|
||||||
postHookExecOpts := types.ExecConfig{
|
|
||||||
AttachStderr: true,
|
|
||||||
AttachStdin: true,
|
|
||||||
AttachStdout: true,
|
|
||||||
Cmd: splitCmd,
|
|
||||||
Detach: false,
|
|
||||||
Tty: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := container.RunExec(dcli, cl, targetContainer.ID, &postHookExecOpts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Infof("succesfully ran %s post-hook command: %s", fullServiceName, bkConfig.postHookCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func copyToFile(outfile string, r io.Reader) error {
|
|
||||||
tmpFile, err := os.CreateTemp(filepath.Dir(outfile), ".tar_temp")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpPath := tmpFile.Name()
|
|
||||||
|
|
||||||
_, err = io.Copy(tmpFile, r)
|
|
||||||
tmpFile.Close()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
os.Remove(tmpPath)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = os.Rename(tmpPath, outfile); err != nil {
|
|
||||||
os.Remove(tmpPath)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func cleanupTempArchives(tarPaths []string) error {
|
|
||||||
for _, tarPath := range tarPaths {
|
|
||||||
if err := os.RemoveAll(tarPath); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Debugf("remove temporary archive file %s", tarPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func mergeArchives(tarPaths []string, serviceName string) error {
|
|
||||||
var out io.Writer
|
|
||||||
var cout *pgzip.Writer
|
|
||||||
|
|
||||||
localBackupPath := filepath.Join(config.BACKUP_DIR, fmt.Sprintf("%s_%s.tar.gz", serviceName, TimeStamp()))
|
|
||||||
|
|
||||||
fout, err := os.Create(localBackupPath)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Failed to open %s: %s", localBackupPath, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer fout.Close()
|
|
||||||
out = fout
|
|
||||||
|
|
||||||
cout = pgzip.NewWriter(out)
|
|
||||||
out = cout
|
|
||||||
|
|
||||||
tw := tar.NewWriter(out)
|
|
||||||
|
|
||||||
for _, tarPath := range tarPaths {
|
|
||||||
if err := addTar(tw, tarPath); err != nil {
|
|
||||||
return fmt.Errorf("failed to merge %s: %v", tarPath, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := tw.Close(); err != nil {
|
|
||||||
return fmt.Errorf("failed to close tar writer %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if cout != nil {
|
|
||||||
if err := cout.Flush(); err != nil {
|
|
||||||
return fmt.Errorf("failed to flush: %s", err)
|
|
||||||
} else if err = cout.Close(); err != nil {
|
|
||||||
return fmt.Errorf("failed to close compressed writer: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Infof("backed up %s to %s", serviceName, localBackupPath)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func addTar(tw *tar.Writer, pth string) (err error) {
|
|
||||||
var tr *tar.Reader
|
|
||||||
var rc io.ReadCloser
|
|
||||||
var hdr *tar.Header
|
|
||||||
|
|
||||||
if tr, rc, err = openTarFile(pth); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
if hdr, err = tr.Next(); err != nil {
|
|
||||||
if err == io.EOF {
|
|
||||||
err = nil
|
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
if err = tw.WriteHeader(hdr); err != nil {
|
|
||||||
break
|
cl, err := client.New(app.Server)
|
||||||
} else if _, err = io.Copy(tw, tr); err != nil {
|
if err != nil {
|
||||||
break
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if err == nil {
|
targetContainer, err := internal.RetrieveBackupBotContainer(cl)
|
||||||
err = rc.Close()
|
if err != nil {
|
||||||
} else {
|
logrus.Fatal(err)
|
||||||
rc.Close()
|
}
|
||||||
}
|
|
||||||
return
|
execEnv := []string{fmt.Sprintf("SERVICE=%s", app.Domain)}
|
||||||
|
if resticRepo != "" {
|
||||||
|
logrus.Debugf("including RESTIC_REPO=%s in backupbot exec invocation", resticRepo)
|
||||||
|
execEnv = append(execEnv, fmt.Sprintf("RESTIC_REPO=%s", resticRepo))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := internal.RunBackupCmdRemote(cl, "create", targetContainer.ID, execEnv); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func openTarFile(pth string) (tr *tar.Reader, rc io.ReadCloser, err error) {
|
var appBackupSnapshotsCommand = cli.Command{
|
||||||
var fin *os.File
|
Name: "snapshots",
|
||||||
var n int
|
Aliases: []string{"s"},
|
||||||
buff := make([]byte, 1024)
|
Flags: []cli.Flag{
|
||||||
|
internal.DebugFlag,
|
||||||
|
internal.OfflineFlag,
|
||||||
|
snapshotFlag,
|
||||||
|
},
|
||||||
|
Before: internal.SubCommandBefore,
|
||||||
|
Usage: "List backup snapshots",
|
||||||
|
BashComplete: autocomplete.AppNameComplete,
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
app := internal.ValidateApp(c)
|
||||||
|
|
||||||
if fin, err = os.Open(pth); err != nil {
|
if err := recipe.EnsureExists(app.Recipe); err != nil {
|
||||||
return
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if n, err = fin.Read(buff); err != nil {
|
if !internal.Chaos {
|
||||||
fin.Close()
|
if err := recipe.EnsureIsClean(app.Recipe); err != nil {
|
||||||
return
|
logrus.Fatal(err)
|
||||||
} else if n == 0 {
|
}
|
||||||
fin.Close()
|
|
||||||
err = fmt.Errorf("%s is empty", pth)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err = fin.Seek(0, 0); err != nil {
|
if !internal.Offline {
|
||||||
fin.Close()
|
if err := recipe.EnsureUpToDate(app.Recipe); err != nil {
|
||||||
return
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rc = fin
|
if err := recipe.EnsureLatest(app.Recipe); err != nil {
|
||||||
tr = tar.NewReader(rc)
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return tr, rc, nil
|
cl, err := client.New(app.Server)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
targetContainer, err := internal.RetrieveBackupBotContainer(cl)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
execEnv := []string{fmt.Sprintf("SERVICE=%s", app.Domain)}
|
||||||
|
if snapshot != "" {
|
||||||
|
logrus.Debugf("including SNAPSHOT=%s in backupbot exec invocation", snapshot)
|
||||||
|
execEnv = append(execEnv, fmt.Sprintf("SNAPSHOT=%s", snapshot))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := internal.RunBackupCmdRemote(cl, "snapshots", targetContainer.ID, execEnv); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var appBackupCommand = cli.Command{
|
||||||
|
Name: "backup",
|
||||||
|
Aliases: []string{"b"},
|
||||||
|
Usage: "Manage app backups",
|
||||||
|
ArgsUsage: "<domain>",
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
appBackupListCommand,
|
||||||
|
appBackupSnapshotsCommand,
|
||||||
|
appBackupDownloadCommand,
|
||||||
|
appBackupCreateCommand,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,9 +76,9 @@ And if you want to copy that file back to your current working directory locally
|
||||||
logrus.Debugf("retrieved %s as target container on %s", formatter.ShortenID(container.ID), app.Server)
|
logrus.Debugf("retrieved %s as target container on %s", formatter.ShortenID(container.ID), app.Server)
|
||||||
|
|
||||||
if toContainer {
|
if toContainer {
|
||||||
err = copyToContainer(cl, container.ID, srcPath, dstPath)
|
err = CopyToContainer(cl, container.ID, srcPath, dstPath)
|
||||||
} else {
|
} else {
|
||||||
err = copyFromContainer(cl, container.ID, srcPath, dstPath)
|
err = CopyFromContainer(cl, container.ID, srcPath, dstPath)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
@ -106,9 +106,9 @@ func parseSrcAndDst(src, dst string) (srcPath string, dstPath string, service st
|
||||||
return "", "", "", false, errServiceMissing
|
return "", "", "", false, errServiceMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
// copyToContainer copies a file or directory from the local file system to the container.
|
// CopyToContainer copies a file or directory from the local file system to the container.
|
||||||
// See the possible copy modes and their documentation.
|
// See the possible copy modes and their documentation.
|
||||||
func copyToContainer(cl *dockerClient.Client, containerID, srcPath, dstPath string) error {
|
func CopyToContainer(cl *dockerClient.Client, containerID, srcPath, dstPath string) error {
|
||||||
srcStat, err := os.Stat(srcPath)
|
srcStat, err := os.Stat(srcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("local %s ", err)
|
return fmt.Errorf("local %s ", err)
|
||||||
|
@ -140,7 +140,7 @@ func copyToContainer(cl *dockerClient.Client, containerID, srcPath, dstPath stri
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := container.RunExec(dcli, cl, containerID, &types.ExecConfig{
|
if _, err := container.RunExec(dcli, cl, containerID, &types.ExecConfig{
|
||||||
AttachStderr: true,
|
AttachStderr: true,
|
||||||
AttachStdin: true,
|
AttachStdin: true,
|
||||||
AttachStdout: true,
|
AttachStdout: true,
|
||||||
|
@ -179,7 +179,7 @@ func copyToContainer(cl *dockerClient.Client, containerID, srcPath, dstPath stri
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := container.RunExec(dcli, cl, containerID, &types.ExecConfig{
|
if _, err := container.RunExec(dcli, cl, containerID, &types.ExecConfig{
|
||||||
AttachStderr: true,
|
AttachStderr: true,
|
||||||
AttachStdin: true,
|
AttachStdin: true,
|
||||||
AttachStdout: true,
|
AttachStdout: true,
|
||||||
|
@ -194,9 +194,9 @@ func copyToContainer(cl *dockerClient.Client, containerID, srcPath, dstPath stri
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// copyFromContainer copies a file or directory from the given container to the local file system.
|
// CopyFromContainer copies a file or directory from the given container to the local file system.
|
||||||
// See the possible copy modes and their documentation.
|
// See the possible copy modes and their documentation.
|
||||||
func copyFromContainer(cl *dockerClient.Client, containerID, srcPath, dstPath string) error {
|
func CopyFromContainer(cl *dockerClient.Client, containerID, srcPath, dstPath string) error {
|
||||||
srcStat, err := cl.ContainerStatPath(context.Background(), containerID, srcPath)
|
srcStat, err := cl.ContainerStatPath(context.Background(), containerID, srcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errdefs.IsNotFound(err) {
|
if errdefs.IsNotFound(err) {
|
||||||
|
|
|
@ -183,6 +183,12 @@ type AppSecrets map[string]string
|
||||||
|
|
||||||
// createSecrets creates all secrets for a new app.
|
// createSecrets creates all secrets for a new app.
|
||||||
func createSecrets(cl *dockerClient.Client, secretsConfig map[string]secret.Secret, sanitisedAppName string) (AppSecrets, error) {
|
func createSecrets(cl *dockerClient.Client, secretsConfig map[string]secret.Secret, sanitisedAppName string) (AppSecrets, error) {
|
||||||
|
// NOTE(d1): trim to match app.StackName() implementation
|
||||||
|
if len(sanitisedAppName) > config.MAX_SANITISED_APP_NAME_LENGTH {
|
||||||
|
logrus.Debugf("trimming %s to %s to avoid runtime limits", sanitisedAppName, sanitisedAppName[:config.MAX_SANITISED_APP_NAME_LENGTH])
|
||||||
|
sanitisedAppName = sanitisedAppName[:config.MAX_SANITISED_APP_NAME_LENGTH]
|
||||||
|
}
|
||||||
|
|
||||||
secrets, err := secret.GenerateSecrets(cl, secretsConfig, internal.NewAppServer)
|
secrets, err := secret.GenerateSecrets(cl, secretsConfig, internal.NewAppServer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -2,7 +2,8 @@ package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
|
@ -10,11 +11,13 @@ import (
|
||||||
"coopcloud.tech/abra/pkg/client"
|
"coopcloud.tech/abra/pkg/client"
|
||||||
"coopcloud.tech/abra/pkg/config"
|
"coopcloud.tech/abra/pkg/config"
|
||||||
"coopcloud.tech/abra/pkg/formatter"
|
"coopcloud.tech/abra/pkg/formatter"
|
||||||
"coopcloud.tech/abra/pkg/service"
|
"coopcloud.tech/abra/pkg/recipe"
|
||||||
|
abraService "coopcloud.tech/abra/pkg/service"
|
||||||
stack "coopcloud.tech/abra/pkg/upstream/stack"
|
stack "coopcloud.tech/abra/pkg/upstream/stack"
|
||||||
"github.com/buger/goterm"
|
"github.com/buger/goterm"
|
||||||
dockerFormatter "github.com/docker/cli/cli/command/formatter"
|
dockerFormatter "github.com/docker/cli/cli/command/formatter"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/filters"
|
||||||
dockerClient "github.com/docker/docker/client"
|
dockerClient "github.com/docker/docker/client"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
@ -27,6 +30,7 @@ var appPsCommand = cli.Command{
|
||||||
ArgsUsage: "<domain>",
|
ArgsUsage: "<domain>",
|
||||||
Description: "Show a more detailed status output of a specific deployed app",
|
Description: "Show a more detailed status output of a specific deployed app",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
|
internal.MachineReadableFlag,
|
||||||
internal.WatchFlag,
|
internal.WatchFlag,
|
||||||
internal.DebugFlag,
|
internal.DebugFlag,
|
||||||
},
|
},
|
||||||
|
@ -40,7 +44,7 @@ var appPsCommand = cli.Command{
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
isDeployed, _, err := stack.IsDeployed(context.Background(), cl, app.StackName())
|
isDeployed, deployedVersion, err := stack.IsDeployed(context.Background(), cl, app.StackName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -49,6 +53,15 @@ var appPsCommand = cli.Command{
|
||||||
logrus.Fatalf("%s is not deployed?", app.Name)
|
logrus.Fatalf("%s is not deployed?", app.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
statuses, err := config.GetAppStatuses([]config.App{app}, true)
|
||||||
|
if statusMeta, ok := statuses[app.StackName()]; ok {
|
||||||
|
if _, exists := statusMeta["chaos"]; !exists {
|
||||||
|
if err := recipe.EnsureVersion(app.Recipe, deployedVersion); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !internal.Watch {
|
if !internal.Watch {
|
||||||
showPSOutput(c, app, cl)
|
showPSOutput(c, app, cl)
|
||||||
return nil
|
return nil
|
||||||
|
@ -66,36 +79,77 @@ var appPsCommand = cli.Command{
|
||||||
|
|
||||||
// showPSOutput renders ps output.
|
// showPSOutput renders ps output.
|
||||||
func showPSOutput(c *cli.Context, app config.App, cl *dockerClient.Client) {
|
func showPSOutput(c *cli.Context, app config.App, cl *dockerClient.Client) {
|
||||||
filters, err := app.Filters(true, true)
|
composeFiles, err := config.GetComposeFiles(app.Recipe, app.Env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
containers, err := cl.ContainerList(context.Background(), types.ContainerListOptions{Filters: filters})
|
deployOpts := stack.Deploy{
|
||||||
|
Composefiles: composeFiles,
|
||||||
|
Namespace: app.StackName(),
|
||||||
|
Prune: false,
|
||||||
|
ResolveImage: stack.ResolveImageAlways,
|
||||||
|
}
|
||||||
|
compose, err := config.GetAppComposeConfig(app.Name, deployOpts, app.Env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tableCol := []string{"service name", "image", "created", "status", "state", "ports"}
|
var tablerows [][]string
|
||||||
table := formatter.CreateTable(tableCol)
|
allContainerStats := make(map[string]map[string]string)
|
||||||
|
for _, service := range compose.Services {
|
||||||
|
filters := filters.NewArgs()
|
||||||
|
filters.Add("name", fmt.Sprintf("^%s_%s", app.StackName(), service.Name))
|
||||||
|
|
||||||
for _, container := range containers {
|
containers, err := cl.ContainerList(context.Background(), types.ContainerListOptions{Filters: filters})
|
||||||
var containerNames []string
|
if err != nil {
|
||||||
for _, containerName := range container.Names {
|
logrus.Fatal(err)
|
||||||
trimmed := strings.TrimPrefix(containerName, "/")
|
return
|
||||||
containerNames = append(containerNames, trimmed)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tableRow := []string{
|
var containerStats map[string]string
|
||||||
service.ContainerToServiceName(container.Names, app.StackName()),
|
|
||||||
formatter.RemoveSha(container.Image),
|
if len(containers) == 0 {
|
||||||
formatter.HumanDuration(container.Created),
|
containerStats = map[string]string{
|
||||||
container.Status,
|
"service name": service.Name,
|
||||||
container.State,
|
"image": "unknown",
|
||||||
dockerFormatter.DisplayablePorts(container.Ports),
|
"created": "unknown",
|
||||||
|
"status": "unknown",
|
||||||
|
"state": "unknown",
|
||||||
|
"ports": "unknown",
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
container := containers[0]
|
||||||
|
containerStats = map[string]string{
|
||||||
|
"service name": abraService.ContainerToServiceName(container.Names, app.StackName()),
|
||||||
|
"image": formatter.RemoveSha(container.Image),
|
||||||
|
"created": formatter.HumanDuration(container.Created),
|
||||||
|
"status": container.Status,
|
||||||
|
"state": container.State,
|
||||||
|
"ports": dockerFormatter.DisplayablePorts(container.Ports),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
table.Append(tableRow)
|
allContainerStats[containerStats["service name"]] = containerStats
|
||||||
|
|
||||||
|
var tablerow []string = []string{containerStats["service name"], containerStats["image"], containerStats["created"], containerStats["status"], containerStats["state"], containerStats["ports"]}
|
||||||
|
tablerows = append(tablerows, tablerow)
|
||||||
|
}
|
||||||
|
if internal.MachineReadable {
|
||||||
|
jsonstring, err := json.Marshal(allContainerStats)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
} else {
|
||||||
|
fmt.Println(string(jsonstring))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
tableCol := []string{"service name", "image", "created", "status", "state", "ports"}
|
||||||
|
table := formatter.CreateTable(tableCol)
|
||||||
|
for _, row := range tablerows {
|
||||||
|
table.Append(row)
|
||||||
|
}
|
||||||
|
table.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
table.Render()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/pkg/autocomplete"
|
"coopcloud.tech/abra/pkg/autocomplete"
|
||||||
|
@ -13,7 +12,6 @@ import (
|
||||||
stack "coopcloud.tech/abra/pkg/upstream/stack"
|
stack "coopcloud.tech/abra/pkg/upstream/stack"
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/volume"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
@ -112,28 +110,19 @@ flag.
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeListOptions := volume.ListOptions{fs}
|
volumeList, err := client.GetVolumes(cl, context.Background(), app.Server, fs)
|
||||||
volumeListOKBody, err := cl.VolumeList(context.Background(), volumeListOptions)
|
|
||||||
volumeList := volumeListOKBody.Volumes
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
volumeNames := client.GetVolumeNames(volumeList)
|
||||||
|
|
||||||
var vols []string
|
if len(volumeNames) > 0 {
|
||||||
for _, vol := range volumeList {
|
err := client.RemoveVolumes(cl, context.Background(), volumeNames, internal.Force, 5)
|
||||||
vols = append(vols, vol.Name)
|
if err != nil {
|
||||||
}
|
log.Fatalf("removing volumes failed: %s", err)
|
||||||
|
|
||||||
if len(vols) > 0 {
|
|
||||||
for _, vol := range vols {
|
|
||||||
err = retryFunc(5, func() error {
|
|
||||||
return cl.VolumeRemove(context.Background(), vol, internal.Force) // last argument is for force removing
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("removing volumes failed: %s", err)
|
|
||||||
}
|
|
||||||
logrus.Info(fmt.Sprintf("volume %s removed", vol))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logrus.Infof("%d volumes removed successfully", len(volumeNames))
|
||||||
} else {
|
} else {
|
||||||
logrus.Info("no volumes to remove")
|
logrus.Info("no volumes to remove")
|
||||||
}
|
}
|
||||||
|
@ -147,21 +136,3 @@ flag.
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// retryFunc retries the given function for the given retries. After the nth
|
|
||||||
// retry it waits (n + 1)^2 seconds before the next retry (starting with n=0).
|
|
||||||
// It returns an error if the function still failed after the last retry.
|
|
||||||
func retryFunc(retries int, fn func() error) error {
|
|
||||||
for i := 0; i < retries; i++ {
|
|
||||||
err := fn()
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if i+1 < retries {
|
|
||||||
sleep := time.Duration(i+1) * time.Duration(i+1)
|
|
||||||
logrus.Infof("%s: waiting %d seconds before next retry", err, sleep)
|
|
||||||
time.Sleep(sleep * time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fmt.Errorf("%d retries failed", retries)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,223 +1,82 @@
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/pkg/autocomplete"
|
"coopcloud.tech/abra/pkg/autocomplete"
|
||||||
"coopcloud.tech/abra/pkg/client"
|
"coopcloud.tech/abra/pkg/client"
|
||||||
"coopcloud.tech/abra/pkg/config"
|
|
||||||
containerPkg "coopcloud.tech/abra/pkg/container"
|
|
||||||
"coopcloud.tech/abra/pkg/recipe"
|
"coopcloud.tech/abra/pkg/recipe"
|
||||||
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
|
||||||
"coopcloud.tech/abra/pkg/upstream/container"
|
|
||||||
"github.com/docker/cli/cli/command"
|
|
||||||
"github.com/docker/docker/api/types"
|
|
||||||
"github.com/docker/docker/api/types/filters"
|
|
||||||
dockerClient "github.com/docker/docker/client"
|
|
||||||
"github.com/docker/docker/pkg/archive"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
type restoreConfig struct {
|
var targetPath string
|
||||||
preHookCmd string
|
var targetPathFlag = &cli.StringFlag{
|
||||||
postHookCmd string
|
Name: "target, t",
|
||||||
|
Usage: "Target path",
|
||||||
|
Destination: &targetPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
var appRestoreCommand = cli.Command{
|
var appRestoreCommand = cli.Command{
|
||||||
Name: "restore",
|
Name: "restore",
|
||||||
Aliases: []string{"rs"},
|
Aliases: []string{"rs"},
|
||||||
Usage: "Run app restore",
|
Usage: "Restore an app backup",
|
||||||
ArgsUsage: "<domain> <service> <file>",
|
ArgsUsage: "<domain> <service>",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
internal.DebugFlag,
|
internal.DebugFlag,
|
||||||
internal.OfflineFlag,
|
internal.OfflineFlag,
|
||||||
internal.ChaosFlag,
|
targetPathFlag,
|
||||||
},
|
},
|
||||||
Before: internal.SubCommandBefore,
|
Before: internal.SubCommandBefore,
|
||||||
BashComplete: autocomplete.AppNameComplete,
|
BashComplete: autocomplete.AppNameComplete,
|
||||||
Description: `
|
|
||||||
Run an app restore.
|
|
||||||
|
|
||||||
Pre/post hook commands are defined in the recipe configuration. Abra reads this
|
|
||||||
configuration and run the comands in the context of the service before
|
|
||||||
restoring the backup.
|
|
||||||
|
|
||||||
Unlike "abra app backup", restore must be run on a per-service basis. You can
|
|
||||||
not restore all services in one go. Backup files produced by Abra are
|
|
||||||
compressed archives which use absolute paths. This allows Abra to restore
|
|
||||||
according to standard tar command logic, i.e. the backup will be restored to
|
|
||||||
the path it was originally backed up from.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
abra app restore example.com app ~/.abra/backups/example_com_app_609341138.tar.gz
|
|
||||||
`,
|
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
|
|
||||||
recipe, err := recipe.Get(app.Recipe, internal.Offline)
|
if err := recipe.EnsureExists(app.Recipe); err != nil {
|
||||||
if err != nil {
|
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !internal.Chaos {
|
if !internal.Chaos {
|
||||||
if err := recipePkg.EnsureIsClean(app.Recipe); err != nil {
|
if err := recipe.EnsureIsClean(app.Recipe); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !internal.Offline {
|
if !internal.Offline {
|
||||||
if err := recipePkg.EnsureUpToDate(app.Recipe); err != nil {
|
if err := recipe.EnsureUpToDate(app.Recipe); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := recipePkg.EnsureLatest(app.Recipe); err != nil {
|
if err := recipe.EnsureLatest(app.Recipe); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceName := c.Args().Get(1)
|
|
||||||
if serviceName == "" {
|
|
||||||
internal.ShowSubcommandHelpAndError(c, errors.New("missing <service>?"))
|
|
||||||
}
|
|
||||||
|
|
||||||
backupPath := c.Args().Get(2)
|
|
||||||
if backupPath == "" {
|
|
||||||
internal.ShowSubcommandHelpAndError(c, errors.New("missing <file>?"))
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := os.Stat(backupPath); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
logrus.Fatalf("%s doesn't exist?", backupPath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
restoreConfigs := make(map[string]restoreConfig)
|
|
||||||
for _, service := range recipe.Config.Services {
|
|
||||||
if restoreEnabled, ok := service.Deploy.Labels["backupbot.restore"]; ok {
|
|
||||||
if restoreEnabled == "true" {
|
|
||||||
fullServiceName := fmt.Sprintf("%s_%s", app.StackName(), service.Name)
|
|
||||||
rsConfig := restoreConfig{}
|
|
||||||
|
|
||||||
logrus.Debugf("restore config detected for %s", fullServiceName)
|
|
||||||
|
|
||||||
if preHookCmd, ok := service.Deploy.Labels["backupbot.restore.pre-hook"]; ok {
|
|
||||||
logrus.Debugf("detected pre-hook command for %s: %s", fullServiceName, preHookCmd)
|
|
||||||
rsConfig.preHookCmd = preHookCmd
|
|
||||||
}
|
|
||||||
|
|
||||||
if postHookCmd, ok := service.Deploy.Labels["backupbot.restore.post-hook"]; ok {
|
|
||||||
logrus.Debugf("detected post-hook command for %s: %s", fullServiceName, postHookCmd)
|
|
||||||
rsConfig.postHookCmd = postHookCmd
|
|
||||||
}
|
|
||||||
|
|
||||||
restoreConfigs[service.Name] = rsConfig
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rsConfig, ok := restoreConfigs[serviceName]
|
|
||||||
if !ok {
|
|
||||||
rsConfig = restoreConfig{}
|
|
||||||
}
|
|
||||||
|
|
||||||
cl, err := client.New(app.Server)
|
cl, err := client.New(app.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := runRestore(cl, app, backupPath, serviceName, rsConfig); err != nil {
|
targetContainer, err := internal.RetrieveBackupBotContainer(cl)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
execEnv := []string{fmt.Sprintf("SERVICE=%s", app.Domain)}
|
||||||
|
if snapshot != "" {
|
||||||
|
logrus.Debugf("including SNAPSHOT=%s in backupbot exec invocation", snapshot)
|
||||||
|
execEnv = append(execEnv, fmt.Sprintf("SNAPSHOT=%s", snapshot))
|
||||||
|
}
|
||||||
|
if targetPath != "" {
|
||||||
|
logrus.Debugf("including TARGET=%s in backupbot exec invocation", targetPath)
|
||||||
|
execEnv = append(execEnv, fmt.Sprintf("TARGET=%s", targetPath))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := internal.RunBackupCmdRemote(cl, "restore", targetContainer.ID, execEnv); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// runRestore does the actual restore logic.
|
|
||||||
func runRestore(cl *dockerClient.Client, app config.App, backupPath, serviceName string, rsConfig restoreConfig) error {
|
|
||||||
// FIXME: avoid instantiating a new CLI
|
|
||||||
dcli, err := command.NewDockerCli()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
filters := filters.NewArgs()
|
|
||||||
filters.Add("name", fmt.Sprintf("^%s_%s", app.StackName(), serviceName))
|
|
||||||
|
|
||||||
targetContainer, err := containerPkg.GetContainer(context.Background(), cl, filters, true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fullServiceName := fmt.Sprintf("%s_%s", app.StackName(), serviceName)
|
|
||||||
if rsConfig.preHookCmd != "" {
|
|
||||||
splitCmd := internal.SafeSplit(rsConfig.preHookCmd)
|
|
||||||
|
|
||||||
logrus.Debugf("split pre-hook command for %s into %s", fullServiceName, splitCmd)
|
|
||||||
|
|
||||||
preHookExecOpts := types.ExecConfig{
|
|
||||||
AttachStderr: true,
|
|
||||||
AttachStdin: true,
|
|
||||||
AttachStdout: true,
|
|
||||||
Cmd: splitCmd,
|
|
||||||
Detach: false,
|
|
||||||
Tty: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := container.RunExec(dcli, cl, targetContainer.ID, &preHookExecOpts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Infof("succesfully ran %s pre-hook command: %s", fullServiceName, rsConfig.preHookCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
backupReader, err := os.Open(backupPath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
content, err := archive.DecompressStream(backupReader)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(d1): we use absolute paths so tar knows what to do. it will restore
|
|
||||||
// files according to the paths set in the compressed archive
|
|
||||||
restorePath := "/"
|
|
||||||
|
|
||||||
copyOpts := types.CopyToContainerOptions{AllowOverwriteDirWithFile: false, CopyUIDGID: false}
|
|
||||||
if err := cl.CopyToContainer(context.Background(), targetContainer.ID, restorePath, content, copyOpts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Infof("restored %s to %s", backupPath, fullServiceName)
|
|
||||||
|
|
||||||
if rsConfig.postHookCmd != "" {
|
|
||||||
splitCmd := internal.SafeSplit(rsConfig.postHookCmd)
|
|
||||||
|
|
||||||
logrus.Debugf("split post-hook command for %s into %s", fullServiceName, splitCmd)
|
|
||||||
|
|
||||||
postHookExecOpts := types.ExecConfig{
|
|
||||||
AttachStderr: true,
|
|
||||||
AttachStdin: true,
|
|
||||||
AttachStdout: true,
|
|
||||||
Cmd: splitCmd,
|
|
||||||
Detach: false,
|
|
||||||
Tty: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := container.RunExec(dcli, cl, targetContainer.ID, &postHookExecOpts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Infof("succesfully ran %s post-hook command: %s", fullServiceName, rsConfig.postHookCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ var appRunCommand = cli.Command{
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := container.RunExec(dcli, cl, targetContainer.ID, &execCreateOpts); err != nil {
|
if _, err := container.RunExec(dcli, cl, targetContainer.ID, &execCreateOpts); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"log"
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/pkg/autocomplete"
|
"coopcloud.tech/abra/pkg/autocomplete"
|
||||||
|
@ -131,12 +132,12 @@ Passing "--force/-f" will select all volumes for removal. Be careful.
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(volumesToRemove) > 0 {
|
if len(volumesToRemove) > 0 {
|
||||||
err = client.RemoveVolumes(cl, context.Background(), app.Server, volumesToRemove, internal.Force)
|
err := client.RemoveVolumes(cl, context.Background(), volumesToRemove, internal.Force, 5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
log.Fatalf("removing volumes failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Info("volumes removed successfully")
|
logrus.Infof("%d volumes removed successfully", len(volumesToRemove))
|
||||||
} else {
|
} else {
|
||||||
logrus.Info("no volumes removed")
|
logrus.Info("no volumes removed")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +1,67 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"context"
|
||||||
|
|
||||||
|
"coopcloud.tech/abra/pkg/config"
|
||||||
|
containerPkg "coopcloud.tech/abra/pkg/container"
|
||||||
|
"coopcloud.tech/abra/pkg/service"
|
||||||
|
"coopcloud.tech/abra/pkg/upstream/container"
|
||||||
|
"github.com/docker/cli/cli/command"
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/filters"
|
||||||
|
dockerClient "github.com/docker/docker/client"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SafeSplit splits up a string into a list of commands safely.
|
// RetrieveBackupBotContainer gets the deployed backupbot container.
|
||||||
func SafeSplit(s string) []string {
|
func RetrieveBackupBotContainer(cl *dockerClient.Client) (types.Container, error) {
|
||||||
split := strings.Split(s, " ")
|
ctx := context.Background()
|
||||||
|
chosenService, err := service.GetServiceByLabel(ctx, cl, config.BackupbotLabel, NoInput)
|
||||||
var result []string
|
if err != nil {
|
||||||
var inquote string
|
return types.Container{}, err
|
||||||
var block string
|
|
||||||
for _, i := range split {
|
|
||||||
if inquote == "" {
|
|
||||||
if strings.HasPrefix(i, "'") || strings.HasPrefix(i, "\"") {
|
|
||||||
inquote = string(i[0])
|
|
||||||
block = strings.TrimPrefix(i, inquote) + " "
|
|
||||||
} else {
|
|
||||||
result = append(result, i)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if !strings.HasSuffix(i, inquote) {
|
|
||||||
block += i + " "
|
|
||||||
} else {
|
|
||||||
block += strings.TrimSuffix(i, inquote)
|
|
||||||
inquote = ""
|
|
||||||
result = append(result, block)
|
|
||||||
block = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
logrus.Debugf("retrieved %s as backup enabled service", chosenService.Spec.Name)
|
||||||
|
|
||||||
|
filters := filters.NewArgs()
|
||||||
|
filters.Add("name", chosenService.Spec.Name)
|
||||||
|
targetContainer, err := containerPkg.GetContainer(
|
||||||
|
ctx,
|
||||||
|
cl,
|
||||||
|
filters,
|
||||||
|
NoInput,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return types.Container{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return targetContainer, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunBackupCmdRemote runs a backup related command on a remote backupbot container.
|
||||||
|
func RunBackupCmdRemote(cl *dockerClient.Client, backupCmd string, containerID string, execEnv []string) error {
|
||||||
|
execBackupListOpts := types.ExecConfig{
|
||||||
|
AttachStderr: true,
|
||||||
|
AttachStdin: true,
|
||||||
|
AttachStdout: true,
|
||||||
|
Cmd: []string{"/usr/bin/backup", "--", backupCmd},
|
||||||
|
Detach: false,
|
||||||
|
Env: execEnv,
|
||||||
|
Tty: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Debugf("running backup %s on %s with exec config %v", backupCmd, containerID, execBackupListOpts)
|
||||||
|
|
||||||
|
// FIXME: avoid instantiating a new CLI
|
||||||
|
dcli, err := command.NewDockerCli()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := container.RunExec(dcli, cl, containerID, &execBackupListOpts); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ func RunCmdRemote(cl *dockerClient.Client, app config.App, abraSh, serviceName,
|
||||||
Tty: false,
|
Tty: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := container.RunExec(dcli, cl, targetContainer.ID, &execCreateOpts); err != nil {
|
if _, err := container.RunExec(dcli, cl, targetContainer.ID, &execCreateOpts); err != nil {
|
||||||
logrus.Infof("%s does not exist for %s, use /bin/sh as fallback", shell, app.Name)
|
logrus.Infof("%s does not exist for %s, use /bin/sh as fallback", shell, app.Name)
|
||||||
shell = "/bin/sh"
|
shell = "/bin/sh"
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ func RunCmdRemote(cl *dockerClient.Client, app config.App, abraSh, serviceName,
|
||||||
execCreateOpts.Tty = false
|
execCreateOpts.Tty = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := container.RunExec(dcli, cl, targetContainer.ID, &execCreateOpts); err != nil {
|
if _, err := container.RunExec(dcli, cl, targetContainer.ID, &execCreateOpts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,17 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/api/types/volume"
|
"github.com/docker/docker/api/types/volume"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetVolumes(cl *client.Client, ctx context.Context, server string, fs filters.Args) ([]*volume.Volume, error) {
|
func GetVolumes(cl *client.Client, ctx context.Context, server string, fs filters.Args) ([]*volume.Volume, error) {
|
||||||
volumeListOptions := volume.ListOptions{fs}
|
volumeListOKBody, err := cl.VolumeList(ctx, volume.ListOptions{Filters: fs})
|
||||||
volumeListOKBody, err := cl.VolumeList(ctx, volumeListOptions)
|
|
||||||
volumeList := volumeListOKBody.Volumes
|
volumeList := volumeListOKBody.Volumes
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return volumeList, err
|
return volumeList, err
|
||||||
|
@ -29,13 +31,32 @@ func GetVolumeNames(volumes []*volume.Volume) []string {
|
||||||
return volumeNames
|
return volumeNames
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveVolumes(cl *client.Client, ctx context.Context, server string, volumeNames []string, force bool) error {
|
func RemoveVolumes(cl *client.Client, ctx context.Context, volumeNames []string, force bool, retries int) error {
|
||||||
for _, volName := range volumeNames {
|
for _, volName := range volumeNames {
|
||||||
err := cl.VolumeRemove(ctx, volName, force)
|
err := retryFunc(5, func() error {
|
||||||
|
return cl.VolumeRemove(context.Background(), volName, force)
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("volume %s: %s", volName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// retryFunc retries the given function for the given retries. After the nth
|
||||||
|
// retry it waits (n + 1)^2 seconds before the next retry (starting with n=0).
|
||||||
|
// It returns an error if the function still failed after the last retry.
|
||||||
|
func retryFunc(retries int, fn func() error) error {
|
||||||
|
for i := 0; i < retries; i++ {
|
||||||
|
err := fn()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if i+1 < retries {
|
||||||
|
sleep := time.Duration(i+1) * time.Duration(i+1)
|
||||||
|
logrus.Infof("%s: waiting %d seconds before next retry", err, sleep)
|
||||||
|
time.Sleep(sleep * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fmt.Errorf("%d retries failed", retries)
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package app
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -69,9 +69,9 @@ func (a App) StackName() string {
|
||||||
func StackName(appName string) string {
|
func StackName(appName string) string {
|
||||||
stackName := SanitiseAppName(appName)
|
stackName := SanitiseAppName(appName)
|
||||||
|
|
||||||
if len(stackName) > 45 {
|
if len(stackName) > MAX_SANITISED_APP_NAME_LENGTH {
|
||||||
logrus.Debugf("trimming %s to %s to avoid runtime limits", stackName, stackName[:45])
|
logrus.Debugf("trimming %s to %s to avoid runtime limits", stackName, stackName[:MAX_SANITISED_APP_NAME_LENGTH])
|
||||||
stackName = stackName[:45]
|
stackName = stackName[:MAX_SANITISED_APP_NAME_LENGTH]
|
||||||
}
|
}
|
||||||
|
|
||||||
return stackName
|
return stackName
|
||||||
|
|
|
@ -36,6 +36,11 @@ var REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud"
|
||||||
var CATALOGUE_JSON_REPO_NAME = "recipes-catalogue-json"
|
var CATALOGUE_JSON_REPO_NAME = "recipes-catalogue-json"
|
||||||
var SSH_URL_TEMPLATE = "ssh://git@git.coopcloud.tech:2222/coop-cloud/%s.git"
|
var SSH_URL_TEMPLATE = "ssh://git@git.coopcloud.tech:2222/coop-cloud/%s.git"
|
||||||
|
|
||||||
|
const MAX_SANITISED_APP_NAME_LENGTH = 45
|
||||||
|
const MAX_DOCKER_SECRET_LENGTH = 64
|
||||||
|
|
||||||
|
var BackupbotLabel = "coop-cloud.backupbot.enabled"
|
||||||
|
|
||||||
// envVarModifiers is a list of env var modifier strings. These are added to
|
// envVarModifiers is a list of env var modifier strings. These are added to
|
||||||
// env vars as comments and modify their processing by Abra, e.g. determining
|
// env vars as comments and modify their processing by Abra, e.g. determining
|
||||||
// how long secrets should be.
|
// how long secrets should be.
|
||||||
|
|
|
@ -28,7 +28,7 @@ func GetContainer(c context.Context, cl *client.Client, filters filters.Args, no
|
||||||
return types.Container{}, fmt.Errorf("no containers matching the %v filter found?", filter)
|
return types.Container{}, fmt.Errorf("no containers matching the %v filter found?", filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(containers) != 1 {
|
if len(containers) > 1 {
|
||||||
var containersRaw []string
|
var containersRaw []string
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
containerName := strings.Join(container.Names, " ")
|
containerName := strings.Join(container.Names, " ")
|
||||||
|
|
|
@ -115,6 +115,13 @@ var LintRules = map[string][]LintRule{
|
||||||
HowToResolve: "upload your recipe to git.coopcloud.tech/coop-cloud/...",
|
HowToResolve: "upload your recipe to git.coopcloud.tech/coop-cloud/...",
|
||||||
Function: LintHasRecipeRepo,
|
Function: LintHasRecipeRepo,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Ref: "R015",
|
||||||
|
Level: "warn",
|
||||||
|
Description: "long secret names",
|
||||||
|
HowToResolve: "reduce length of secret names to 12 chars",
|
||||||
|
Function: LintSecretLengths,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
{
|
{
|
||||||
|
@ -401,6 +408,16 @@ func LintHasRecipeRepo(recipe recipe.Recipe) (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LintSecretLengths(recipe recipe.Recipe) (bool, error) {
|
||||||
|
for name := range recipe.Config.Secrets {
|
||||||
|
if len(name) > 12 {
|
||||||
|
return false, fmt.Errorf("secret %s is longer than 12 characters", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
func LintValidTags(recipe recipe.Recipe) (bool, error) {
|
func LintValidTags(recipe recipe.Recipe) (bool, error) {
|
||||||
recipeDir := path.Join(config.RECIPES_DIR, recipe.Name)
|
recipeDir := path.Join(config.RECIPES_DIR, recipe.Name)
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ func ReadSecretsConfig(appEnvPath string, composeFiles []string, stackName strin
|
||||||
appEnv["STACK_NAME"] = stackName
|
appEnv["STACK_NAME"] = stackName
|
||||||
|
|
||||||
opts := stack.Deploy{Composefiles: composeFiles}
|
opts := stack.Deploy{Composefiles: composeFiles}
|
||||||
config, err := loader.LoadComposefile(opts, appEnv)
|
composeConfig, err := loader.LoadComposefile(opts, appEnv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ func ReadSecretsConfig(appEnvPath string, composeFiles []string, stackName strin
|
||||||
}
|
}
|
||||||
|
|
||||||
var enabledSecrets []string
|
var enabledSecrets []string
|
||||||
for _, service := range config.Services {
|
for _, service := range composeConfig.Services {
|
||||||
for _, secret := range service.Secrets {
|
for _, secret := range service.Secrets {
|
||||||
enabledSecrets = append(enabledSecrets, secret.Source)
|
enabledSecrets = append(enabledSecrets, secret.Source)
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func ReadSecretsConfig(appEnvPath string, composeFiles []string, stackName strin
|
||||||
}
|
}
|
||||||
|
|
||||||
secretValues := map[string]Secret{}
|
secretValues := map[string]Secret{}
|
||||||
for secretId, secretConfig := range config.Secrets {
|
for secretId, secretConfig := range composeConfig.Secrets {
|
||||||
if string(secretConfig.Name[len(secretConfig.Name)-1]) == "_" {
|
if string(secretConfig.Name[len(secretConfig.Name)-1]) == "_" {
|
||||||
return nil, fmt.Errorf("missing version for secret? (%s)", secretId)
|
return nil, fmt.Errorf("missing version for secret? (%s)", secretId)
|
||||||
}
|
}
|
||||||
|
@ -126,6 +126,10 @@ func ReadSecretsConfig(appEnvPath string, composeFiles []string, stackName strin
|
||||||
secretVersion := secretConfig.Name[lastIdx+1:]
|
secretVersion := secretConfig.Name[lastIdx+1:]
|
||||||
value := Secret{Version: secretVersion, RemoteName: secretConfig.Name}
|
value := Secret{Version: secretVersion, RemoteName: secretConfig.Name}
|
||||||
|
|
||||||
|
if len(value.RemoteName) > config.MAX_DOCKER_SECRET_LENGTH {
|
||||||
|
return nil, fmt.Errorf("secret %s is > %d chars when combined with %s", secretId, config.MAX_DOCKER_SECRET_LENGTH, stackName)
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the length modifier is set for this secret.
|
// Check if the length modifier is set for this secret.
|
||||||
for envName, modifierValues := range appModifiers {
|
for envName, modifierValues := range appModifiers {
|
||||||
// configWithoutEnv contains the raw name as defined in the compose.yaml
|
// configWithoutEnv contains the raw name as defined in the compose.yaml
|
||||||
|
|
|
@ -28,3 +28,12 @@ func TestReadSecretsConfig(t *testing.T) {
|
||||||
assert.Equal(t, "v2", secretsFromConfig["test_pass_three"].Version)
|
assert.Equal(t, "v2", secretsFromConfig["test_pass_three"].Version)
|
||||||
assert.Equal(t, 0, secretsFromConfig["test_pass_three"].Length)
|
assert.Equal(t, 0, secretsFromConfig["test_pass_three"].Length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadSecretsConfigWithLongDomain(t *testing.T) {
|
||||||
|
composeFiles := []string{"./testdir/compose.yaml"}
|
||||||
|
_, err := ReadSecretsConfig("./testdir/.env.sample", composeFiles, "should_break_on_forty_eight_char_stack_nameeeeee")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected failure, stack name is too long")
|
||||||
|
}
|
||||||
|
assert.Contains(t, err.Error(), "is > 64 chars")
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,70 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetService retrieves a service container based on a label. If prompt is true
|
||||||
|
// and the retrievd count of service containers does not match 1, then a prompt
|
||||||
|
// is presented to let the user choose. An error is returned when no service is
|
||||||
|
// found.
|
||||||
|
func GetServiceByLabel(c context.Context, cl *client.Client, label string, prompt bool) (swarm.Service, error) {
|
||||||
|
services, err := cl.ServiceList(c, types.ServiceListOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return swarm.Service{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(services) == 0 {
|
||||||
|
return swarm.Service{}, fmt.Errorf("no services deployed?")
|
||||||
|
}
|
||||||
|
|
||||||
|
var matchingServices []swarm.Service
|
||||||
|
for _, service := range services {
|
||||||
|
if enabled, exists := service.Spec.Labels[label]; exists && enabled == "true" {
|
||||||
|
matchingServices = append(matchingServices, service)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(matchingServices) == 0 {
|
||||||
|
return swarm.Service{}, fmt.Errorf("no services deployed matching label '%s'?", label)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(matchingServices) > 1 {
|
||||||
|
var servicesRaw []string
|
||||||
|
for _, service := range matchingServices {
|
||||||
|
serviceName := service.Spec.Name
|
||||||
|
created := formatter.HumanDuration(service.CreatedAt.Unix())
|
||||||
|
servicesRaw = append(servicesRaw, fmt.Sprintf("%s (created %v)", serviceName, created))
|
||||||
|
}
|
||||||
|
|
||||||
|
if !prompt {
|
||||||
|
err := fmt.Errorf("expected 1 service but found %v: %s", len(matchingServices), strings.Join(servicesRaw, " "))
|
||||||
|
return swarm.Service{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Warnf("ambiguous service list received, prompting for input")
|
||||||
|
|
||||||
|
var response string
|
||||||
|
prompt := &survey.Select{
|
||||||
|
Message: "which service are you looking for?",
|
||||||
|
Options: servicesRaw,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := survey.AskOne(prompt, &response); err != nil {
|
||||||
|
return swarm.Service{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
chosenService := strings.TrimSpace(strings.Split(response, " ")[0])
|
||||||
|
for _, service := range matchingServices {
|
||||||
|
serviceName := strings.ToLower(service.Spec.Name)
|
||||||
|
if serviceName == chosenService {
|
||||||
|
return service, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Panic("failed to match chosen service")
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchingServices[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetService retrieves a service container. If prompt is true and the retrievd
|
// GetService retrieves a service container. If prompt is true and the retrievd
|
||||||
// count of service containers does not match 1, then a prompt is presented to
|
// count of service containers does not match 1, then a prompt is presented to
|
||||||
// let the user choose. A count of 0 is handled gracefully.
|
// let the user choose. A count of 0 is handled gracefully.
|
||||||
|
|
|
@ -13,7 +13,10 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunExec(dockerCli command.Cli, client *apiclient.Client, containerID string, execConfig *types.ExecConfig) error {
|
// RunExec runs a command on a remote container. io.Writer corresponds to the
|
||||||
|
// command output.
|
||||||
|
func RunExec(dockerCli command.Cli, client *apiclient.Client, containerID string,
|
||||||
|
execConfig *types.ExecConfig) (io.Writer, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// We need to check the tty _before_ we do the ContainerExecCreate, because
|
// We need to check the tty _before_ we do the ContainerExecCreate, because
|
||||||
|
@ -21,22 +24,22 @@ func RunExec(dockerCli command.Cli, client *apiclient.Client, containerID string
|
||||||
// there's no easy way to clean those up). But also in order to make "not
|
// there's no easy way to clean those up). But also in order to make "not
|
||||||
// exist" errors take precedence we do a dummy inspect first.
|
// exist" errors take precedence we do a dummy inspect first.
|
||||||
if _, err := client.ContainerInspect(ctx, containerID); err != nil {
|
if _, err := client.ContainerInspect(ctx, containerID); err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !execConfig.Detach {
|
if !execConfig.Detach {
|
||||||
if err := dockerCli.In().CheckTty(execConfig.AttachStdin, execConfig.Tty); err != nil {
|
if err := dockerCli.In().CheckTty(execConfig.AttachStdin, execConfig.Tty); err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := client.ContainerExecCreate(ctx, containerID, *execConfig)
|
response, err := client.ContainerExecCreate(ctx, containerID, *execConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
execID := response.ID
|
execID := response.ID
|
||||||
if execID == "" {
|
if execID == "" {
|
||||||
return errors.New("exec ID empty")
|
return nil, errors.New("exec ID empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
if execConfig.Detach {
|
if execConfig.Detach {
|
||||||
|
@ -44,13 +47,13 @@ func RunExec(dockerCli command.Cli, client *apiclient.Client, containerID string
|
||||||
Detach: execConfig.Detach,
|
Detach: execConfig.Detach,
|
||||||
Tty: execConfig.Tty,
|
Tty: execConfig.Tty,
|
||||||
}
|
}
|
||||||
return client.ContainerExecStart(ctx, execID, execStartCheck)
|
return nil, client.ContainerExecStart(ctx, execID, execStartCheck)
|
||||||
}
|
}
|
||||||
return interactiveExec(ctx, dockerCli, client, execConfig, execID)
|
return interactiveExec(ctx, dockerCli, client, execConfig, execID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func interactiveExec(ctx context.Context, dockerCli command.Cli, client *apiclient.Client,
|
func interactiveExec(ctx context.Context, dockerCli command.Cli, client *apiclient.Client,
|
||||||
execConfig *types.ExecConfig, execID string) error {
|
execConfig *types.ExecConfig, execID string) (io.Writer, error) {
|
||||||
// Interactive exec requested.
|
// Interactive exec requested.
|
||||||
var (
|
var (
|
||||||
out, stderr io.Writer
|
out, stderr io.Writer
|
||||||
|
@ -76,7 +79,7 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, client *apiclie
|
||||||
}
|
}
|
||||||
resp, err := client.ContainerExecAttach(ctx, execID, execStartCheck)
|
resp, err := client.ContainerExecAttach(ctx, execID, execStartCheck)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return out, err
|
||||||
}
|
}
|
||||||
defer resp.Close()
|
defer resp.Close()
|
||||||
|
|
||||||
|
@ -107,10 +110,10 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, client *apiclie
|
||||||
|
|
||||||
if err := <-errCh; err != nil {
|
if err := <-errCh; err != nil {
|
||||||
logrus.Debugf("Error hijack: %s", err)
|
logrus.Debugf("Error hijack: %s", err)
|
||||||
return err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return getExecExitStatus(ctx, client, execID)
|
return out, getExecExitStatus(ctx, client, execID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getExecExitStatus(ctx context.Context, client apiclient.ContainerAPIClient, execID string) error {
|
func getExecExitStatus(ctx context.Context, client apiclient.ContainerAPIClient, execID string) error {
|
||||||
|
|
|
@ -233,7 +233,7 @@ func validateExternalNetworks(ctx context.Context, client dockerClient.NetworkAP
|
||||||
network, err := client.NetworkInspect(ctx, networkName, types.NetworkInspectOptions{})
|
network, err := client.NetworkInspect(ctx, networkName, types.NetworkInspectOptions{})
|
||||||
switch {
|
switch {
|
||||||
case dockerClient.IsErrNotFound(err):
|
case dockerClient.IsErrNotFound(err):
|
||||||
return errors.Errorf("network %q is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed", networkName)
|
return errors.Errorf("network %q is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed, which you can do by running this on the server: docker network create -d overlay proxy", networkName)
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return err
|
return err
|
||||||
case network.Scope != "swarm":
|
case network.Scope != "swarm":
|
||||||
|
|
|
@ -45,7 +45,9 @@ function install_abra_release {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
if [[ $ARCH =~ "aarch64" ]]; then
|
if [[ $ARCH =~ "x86_64" ]]; then
|
||||||
|
ARCH="amd64"
|
||||||
|
elif [[ $ARCH =~ "aarch64" ]]; then
|
||||||
ARCH="arm64"
|
ARCH="arm64"
|
||||||
elif [[ $ARCH =~ "armv5l" ]]; then
|
elif [[ $ARCH =~ "armv5l" ]]; then
|
||||||
ARCH="armv5"
|
ARCH="armv5"
|
||||||
|
@ -55,7 +57,7 @@ function install_abra_release {
|
||||||
ARCH="armv7"
|
ARCH="armv7"
|
||||||
fi
|
fi
|
||||||
PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]')_$ARCH
|
PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]')_$ARCH
|
||||||
FILENAME="abra_"$ABRA_VERSION"_"$PLATFORM""
|
FILENAME="abra_"$ABRA_VERSION"_"$PLATFORM".tar.gz"
|
||||||
sed_command_rel='s/.*"assets":\[\{[^]]*"name":"'$FILENAME'"[^}]*"browser_download_url":"([^"]*)".*\].*/\1/p'
|
sed_command_rel='s/.*"assets":\[\{[^]]*"name":"'$FILENAME'"[^}]*"browser_download_url":"([^"]*)".*\].*/\1/p'
|
||||||
sed_command_checksums='s/.*"assets":\[\{[^\]*"name":"checksums.txt"[^}]*"browser_download_url":"([^"]*)".*\].*/\1/p'
|
sed_command_checksums='s/.*"assets":\[\{[^\]*"name":"checksums.txt"[^}]*"browser_download_url":"([^"]*)".*\].*/\1/p'
|
||||||
|
|
||||||
|
@ -65,7 +67,7 @@ function install_abra_release {
|
||||||
|
|
||||||
checksums=$(wget -q -O- $checksums_url)
|
checksums=$(wget -q -O- $checksums_url)
|
||||||
checksum=$(echo "$checksums" | grep "$FILENAME" - | sed -En 's/([0-9a-f]{64})\s+'"$FILENAME"'.*/\1/p')
|
checksum=$(echo "$checksums" | grep "$FILENAME" - | sed -En 's/([0-9a-f]{64})\s+'"$FILENAME"'.*/\1/p')
|
||||||
abra_download="/tmp/abra-download"
|
abra_download="/tmp/abra-download.tar.gz"
|
||||||
|
|
||||||
echo "downloading $ABRA_VERSION $PLATFORM binary release for abra..."
|
echo "downloading $ABRA_VERSION $PLATFORM binary release for abra..."
|
||||||
|
|
||||||
|
@ -77,7 +79,10 @@ function install_abra_release {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$(tput setaf 2)check successful!$(tput sgr0)"
|
echo "$(tput setaf 2)check successful!$(tput sgr0)"
|
||||||
mv "$abra_download" "$HOME/.local/bin/abra"
|
cd /tmp/
|
||||||
|
tar xf abra-download.tar.gz
|
||||||
|
mv abra "$HOME/.local/bin/abra"
|
||||||
|
tar tf abra-download.tar.gz | xargs rm -f
|
||||||
chmod +x "$HOME/.local/bin/abra"
|
chmod +x "$HOME/.local/bin/abra"
|
||||||
|
|
||||||
x=$(echo $PATH | grep $HOME/.local/bin)
|
x=$(echo $PATH | grep $HOME/.local/bin)
|
||||||
|
|
|
@ -104,9 +104,6 @@ teardown(){
|
||||||
|
|
||||||
_undeploy_app
|
_undeploy_app
|
||||||
|
|
||||||
# TODO: should wait as long as volume is no longer in use
|
|
||||||
sleep 10
|
|
||||||
|
|
||||||
run $ABRA app volume rm "$TEST_APP_DOMAIN" --no-input
|
run $ABRA app volume rm "$TEST_APP_DOMAIN" --no-input
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
|
|
|
@ -78,9 +78,6 @@ teardown(){
|
||||||
|
|
||||||
_undeploy_app
|
_undeploy_app
|
||||||
|
|
||||||
# NOTE(d1): to let the stack come down before nuking volumes
|
|
||||||
sleep 10
|
|
||||||
|
|
||||||
run $ABRA app volume rm "$TEST_APP_DOMAIN" --force
|
run $ABRA app volume rm "$TEST_APP_DOMAIN" --force
|
||||||
assert_success
|
assert_success
|
||||||
assert_output --partial 'volumes removed successfully'
|
assert_output --partial 'volumes removed successfully'
|
||||||
|
@ -92,9 +89,6 @@ teardown(){
|
||||||
|
|
||||||
_undeploy_app
|
_undeploy_app
|
||||||
|
|
||||||
# NOTE(d1): to let the stack come down before nuking volumes
|
|
||||||
sleep 10
|
|
||||||
|
|
||||||
run $ABRA app volume rm "$TEST_APP_DOMAIN" --force
|
run $ABRA app volume rm "$TEST_APP_DOMAIN" --force
|
||||||
assert_success
|
assert_success
|
||||||
assert_output --partial 'volumes removed successfully'
|
assert_output --partial 'volumes removed successfully'
|
||||||
|
|
Loading…
Reference in New Issue