Skip to content

Commit

Permalink
Fix and improve Docker Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpl0itU committed Mar 26, 2024
1 parent 0439f5f commit 9577a93
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 53 deletions.
5 changes: 4 additions & 1 deletion docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"strings"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
Expand Down Expand Up @@ -41,7 +42,9 @@ services:
if err != nil {
continue
}
dockerComposeFile += dockerCompose
for _, line := range strings.Split(dockerCompose, "\n") {
dockerComposeFile += "\t" + line + "\n"
}
}
return dockerComposeFile
}
Expand Down
14 changes: 7 additions & 7 deletions earnapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ func (i *EarnAppConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form)
switch kind {
case KIND_DOCKER_COMPOSE:
return `earnapp:
image: ` + EARNAPP_IMAGE_NAME + `
environment:
- EARNAPP_UUID=` + i.UUID + `
- EARNAPP_TERM="yes"
volumes:
- earnapp-data:/etc/earnapp
restart: unless-stopped
image: ` + EARNAPP_IMAGE_NAME + `
environment:
- EARNAPP_UUID=` + i.UUID + `
- EARNAPP_TERM="yes"
volumes:
- earnapp-data:/etc/earnapp
restart: unless-stopped
`, nil
case KIND_DIRECTLY_CONFIGURE_DOCKER:
containerConfig := &container.Config{
Expand Down
10 changes: 5 additions & 5 deletions grass.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func (i *GrassConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (
switch kind {
case KIND_DOCKER_COMPOSE:
return `grass:
image: ` + GRASS_IMAGE_NAME + `
environment:
- GRASS_USER=` + i.Email + `
- GRASS_PASS=` + i.Password + `
restart: unless-stopped
image: ` + GRASS_IMAGE_NAME + `
environment:
- GRASS_USER=` + i.Email + `
- GRASS_PASS=` + i.Password + `
restart: unless-stopped
`, nil
case KIND_DIRECTLY_CONFIGURE_DOCKER:
containerConfig := &container.Config{
Expand Down
10 changes: 5 additions & 5 deletions honeygain.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func (i *HoneygainConfig) ConfigureDocker(kind DockerConfigKind, form *tview.For
switch kind {
case KIND_DOCKER_COMPOSE:
return `honeygain:
image: ` + HONEYGAIN_IMAGE_NAME + `
restart: unless-stopped
environment:
- HONEYGAIN_DUMMY=''
command: -tou-accept -email ` + i.Email + ` -pass ` + i.Password + ` -device ` + i.DeviceName + "\n", nil
image: ` + HONEYGAIN_IMAGE_NAME + `
restart: unless-stopped
environment:
- HONEYGAIN_DUMMY=''
command: -tou-accept -email ` + i.Email + ` -pass ` + i.Password + ` -device ` + i.DeviceName + "\n", nil
case KIND_DIRECTLY_CONFIGURE_DOCKER:
hostConfig := &container.HostConfig{
RestartPolicy: container.RestartPolicy{
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ func main() {
form.AddTextView("Success", "Copied to clipboard", 0, 1, true, false)
}
})
form.AddButton("Save to File", func() {
if err := saveToFile("compose.yml", dockerComposeFile); err != nil {
form.AddTextView("Error", "Failed to save to file", 0, 1, true, false)
} else {
form.AddTextView("Success", "Saved to file", 0, 1, true, false)
}
})
form.AddButton("Return", func() {
returnToMenu(mainFrame, app)
})
Expand Down
24 changes: 12 additions & 12 deletions mystnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ func (i *MystConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (s
switch kind {
case KIND_DOCKER_COMPOSE:
return `myst:
image: ` + MYST_IMAGE_NAME + `
environment:
- MYSTNODE_DUMMY=''
command: service --agreed-terms-and-conditions
network_mode: host
cap_add:
- NET_ADMIN
ports:
- "4449:4449"
volumes:
- myst-data:/var/lib/mysterium-node
restart: unless-stopped
image: ` + MYST_IMAGE_NAME + `
environment:
- MYSTNODE_DUMMY=''
command: service --agreed-terms-and-conditions
network_mode: host
cap_add:
- NET_ADMIN
ports:
- "4449:4449"
volumes:
- myst-data:/var/lib/mysterium-node
restart: unless-stopped
`, nil
case KIND_DIRECTLY_CONFIGURE_DOCKER:
containerConfig := &container.Config{
Expand Down
8 changes: 4 additions & 4 deletions packetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func (i *PacketStreamConfig) ConfigureDocker(kind DockerConfigKind, form *tview.
switch kind {
case KIND_DOCKER_COMPOSE:
return `packetstream:
image: ` + PACKETSTREAM_IMAGE_NAME + `
environment:
- CID=` + i.CID + `
restart: unless-stopped
image: ` + PACKETSTREAM_IMAGE_NAME + `
environment:
- CID=` + i.CID + `
restart: unless-stopped
`, nil
case KIND_DIRECTLY_CONFIGURE_DOCKER:
containerConfig := &container.Config{
Expand Down
10 changes: 5 additions & 5 deletions pawnsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func (i *PawnsAppConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form
switch kind {
case KIND_DOCKER_COMPOSE:
return `pawnsapp:
image: ` + PAWNSAPP_IMAGE_NAME + `
environment:
- IPROYALPAWNS_DUMMY=''
command: -accept-tos -email=` + i.Email + ` -password=` + i.Password + ` -device-name=` + i.DeviceName + ` -device-id=id_` + i.DeviceName + `
restart: unless-stopped
image: ` + PAWNSAPP_IMAGE_NAME + `
environment:
- IPROYALPAWNS_DUMMY=''
command: -accept-tos -email=` + i.Email + ` -password=` + i.Password + ` -device-name=` + i.DeviceName + ` -device-id=id_` + i.DeviceName + `
restart: unless-stopped
`, nil
case KIND_DIRECTLY_CONFIGURE_DOCKER:
containerConfig := &container.Config{
Expand Down
20 changes: 10 additions & 10 deletions peer2profit.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ func (i *Peer2ProfitConfig) ConfigureDocker(kind DockerConfigKind, form *tview.F
switch kind {
case KIND_DOCKER_COMPOSE:
compose := `peer2profit:
image: ` + PEER2PROFIT_IMAGE_NAME + `
environment:
- email=` + i.Email + `
- use_proxy=false
restart: unless-stopped
platform: linux/amd64
image: ` + PEER2PROFIT_IMAGE_NAME + `
environment:
- email=` + i.Email + `
- use_proxy=false
restart: unless-stopped
platform: linux/amd64
`
if runtime.GOARCH == "arm64" {
return compose + `binfmt:
image: tonistiigi/binfmt:latest
privileged: true
command: --install all
restart: unless-stopped
image: tonistiigi/binfmt:latest
privileged: true
command: --install all
restart: unless-stopped
`, nil
}
return compose, nil
Expand Down
16 changes: 16 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/md5"
"fmt"
"math/rand"
"os"
"time"
)

Expand All @@ -25,3 +26,18 @@ func randomString(length int) string {
func generateEarnAppUUID() string {
return fmt.Sprintf("sdk-node-%x", md5.Sum([]byte(randomString(32))))
}

func saveToFile(filename, data string) error {
file, err := os.Create(filename)
if err != nil {
return err
}
defer file.Close()

_, err = file.WriteString(data)
if err != nil {
return err
}

return nil
}
8 changes: 4 additions & 4 deletions watchtower.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func (i *WatchtowerConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Fo
switch kind {
case KIND_DOCKER_COMPOSE:
return `watchtower:
image: ` + WATCHTOWER_IMAGE_NAME + `
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: always
image: ` + WATCHTOWER_IMAGE_NAME + `
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: always
`, nil
case KIND_DIRECTLY_CONFIGURE_DOCKER:
containerConfig := &container.Config{
Expand Down

0 comments on commit 9577a93

Please sign in to comment.