Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Update documentation for docker

Neeraj Gupta98585407d31e
diff --git a/README.md b/README.md
index 641213f1fd..5371a17901 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,33 @@
ente-cli export
```
-## Testing
+## Docker
+
+### Configure
+Modify the `docker-compose.yml` and add volume.
+``cli-data`` volume is mandatory, you can add more volumes for your export directory.
+ * Build the docker image
+ ```shell
+ docker build -t ente-cli:latest .
+ ```
+ * Start the container in detached mode
+ ```bash
+ docker-compose up -d
+ ```
+exec into the container
+```shell
+ docker-compose exec ente-cli /bin/sh
+```
+
+
+#### How to directly execute the command
+
+ ```shell
+ docker run -it --rm ente-cli:latest ls
+ ```
+
+
+## Build locally
Run the release script to build the binary and run it.
@@ -44,14 +70,3 @@ or you can run the following command
```shell
./bin/ente-cli --help
```
-
-
-## Docker
- Build the docker image
- ```shell
- docker build -t ente-cli:latest .
- ```
- Run the commands using:
- ```shell
- docker run -it --rm ente-cli:latest ./ente-cli --help
- ```
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000000..b3c8ad0cea
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,11 @@
+version: '3'
+services:
+ ente-cli:
+ image: ente-cli:latest
+ command: /bin/sh
+ volumes:
+ # Replace /Volumes/Data/ with a folder path on your system, typically $HOME/.ente-cli/
+ - ~/.ente-cli/:/cli-data:rw
+# - ~/Downloads/export-data:/data:rw
+ stdin_open: true
+ tty: true
diff --git a/main.go b/main.go
index 168fb921df..624dd45c8c 100644
--- a/main.go
+++ b/main.go
@@ -2,13 +2,25 @@ package main
import (
"cli-go/cmd"
+ "cli-go/internal"
"cli-go/internal/api"
"cli-go/pkg"
"cli-go/pkg/secrets"
+ "cli-go/utils/constants"
+ "fmt"
+ "log"
)
func main() {
- db, err := pkg.GetDB("ente-cli.db")
+ cliDBPath := ""
+ if secrets.IsRunningInContainer() {
+ cliDBPath = constants.CliDataPath
+ _, err := internal.ValidateDirForWrite(cliDBPath)
+ if err != nil {
+ log.Fatalf("Please mount a volume to %s to persist cli data\n%v\n", cliDBPath, err)
+ }
+ }
+ db, err := pkg.GetDB(fmt.Sprintf("%sente-cli.db", cliDBPath))
if err != nil {
panic(err)
}
diff --git a/pkg/secrets/secret.go b/pkg/secrets/secret.go
index 3c67bc7b02..49b61a232f 100644
--- a/pkg/secrets/secret.go
+++ b/pkg/secrets/secret.go
@@ -1,20 +1,32 @@
package secrets
import (
+ "cli-go/utils/constants"
"crypto/rand"
"errors"
"fmt"
"log"
+ "os"
"github.com/zalando/go-keyring"
)
+func IsRunningInContainer() bool {
+ if _, err := os.Stat("/.dockerenv"); err != nil {
+ return false
+ }
+ return true
+}
func GetOrCreateClISecret() []byte {
// get password
secret, err := keyring.Get("ente-cli-cli", "ghost")
if err != nil {
if !errors.Is(err, keyring.ErrNotFound) {
- log.Fatal(fmt.Errorf("error getting password from keyring: %w", err))
+ if IsRunningInContainer() {
+ return GetSecretFromSecretText()
+ } else {
+ log.Fatal(fmt.Errorf("error getting password from keyring: %w", err))
+ }
}
key := make([]byte, 32)
_, err = rand.Read(key)
@@ -30,3 +42,35 @@ func GetOrCreateClISecret() []byte {
}
return []byte(secret)
}
+
+// GetSecretFromSecretText reads the scecret from the secret text file.
+// If the file does not exist, it will be created and write random 32 byte secret to it.
+func GetSecretFromSecretText() []byte {
+ // Define the path to the secret text file
+ secretFilePath := fmt.Sprintf("%s.secret.txt", constants.CliDataPath)
+
+ // Check if file exists
+ _, err := os.Stat(secretFilePath)
+ if err != nil {
+ if !errors.Is(err, os.ErrNotExist) {
+ log.Fatal(fmt.Errorf("error checking secret file: %w", err))
+ }
+ // File does not exist; create and write a random 32-byte secret
+ key := make([]byte, 32)
+ _, err := rand.Read(key)
+ if err != nil {
+ log.Fatal(fmt.Errorf("error generating key: %w", err))
+ }
+ err = os.WriteFile(secretFilePath, key, 0644)
+ if err != nil {
+ log.Fatal(fmt.Errorf("error writing to secret file: %w", err))
+ }
+ return key
+ }
+ // File exists; read the secret
+ secret, err := os.ReadFile(secretFilePath)
+ if err != nil {
+ log.Fatal(fmt.Errorf("error reading from secret file: %w", err))
+ }
+ return secret
+}
diff --git a/utils/constants/constants.go b/utils/constants/constants.go
new file mode 100644
index 0000000000..7209d6466a
--- /dev/null
+++ b/utils/constants/constants.go
@@ -0,0 +1,3 @@
+package constants
+
+const CliDataPath = "/cli-data/"