Compare commits

...

4 Commits

Author SHA1 Message Date
rdelaage
bbb1c85cad
Fix upgrade command (#259)
fix #191

Co-authored-by: Romain de Laage <romain.delaage@rdelaage.ovh>
2024-02-15 14:27:37 +01:00
Natanel Shitrit
4cc44315ab
feat: add docker-cli package (#339)
Co-authored-by: Nicco <hi@nicco.io>
2024-02-15 14:26:26 +01:00
dependabot[bot]
b3440cd87c
Bump golang from 1.21-alpine to 1.22-alpine (#355)
Bumps golang from 1.21-alpine to 1.22-alpine.

---
updated-dependencies:
- dependency-name: golang
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-15 14:24:17 +01:00
rdelaage
4848702929
Use options on exec command (#253)
Co-authored-by: Romain de Laage <romain.delaage@rdelaage.ovh>
2024-02-15 14:23:43 +01:00
3 changed files with 24 additions and 21 deletions

View File

@ -1,4 +1,4 @@
FROM golang:1.21-alpine as builder FROM golang:1.22-alpine as builder
WORKDIR /app WORKDIR /app
COPY go.* . COPY go.* .
@ -7,7 +7,7 @@ COPY . .
RUN go build RUN go build
FROM restic/restic:0.16.4 FROM restic/restic:0.16.4
RUN apk add --no-cache rclone bash curl RUN apk add --no-cache rclone bash curl docker-cli
COPY --from=builder /app/autorestic /usr/bin/autorestic COPY --from=builder /app/autorestic /usr/bin/autorestic
ENTRYPOINT [] ENTRYPOINT []
CMD [ "autorestic" ] CMD [ "autorestic" ]

View File

@ -143,6 +143,7 @@ func (b Backend) Exec(args []string) error {
return err return err
} }
options := ExecuteOptions{Envs: env} options := ExecuteOptions{Envs: env}
args = append(args, combineBackendOptions("exec", b)...)
_, out, err := ExecuteResticCommand(options, args...) _, out, err := ExecuteResticCommand(options, args...)
if err != nil { if err != nil {
colors.Error.Println(out) colors.Error.Println(out)

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path" "path"
@ -37,7 +36,7 @@ func dlJSON(url string) (GithubRelease, error) {
return parsed, err return parsed, err
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return parsed, err return parsed, err
@ -73,9 +72,10 @@ func downloadAndInstallAsset(body GithubRelease, name string) error {
// Uncompress // Uncompress
bz := bzip2.NewReader(resp.Body) bz := bzip2.NewReader(resp.Body)
// Save to tmp // Save to tmp file in the same directory as the install directory
// Linux does not support overwriting the file that is currently being overwritten, but it can be deleted and a new one moved in its place. // Linux does not support overwriting the file that is currently being running
tmp, err := ioutil.TempFile(os.TempDir(), "autorestic-") // But it can be delete the old one and a new one moved in its place.
tmp, err := os.CreateTemp(INSTALL_PATH, "autorestic-")
if err != nil { if err != nil {
return err return err
} }
@ -89,24 +89,26 @@ func downloadAndInstallAsset(body GithubRelease, name string) error {
to := path.Join(INSTALL_PATH, name) to := path.Join(INSTALL_PATH, name)
defer os.Remove(tmp.Name()) // Cleanup temporary file after thread exits defer os.Remove(tmp.Name()) // Cleanup temporary file after thread exits
if err := os.Rename(tmp.Name(), to); err != nil {
colors.Error.Printf("os.Rename() failed (%v), retrying with io.Copy()\n", err.Error()) mode := os.FileMode(0755)
var src *os.File if originalBin, err := os.Lstat(to); err == nil {
var dst *os.File mode = originalBin.Mode()
if src, err = os.Open(tmp.Name()); err != nil { err := os.Remove(to)
return err if err != nil {
}
if dst, err = os.Create(to); err != nil {
return err
}
if _, err := io.Copy(dst, src); err != nil {
return err
}
if err := os.Chmod(to, 0755); err != nil {
return err return err
} }
} }
err = os.Rename(tmp.Name(), to)
if err != nil {
return err
}
err = os.Chmod(to, mode)
if err != nil {
return err
}
colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH) colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH)
return nil return nil
} }