Skip to content
This repository has been archived by the owner on Feb 14, 2021. It is now read-only.

Commit

Permalink
Dockerized osrs.cx bot; includes Dockerfile and docker-compose.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
notmeta committed Jul 7, 2019
1 parent 6a7b093 commit b0a4772
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
23 changes: 23 additions & 0 deletions Dockerfile
@@ -0,0 +1,23 @@
# builder
FROM golang:1.12 as builder

RUN mkdir /osrscx
WORKDIR /osrscx

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o /go/bin/osrscx

# runner
FROM alpine:latest

LABEL maintainer="Corey (notmeta) <https://github.com/notmeta/>"

RUN apk --no-cache add ca-certificates bash
COPY --from=builder /go/bin/osrscx /go/bin/osrscx

ENTRYPOINT ["/go/bin/osrscx"]
16 changes: 16 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,16 @@
version: "3.7"
services:
redis_db:
image: redis
command: redis-server --appendonly yes
ports:
- "127.0.0.1:6379:6379"
volumes:
- /docker/redis-data:/data
bot:
build: .
links:
- redis_db
environment:
# - DG_TOKEN=
- REDIS_IP=redis_db
4 changes: 4 additions & 0 deletions main.go
Expand Up @@ -27,6 +27,10 @@ func init() {
if Session.Token == "" {
flag.StringVar(&Session.Token, "t", "", "Discord Authentication Token")
}
util.RedisIp = os.Getenv("REDIS_IP")
if util.RedisIp == "" {
flag.StringVar(&util.RedisIp, "redis", "localhost", "Redis Store IP Address")
}
}

func main() {
Expand Down
21 changes: 19 additions & 2 deletions util/store.go
Expand Up @@ -5,19 +5,36 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/go-redis/redis"
"log"
"time"
)

var Store *redis.Client
var RedisIp string

const RsnKeyFormat = "rsn:%s"

func StoreInit() {
Store = redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Addr: RedisIp + ":6379",
Password: "",
DB: 0,
})
_, err := Store.Ping().Result()

var err error
pingAttempts := 0

for pingAttempts < 5 {
_, err = Store.Ping().Result()

if err != nil {
log.Printf("Ping failed, waiting and trying again")
pingAttempts += 1
time.Sleep(5 * time.Second)
} else {
break
}
}

if err != nil {
log.Fatalf("Failed to connect to local redis container!\n%s", err)
} else {
Expand Down

0 comments on commit b0a4772

Please sign in to comment.