Skip to content

Commit

Permalink
Merge pull request #285 from COS301-SE-2024/chore/backend/fixing-quir…
Browse files Browse the repository at this point in the history
…ks-and-gotchas

chore: 🫨Stabilising backend with addition of centrifugo
  • Loading branch information
waveyboym authored Aug 7, 2024
2 parents f0dd515 + 58b23c3 commit 871e74f
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 113 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/deploy-golang-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ jobs:
- name: ⬇️ Checkout code
uses: actions/checkout@v4

- name: 🔓 Decrypt Centrifugo config
run: |
echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --quiet --batch --yes --decrypt --passphrase-fd 0 configs/centrifugo.config.json.gpg > configs/centrifugo.config.json
- name: 🪷 Copy files to VM
uses: appleboy/scp-action@v0.1.5
with:
host: ${{ secrets.VM_IP }}
username: ${{ secrets.VM_USERNAME }}
key: ${{ secrets.VM_SSH_KEY }}
source: "occupi-backend/docker-compose.dev.yml,occupi-backend/Dockerfile.dev"
source: "occupi-backend/docker-compose.dev.yml,occupi-backend/Dockerfile.dev,occupi-backend/configs/centrifugo.config.json"
target: "/home/${{ secrets.VM_USERNAME }}/occupi-backend-dev"

# SSH to VM and run commands
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/deploy-golang-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,18 @@ jobs:
- name: ⬇️ Checkout code
uses: actions/checkout@v4

- name: 🔓 Decrypt Centrifugo config
run: |
echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --quiet --batch --yes --decrypt --passphrase-fd 0 configs/centrifugo.config.json.gpg > configs/centrifugo.config.json
- name: 🪷 Copy files to VM
uses: appleboy/scp-action@v0.1.5
with:
host: ${{ secrets.VM_IP }}
username: ${{ secrets.VM_USERNAME }}
key: ${{ secrets.VM_SSH_KEY }}
source: "occupi-backend/docker-compose.prod.yml,occupi-backend/Dockerfile.prod"
source: "occupi-backend/docker-compose.prod.yml,occupi-backend/Dockerfile.prod,occupi-backend/configs/centrifugo.config.json"
target: "/home/${{ secrets.VM_USERNAME }}/occupi-backend-prod"

# SSH to VM and run commands
Expand Down
Binary file added occupi-backend/configs/centrifugo.config.json.gpg
Binary file not shown.
35 changes: 27 additions & 8 deletions occupi-backend/configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ const (
RPID = "RP_ID"
RPName = "RP_NAME"
RPOrigins = "RP_ORIGINS"
Centrifugo = "CENTRIFUGO_API_KEY"
CentrifugoAKy = "CENTRIFUGO_API_KEY"
CentrifugoHost = "CENTRIFUGO_HOST"
CentrifugoPort = "CENTRIFUGO_PORT"
)

// init viper
Expand Down Expand Up @@ -157,13 +159,6 @@ func GetSMTPPort() int {
}
return portInt
}
func GetCentrifugoAPIKey() string {
key := viper.GetString(Centrifugo)
if key == "" {
key = "CENTRIFUGO_API_KEY"
}
return key
}

// gets the smtp password as defined in the config.yaml file
func GetSMTPPassword() string {
Expand Down Expand Up @@ -414,3 +409,27 @@ func GetRPOrigins() []string {
}
return []string{}
}

func GetCentrifugoAPIKey() string {
key := viper.GetString(CentrifugoAKy)
if key == "" {
key = "CENTRIFUGO_API_KEY"
}
return key
}

func GetCentrifugoHost() string {
host := viper.GetString(CentrifugoHost)
if host == "" {
host = "CENTRIFUGO_HOST"
}
return host
}

func GetCentrifugoPort() string {
port := viper.GetString(CentrifugoPort)
if port == "" {
port = "CENTRIFUGO_PORT"
}
return port
}
Binary file modified occupi-backend/configs/config.yaml.gpg
Binary file not shown.
Binary file modified occupi-backend/configs/dev.deployed.yaml.gpg
Binary file not shown.
Binary file modified occupi-backend/configs/dev.localhost.yaml.gpg
Binary file not shown.
Binary file modified occupi-backend/configs/prod.yaml.gpg
Binary file not shown.
20 changes: 20 additions & 0 deletions occupi-backend/configs/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/allegro/bigcache/v3"
"github.com/centrifugal/gocent/v3"
"github.com/go-webauthn/webauthn/webauthn"
"github.com/ipinfo/go/v2/ipinfo"
"github.com/ipinfo/go/v2/ipinfo/cache"
Expand Down Expand Up @@ -226,3 +227,22 @@ func CreateWebAuthnInstance() *webauthn.WebAuthn {

return webAuthn
}

func CreateCentrifugoClient() *gocent.Client {
// Centrifugo connection parameters
centrifugoHost := GetCentrifugoHost()
centrifugoPort := GetCentrifugoPort()
centrifugoAPIKey := GetCentrifugoAPIKey()

centrifugoAddr := fmt.Sprintf("http://%s:%s/api", centrifugoHost, centrifugoPort)

// Create a new Centrifugo client
client := gocent.New(gocent.Config{
Addr: centrifugoAddr,
Key: centrifugoAPIKey,
})

fmt.Println("Centrifugo client created!")

return client
}
Binary file modified occupi-backend/configs/test.yaml.gpg
Binary file not shown.
37 changes: 16 additions & 21 deletions occupi-backend/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ services:
depends_on:
rabbitmq-dev:
condition: service_healthy
# centrifugo-dev:
# condition: service_healthy
centrifugo-dev:
condition: service_started

rabbitmq-dev:
image: rabbitmq:latest
Expand All @@ -42,28 +42,23 @@ services:
timeout: 30s
retries: 3

# centrifugo-dev:
# image: centrifugo/centrifugo:v5
# container_name: centrifugo-dev
# volumes:
# - ./configs/config.json:/centrifugo/config.json
# - centrifugo-dev:/centrifugo/data
# command: centrifugo -c config.json --health
# ports:
# - 8001:8000
# ulimits:
# nofile:
# soft: 262144
# hard: 262144
# healthcheck:
# test: curl -f http://localhost:8001/health
# interval: 30s
# timeout: 10s
# retries: 5
centrifugo-dev:
image: centrifugo/centrifugo:v5
container_name: centrifugo-dev
volumes:
- ./configs/centrifugo.config.json:/centrifugo/centrifugo.config.json
- centrifugo-dev:/centrifugo/data
command: centrifugo -c centrifugo.config.json
ports:
- 8001:8000
ulimits:
nofile:
soft: 262144
hard: 262144

volumes:
rabbitmq-dev:
# centrifugo-dev:
centrifugo-dev:

networks:
webnet:
Expand Down
33 changes: 14 additions & 19 deletions occupi-backend/docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,20 @@ services:
volumes:
- rabbitmq-dev-local-local:/var/lib/rabbitmq

# centrifugo-dev-local-local:
# image: centrifugo/centrifugo:v5
# container_name: centrifugo-dev-local-local
# volumes:
# - ./configs/config.json:/centrifugo/config.json
# - centrifugo-dev-local-local:/centrifugo/data
# command: centrifugo -c config.json --health
# ports:
# - 8001:8000
# ulimits:
# nofile:
# soft: 262144
# hard: 262144
# healthcheck:
# test: curl -f http://localhost:8001/health
# interval: 30s
# timeout: 10s
# retries: 5
centrifugo-dev-local-local:
image: centrifugo/centrifugo:v5
container_name: centrifugo-dev-local-local
volumes:
- ./configs/centrifugo.config.json:/centrifugo/centrifugo.config.json
- centrifugo-dev-local-local:/centrifugo/data
command: centrifugo -c centrifugo.config.json
ports:
- 8001:8000
ulimits:
nofile:
soft: 262144
hard: 262144

volumes:
rabbitmq-dev-local-local:
# centrifugo-dev-local-local:
centrifugo-dev-local-local:
37 changes: 16 additions & 21 deletions occupi-backend/docker-compose.localdev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ services:
- "8081:8081"
restart: on-failure:5
depends_on:
centrifugo-dev-local:
condition: service_healthy
rabbitmq-dev-local:
condition: service_healthy
centrifugo-dev-local:
condition: service_started

rabbitmq-dev-local:
image: rabbitmq:latest
Expand All @@ -30,25 +30,20 @@ services:
timeout: 30s
retries: 3

# centrifugo-dev-local:
# image: centrifugo/centrifugo:v5
# container_name: centrifugo-dev-local
# volumes:
# - ./configs/config.json:/centrifugo/config.json
# - centrifugo-dev-local:/centrifugo/data
# command: centrifugo -c config.json --health
# ports:
# - 8001:8000
# ulimits:
# nofile:
# soft: 262144
# hard: 262144
# healthcheck:
# test: curl -f http://localhost:8001/health
# interval: 30s
# timeout: 10s
# retries: 5
centrifugo-dev-local:
image: centrifugo/centrifugo:v5
container_name: centrifugo-dev-local
volumes:
- ./configs/centrifugo.config.json:/centrifugo/centrifugo.config.json
- centrifugo-dev-local:/centrifugo/data
command: centrifugo -c centrifugo.config.json
ports:
- 8000:8000
ulimits:
nofile:
soft: 262144
hard: 262144

volumes:
rabbitmq-dev-local:
# centrifugo-dev-local:
centrifugo-dev-local:
35 changes: 16 additions & 19 deletions occupi-backend/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ services:
depends_on:
rabbitmq-prod:
condition: service_healthy
centrifugo-prod:
condition: service_started

rabbitmq-prod:
image: rabbitmq:latest
Expand All @@ -40,28 +42,23 @@ services:
timeout: 30s
retries: 3

# centrifugo-prod:
# image: centrifugo/centrifugo:v5
# container_name: centrifugo-prod
# volumes:
# - ./configs/config.json:/centrifugo/config.json
# - centrifugo-prod:/centrifugo/data
# command: centrifugo -c config.json --health
# ports:
# - 8001:8000
# ulimits:
# nofile:
# soft: 262144
# hard: 262144
# healthcheck:
# test: curl -f http://localhost:8001/health
# interval: 30s
# timeout: 10s
# retries: 5
centrifugo-prod:
image: centrifugo/centrifugo:v5
container_name: centrifugo-prod
volumes:
- ./configs/centrifugo.config.json:/centrifugo/centrifugo.config.json
- centrifugo-prod:/centrifugo/data
command: centrifugo -c centrifugo.config.json --health
ports:
- 8000:8000
ulimits:
nofile:
soft: 262144
hard: 262144

volumes:
mongo-prod:
rabbitmq-prod:
centrifugo-prod:

networks:
webnet:
Expand Down
Loading

0 comments on commit 871e74f

Please sign in to comment.