Skip to content

Commit 362be15

Browse files
committed
refactor(queue): switch from rabbitmq to lavinmq
1 parent 7ed9880 commit 362be15

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

internal/assets/docker-compose.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,36 @@ services:
3939

4040
runtipi-queue:
4141
container_name: runtipi-queue
42-
image: rabbitmq:4-alpine
42+
image: cloudamqp/lavinmq
43+
healthcheck:
44+
test: ["CMD-SHELL", "lavinmqctl status"]
45+
interval: 5s
46+
timeout: 10s
47+
retries: 20
48+
start_period: 5s
4349
restart: unless-stopped
50+
volumes:
51+
- ./lavinmq.ini:/etc/lavinmq/lavinmq.ini
4452
ports:
4553
- 5672:5672
46-
environment:
47-
RABBITMQ_DEFAULT_USER: tipi
48-
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD}
4954
networks:
5055
- tipi_main_network
5156

5257
runtipi:
5358
container_name: runtipi
5459
healthcheck:
55-
start_period: 10s
5660
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
5761
interval: 5s
5862
timeout: 10s
5963
retries: 20
64+
start_period: 10s
6065
image: ghcr.io/runtipi/runtipi:${TIPI_VERSION}
6166
restart: unless-stopped
6267
depends_on:
6368
runtipi-db:
6469
condition: service_healthy
6570
runtipi-queue:
66-
condition: service_started
71+
condition: service_healthy
6772
env_file:
6873
- .env
6974
volumes:

internal/utils/env.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ func GenerateEnvFile(customEnvFile string) error {
131131
rabbitmqPassword = DeriveEntropy("rabbitmq_password", seed)
132132
}
133133

134+
hashedPassword, err := HashPassword(rabbitmqPassword)
135+
if err != nil {
136+
return fmt.Errorf("failed to hash rabbitmq password: %w", err)
137+
}
138+
139+
lavinmqIniPath := filepath.Join(config.RootFolder, "lavinmq.ini")
140+
lavinmqIniContent := fmt.Sprintf("[main]\ndefault_user = tipi\ndefault_password = %s\n", hashedPassword)
141+
if err := os.WriteFile(lavinmqIniPath, []byte(lavinmqIniContent), 0644); err != nil {
142+
return fmt.Errorf("failed to write lavinmq.ini: %w", err)
143+
}
144+
134145
// Handle app data path
135146
appDataPath := settings.AppDataPath
136147
if appDataPath == "" {

internal/utils/system_info.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package utils
22

33
import (
4+
"crypto/rand"
45
"crypto/sha256"
6+
"encoding/base64"
57
"encoding/hex"
68
"net"
79
"os"
@@ -34,3 +36,21 @@ func DeriveEntropy(key, seed string) string {
3436
hash := sha256.Sum256([]byte(key + seed))
3537
return hex.EncodeToString(hash[:])[:32]
3638
}
39+
40+
func HashPassword(password string) (string, error) {
41+
salt := make([]byte, 4)
42+
_, err := rand.Read(salt)
43+
if err != nil {
44+
return "", err
45+
}
46+
47+
salted := append(salt, []byte(password)...)
48+
49+
hash := sha256.Sum256(salted)
50+
51+
final := append(salt, hash[:]...)
52+
53+
encoded := base64.StdEncoding.EncodeToString(final)
54+
55+
return encoded, nil
56+
}

0 commit comments

Comments
 (0)