Skip to content

Commit

Permalink
Update to use new CDN structure
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRalex committed Oct 30, 2023
1 parent 61c393a commit f8ad87a
Show file tree
Hide file tree
Showing 8 changed files with 862 additions and 87 deletions.
31 changes: 0 additions & 31 deletions 404.html

This file was deleted.

6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ FROM golang:alpine AS builder
WORKDIR /build
COPY ./main.go ./main.go

RUN go build -o dswrap ./main.go
RUN go build -o dswrap github.com/minecrafthopper/dswrap

FROM alpine

WORKDIR /dswrap

COPY --from=builder /build/dswrap /dswrap/dswrap
COPY ./404.html ./paste.html /dswrap/

ENV DISCORD_TOKEN="" \
DISCORD_TOKEN_FILE=""

EXPOSE 8080

Expand Down
20 changes: 16 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
version: "3.4"
version: "3.7"
services:
updatejson:
image: ghcr.io/minecrafthopper/dswrap
restart: always
networks:
- default
- ingress_default
environment:
DISCORD_TOKEN_FILE: "/run/secrets/discord_token"
secrets:
- discord_token
deploy:
placement:
constraints:
- "node.role==manager"
labels:
- "traefik.enable=true"
- "traefik.http.routers.dswrap.rule=Host(`${HOST}`)"
- "traefik.http.routers.dswrap.entrypoints=websecure"
- "traefik.http.routers.dswrap.tls.certresolver=myresolver"
- "traefik.http.services.dswrap.loadbalancer.server.port=8080"
logging:
driver: "json-file"
options:
max-size: "100M"
max-file: "5"


networks:
ingress_default:
external: true

secrets:
discord_token:
name: absol_discord_token
external: true
87 changes: 87 additions & 0 deletions env/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package env

import (
"github.com/spf13/cast"
"github.com/spf13/viper"
"io"
"log"
"os"
"strings"
)

var cache = make(map[string]string)

func init() {
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
}

func Get(key string) string {
val, exists := cache[key]
if exists {
return val
}

filename := viper.GetString(key + ".file")
if filename == "" {
return viper.GetString(key)
}
val, err := readSecret(filename)
if err != nil {
log.Printf("error reading secret: %s", err.Error())
}
//update cache with the full value, so we don't constantly read it
cache[key] = val
return val
}

func Set(key string, val string) {
cache[key] = val
}

func GetOr(key string, def string) string {
res := Get(key)
if res == "" {
return def
}
return res
}

func GetBool(key string) bool {
return GetBoolOr(key, false)
}

func GetBoolOr(key string, def bool) bool {
res := Get(key)
if res == "" {
return def
}
return cast.ToBool(res)
}

func GetInt(key string) int {
return cast.ToInt(Get(key))
}

func GetStringArray(key, separator string) []string {
val := Get(key)
if separator == "" {
separator = ","
}
return strings.Split(val, separator)
}

func readSecret(file string) (string, error) {
f, err := os.Open(file)
if err != nil {
return "", err
}
defer f.Close()

data, err := io.ReadAll(f)
if err != nil {
return "", err
}

return strings.TrimSpace(string(data)), nil
}
50 changes: 50 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module github.com/minecrafthopper/dswrap

go 1.21.0

require (
github.com/spf13/cast v1.5.1
github.com/spf13/viper v1.17.0
)

require (
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit f8ad87a

Please sign in to comment.