diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..1c15be5 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,30 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Log in to Docker registry + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Build Docker image + run: | + docker build -t gabehf/koito-multi-proxy:latest . + + - name: Push Docker image + run: | + docker push gabehf/koito-multi-proxy:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cc5e67e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Stage 1: Build Go binary using lightweight Alpine +FROM golang:1.24-alpine AS builder + +# Set workdir +WORKDIR /app + +# Copy go.mod/go.sum and download dependencies +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source code +COPY . . + +# Build Go binary +RUN GOOS=linux go build -o koito-multi-proxy . + +# Stage 2: Runtime on Ubuntu 24.04 +FROM ubuntu:24.04 + +# Avoid interactive prompts during apt installs +ENV DEBIAN_FRONTEND=noninteractive + +# Copy Go binary from builder stage +COPY --from=builder /app/koito-multi-proxy /usr/local/bin/koito-multi-proxy + +# Entrypoint +ENTRYPOINT ["koito-multi-proxy"] diff --git a/main.go b/main.go index 97c29a9..191b18e 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "net/http/httputil" "net/url" "os" + "path" "strings" "gopkg.in/yaml.v3" @@ -24,7 +25,11 @@ var urlMap map[string]string func main() { // 1. Load and Parse Config - if err := loadConfig("config.yml"); err != nil { + cfgDir := os.Getenv("KMP_CONFIG_DIR") + if cfgDir == "" { + cfgDir = "/etc/kmp" + } + if err := loadConfig(path.Join(cfgDir, "config.yml")); err != nil { log.Fatalf("Failed to load configuration: %v", err) }