Skip to content

Commit

Permalink
Import transcode code. Reorganize code. (#4639)
Browse files Browse the repository at this point in the history
  • Loading branch information
stereosteve committed Jan 20, 2023
1 parent 9dc5c49 commit 311b88b
Show file tree
Hide file tree
Showing 97 changed files with 5,686 additions and 821 deletions.
4 changes: 0 additions & 4 deletions comms/.vscode/settings.json

This file was deleted.

2 changes: 2 additions & 0 deletions comms/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

FROM golang:latest

RUN apt update && apt install -y ffmpeg

# install in-container tools: dbmate, nats cli
RUN cd /tmp && \
curl -fsSL -o /usr/local/bin/dbmate https://github.com/amacneil/dbmate/releases/latest/download/dbmate-linux-amd64 && \
Expand Down
4 changes: 3 additions & 1 deletion comms/DockerfileFast
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

FROM golang:1.19

RUN apt update && apt install -y ffmpeg

# install in-container tools: dbmate, nats cli
RUN cd /tmp && \
curl -fsSL -o /usr/local/bin/dbmate https://github.com/amacneil/dbmate/releases/latest/download/dbmate-linux-amd64 && \
Expand All @@ -14,7 +16,7 @@ WORKDIR /app


COPY build/comms-linux-amd64 /comms-linux
COPY db/migrations ./db/migrations
COPY discovery/db/migrations ./discovery/db/migrations

EXPOSE 8925

Expand Down
19 changes: 11 additions & 8 deletions comms/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@

server::
dev.discovery::
@ audius_discprov_env='standalone' \
audius_delegate_private_key='293589cdf207ed2f2253bb72b17bb7f2cfe399cdc34712b1d32908d969682238' \
audius_db_url='postgresql://postgres:postgres@localhost:5454/audius_discovery?sslmode=disable' \
go run main.go
go run main.go discovery

dev.storage::
@ audius_discprov_env='standalone' \
go run main.go storage

reset::
docker compose down --volumes
docker compose up comdb -d
docker compose up comdb comnats -d
DATABASE_URL="postgresql://postgres:postgres@localhost:5454/audius_discovery?sslmode=disable" \
dbmate --wait up
dbmate --wait --migrations-dir ./discovery/db/migrations up
docker exec -it comdb psql -U postgres -c "create database comtest WITH TEMPLATE audius_discovery"

psql::
Expand Down Expand Up @@ -55,8 +58,8 @@ build::
# also... this is pretty much identical to doing a docker "multi-stage" build, but way simpler.
build.fast::
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/comms-linux-amd64
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker build . -f ./DockerfileFast -t audius/wip-comms:latest
docker push audius/wip-comms:latest
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker build . -f ./DockerfileFast -t audius/wip-comms:a1
docker push audius/wip-comms:a1


tools::
Expand All @@ -68,5 +71,5 @@ sqlc:: reset
sqlc generate

quicktype::
cp ../libs/src/sdk/api/chats/serverTypes.ts schema/schema.ts
npx quicktype --package schema --out schema/schema.go --just-types-and-package schema/*.ts
cp ../libs/src/sdk/api/chats/serverTypes.ts discovery/schema/schema.ts
npx quicktype --package schema --out discovery/schema/schema.go --just-types-and-package discovery/schema/*.ts
33 changes: 30 additions & 3 deletions comms/config/config.go → comms/discovery/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"os/exec"
"strings"

"github.com/ethereum/go-ethereum/crypto"
"github.com/inconshreveable/log15"
Expand All @@ -30,7 +31,8 @@ var (
NatsUseNkeys = true
NatsReplicaCount = 3

IsStaging = Env == "stage"
IsStaging = Env == "stage"
IsCreatorNode = false
)

func init() {
Expand All @@ -40,14 +42,23 @@ func init() {
func Init() {
var err error

// todo: hack for creator node config
if strings.Contains(os.Getenv("creatorNodeEndpoint"), "staging") {
Env = "stage"
IsStaging = true
}
if os.Getenv("delegateOwnerWallet") != "" {
IsCreatorNode = true
}

switch Env {
case "standalone":
envStandalone()
default:
Logger.Info("no env defaults for: " + Env)
}

privateKeyHex := os.Getenv("audius_delegate_private_key")
privateKeyHex := mgetenv("audius_delegate_private_key", "delegatePrivateKey")
if privateKeyHex == "" {
privateKeyHex = generatePrivateKeyHex()
Logger.Warn("audius_delegate_private_key not provided. Using randomly generated private key.")
Expand Down Expand Up @@ -104,7 +115,23 @@ func Init() {
NatsClusterUsername = signedHex[0:10]
NatsClusterPassword = signedHex[10:20]

Logger.Info("config", "wallet", WalletAddress, "nkey", NkeyPublic, "ip", IP, "nu", NatsClusterUsername, "np", NatsClusterPassword)
Logger.Info("config",
"env", Env,
"wallet", WalletAddress,
"nkey", NkeyPublic,
"ip", IP,
"nu", NatsClusterUsername,
"np", NatsClusterPassword)
}

func mgetenv(keys ...string) string {
for _, k := range keys {
v := os.Getenv(k)
if v != "" {
return v
}
}
return ""
}

func dieOnErr(err error) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion comms/db/conn.go → comms/discovery/db/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"strings"

"comms.audius.co/config"
"comms.audius.co/discovery/config"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package queries
import (
"context"

"comms.audius.co/db"
"comms.audius.co/discovery/db"
)

const chatBlock = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"database/sql"

"comms.audius.co/db"
"comms.audius.co/discovery/db"
)

type ChatMembershipParams struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"errors"
"time"

"comms.audius.co/db"
"comms.audius.co/discovery/db"
)

// Get a chat message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package queries
import (
"context"

"comms.audius.co/db"
"comms.audius.co/schema"
"comms.audius.co/discovery/db"
"comms.audius.co/discovery/schema"
)

const getChatPermissions = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"database/sql"
"time"

"comms.audius.co/db"
"comms.audius.co/discovery/db"
"github.com/jmoiron/sqlx"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package queries
import (
"context"

"comms.audius.co/db"
"comms.audius.co/discovery/db"
)

const countFollows = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

"comms.audius.co/db"
"comms.audius.co/discovery/db"
)

type SummaryRow struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package queries
import (
"context"

"comms.audius.co/db"
"comms.audius.co/discovery/db"
)

const countTips = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package queries
import (
"context"

"comms.audius.co/db"
"comms.audius.co/discovery/db"
)

const getUserIDFromWallet = `
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions comms/discovery/db/run_migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package db

import (
"fmt"
"os"
"os/exec"
)

func RunMigrations() error {
out, err := exec.Command("dbmate",
"--no-dump-schema",
"--migrations-dir", "./discovery/db/migrations",
"--url", os.Getenv("audius_db_url"),
"up").CombinedOutput()
fmt.Println("dbmate: ", string(out))
return err
}

0 comments on commit 311b88b

Please sign in to comment.