automated setup
This commit is contained in:
parent
280f09d287
commit
dfd57bd581
|
@ -0,0 +1,13 @@
|
||||||
|
FROM xena/go:1.13.5 AS build
|
||||||
|
WORKDIR /mi
|
||||||
|
COPY go.mod .
|
||||||
|
COPY go.sum .
|
||||||
|
RUN go mod download
|
||||||
|
COPY . .
|
||||||
|
RUN GOBIN=/mi/bin go install ./cmd/...
|
||||||
|
|
||||||
|
FROM xena/alpine
|
||||||
|
COPY --from=build /mi/bin /usr/local/bin
|
||||||
|
COPY ./run /run
|
||||||
|
RUN mkdir -p /mi
|
||||||
|
CMD ["/bin/sh", "/run/start.sh"]
|
|
@ -0,0 +1,55 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/facebookgo/flagenv"
|
||||||
|
"github.com/hashicorp/go-multierror"
|
||||||
|
_ "github.com/joho/godotenv/autoload"
|
||||||
|
r "gopkg.in/rethinkdb/rethinkdb-go.v6"
|
||||||
|
"within.website/mi/rethink"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
rethinkDBURL = flag.String("rethinkdb-url", "rethinkdb2://admin@127.0.0.1:28015/mi", "RethinkDB URL")
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flagenv.Parse()
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
session, err := rethink.GetSession(*rethinkDBURL)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = r.DB("mi").Info().Exec(session)
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.DBCreate("mi").Exec(session); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tables := []string{
|
||||||
|
"mastodon",
|
||||||
|
"blogposts",
|
||||||
|
"reddit_comments",
|
||||||
|
"reddit_posts",
|
||||||
|
"twitter",
|
||||||
|
}
|
||||||
|
|
||||||
|
var result error
|
||||||
|
|
||||||
|
for _, tbl := range tables {
|
||||||
|
if err := r.DB("mi").TableCreate(tbl).Exec(session); err != nil {
|
||||||
|
result = multierror.Append(result, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if result != nil {
|
||||||
|
log.Fatal(result)
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,16 +5,15 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/facebookarchive/flagenv"
|
"github.com/facebookarchive/flagenv"
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
r "gopkg.in/rethinkdb/rethinkdb-go.v6"
|
|
||||||
"within.website/ln"
|
"within.website/ln"
|
||||||
"within.website/ln/ex"
|
"within.website/ln/ex"
|
||||||
|
"within.website/mi/rethink"
|
||||||
"within.website/x/web/useragent"
|
"within.website/x/web/useragent"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,9 +30,6 @@ var (
|
||||||
// RethinkDB
|
// RethinkDB
|
||||||
rethinkDBURL = flag.String("rethinkdb-url", "rethinkdb2://admin@127.0.0.1:28015/mi", "RethinkDB URL")
|
rethinkDBURL = flag.String("rethinkdb-url", "rethinkdb2://admin@127.0.0.1:28015/mi", "RethinkDB URL")
|
||||||
|
|
||||||
// Blog
|
|
||||||
blogURL = flag.String("blog-url", "https://christine.website/blog.json", "JSONFeed to monitor for new posts")
|
|
||||||
|
|
||||||
// Port
|
// Port
|
||||||
port = flag.String("port", "5000", "HTTP port")
|
port = flag.String("port", "5000", "HTTP port")
|
||||||
domain = flag.String("domain", "mi.within.website", "domain this is being served on")
|
domain = flag.String("domain", "mi.within.website", "domain this is being served on")
|
||||||
|
@ -43,29 +39,11 @@ func main() {
|
||||||
flagenv.Parse()
|
flagenv.Parse()
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
http.DefaultTransport = useragent.Transport("mi-posse", "https://" + *domain + "/.within/botinfo", http.DefaultTransport)
|
http.DefaultTransport = useragent.Transport("mi-posse", "https://"+*domain+"/.within/botinfo", http.DefaultTransport)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
r.SetTags("rethinkdb", "json")
|
session, err := rethink.GetSession(*rethinkDBURL)
|
||||||
|
|
||||||
u, err := url.Parse(*rethinkDBURL)
|
|
||||||
if err != nil {
|
|
||||||
ln.FatalErr(ctx, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pw, _ := u.User.Password()
|
|
||||||
db := u.Path[1:]
|
|
||||||
|
|
||||||
session, err := r.Connect(r.ConnectOpts{
|
|
||||||
Address: u.Host,
|
|
||||||
Database: db,
|
|
||||||
Username: u.User.Username(),
|
|
||||||
Password: pw,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ln.FatalErr(ctx, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mastodonClient, err := makeMastodon()
|
mastodonClient, err := makeMastodon()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -82,6 +60,11 @@ func main() {
|
||||||
ln.FatalErr(ctx, err)
|
ln.FatalErr(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patreonClient, err := makePatreon()
|
||||||
|
if err != nil {
|
||||||
|
ln.FatalErr(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
pm, err := MakeMiddleware(*pasetoPublicKey, *pasetoPrivateKey, mux)
|
pm, err := MakeMiddleware(*pasetoPublicKey, *pasetoPrivateKey, mux)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -104,6 +87,7 @@ func main() {
|
||||||
session: session,
|
session: session,
|
||||||
mastodonClient: mastodonClient,
|
mastodonClient: mastodonClient,
|
||||||
twitterClient: twitterClient,
|
twitterClient: twitterClient,
|
||||||
|
patreonClient: patreonClient,
|
||||||
redditBot: redditBot,
|
redditBot: redditBot,
|
||||||
mux: mux,
|
mux: mux,
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,8 +83,9 @@ type MastodonStatus struct {
|
||||||
Account struct {
|
Account struct {
|
||||||
Acct string `json:"acct"`
|
Acct string `json:"acct"`
|
||||||
} `json:"account"`
|
} `json:"account"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
|
Sensitive bool `json:"sensitive"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NewStatus struct {
|
type NewStatus struct {
|
||||||
|
@ -128,6 +129,10 @@ func (mi *Mi) StreamMastodonToTwitter(ctx context.Context) {
|
||||||
}
|
}
|
||||||
st := ns.NewVal
|
st := ns.NewVal
|
||||||
|
|
||||||
|
if st.Sensitive {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if st.Account.Acct != *mastodonAccount {
|
if st.Account.Acct != *mastodonAccount {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
version: '3.7'
|
||||||
|
|
||||||
|
services:
|
||||||
|
mi:
|
||||||
|
restart: always
|
||||||
|
build: .
|
||||||
|
env_file: .env
|
||||||
|
depends_on: rethinkdb
|
||||||
|
ports: "127.0.0.1:39243:5000"
|
||||||
|
|
||||||
|
rethinkdb:
|
||||||
|
image: "rethinkdb:2.4.0"
|
||||||
|
volumes:
|
||||||
|
- "rethink-data:/data"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
rethink-data:
|
|
@ -0,0 +1,31 @@
|
||||||
|
package rethink
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/url"
|
||||||
|
|
||||||
|
r "gopkg.in/rethinkdb/rethinkdb-go.v6"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetSession(dbURL string) (*r.Session, error) {
|
||||||
|
r.SetTags("rethinkdb", "json")
|
||||||
|
|
||||||
|
u, err := url.Parse(dbURL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pw, _ := u.User.Password()
|
||||||
|
db := u.Path[1:]
|
||||||
|
|
||||||
|
session, err := r.Connect(r.ConnectOpts{
|
||||||
|
Address: u.Host,
|
||||||
|
Database: db,
|
||||||
|
Username: u.User.Username(),
|
||||||
|
Password: pw,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return session, nil
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
mi-init
|
||||||
|
mi
|
Loading…
Reference in New Issue