Update documentation for docker
This commit is contained in:
parent
3e29d17625
commit
98585407d3
5 changed files with 99 additions and 14 deletions
39
README.md
39
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
|
||||
```
|
||||
|
|
11
docker-compose.yml
Normal file
11
docker-compose.yml
Normal file
|
@ -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
|
14
main.go
14
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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
3
utils/constants/constants.go
Normal file
3
utils/constants/constants.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
package constants
|
||||
|
||||
const CliDataPath = "/cli-data/"
|
Loading…
Reference in a new issue