From 66bbd2b5e9b4bd891f9c940d6bbfc5f6517ca7fe Mon Sep 17 00:00:00 2001 From: slhmy Date: Sun, 14 Jan 2024 18:40:09 +0800 Subject: [PATCH] Fix docker --- .dockerignore | 7 ++----- docker/oj-lab-platform.dockerfile | 9 --------- environment/configs/production.toml | 2 +- src/core/agent/redis/client.go | 19 +++++++++++++++++-- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.dockerignore b/.dockerignore index 9a8b25e..ab3d0b2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,4 @@ .github/ .vscode/ -test/ -test-collection/ -frontend/ -postman/ -oj-lab-services-structure.drawio \ No newline at end of file +tests/ +artifacts/ \ No newline at end of file diff --git a/docker/oj-lab-platform.dockerfile b/docker/oj-lab-platform.dockerfile index a1fadd4..6660c3c 100644 --- a/docker/oj-lab-platform.dockerfile +++ b/docker/oj-lab-platform.dockerfile @@ -1,6 +1,5 @@ FROM golang:latest as build -RUN mkdir /oj-lab-platform-build WORKDIR /oj-lab-platform-build COPY go.mod /oj-lab-platform-build/go.mod @@ -19,21 +18,13 @@ RUN make get-front FROM ubuntu:latest -RUN apt update && apt install -y make - -RUN mkdir /workspace WORKDIR /workspace COPY --from=build /oj-lab-platform-build/artifacts/bin/service /usr/local/bin/oj-lab-service -COPY --from=build /oj-lab-platform-build/artifacts/bin/asynq_worker /usr/local/bin/asynq_worker - COPY --from=build /oj-lab-platform-build/artifacts/oj-lab-front /workspace/artifacts/oj-lab-front COPY environment/configs/production.toml /workspace/environment/configs/production.toml -COPY Makefile /workspace/Makefile -COPY scripts/ /workspace/scripts/ - ENV OJ_LAB_SERVICE_ENV=production ENV OJ_LAB_PROJECT_ROOT=workspace EXPOSE 8080 diff --git a/environment/configs/production.toml b/environment/configs/production.toml index 927f60f..7ab693a 100644 --- a/environment/configs/production.toml +++ b/environment/configs/production.toml @@ -5,7 +5,7 @@ level = "debug" dsn = "user=postgres password=development host=host.docker.internal port=5432 dbname=oj_lab sslmode=disable TimeZone=Asia/Shanghai" [redis] -host = "localhost:6379" +host = "host.docker.internal:6379" [jwt] secret = "example_secret" diff --git a/src/core/agent/redis/client.go b/src/core/agent/redis/client.go index 979b29c..68d37df 100644 --- a/src/core/agent/redis/client.go +++ b/src/core/agent/redis/client.go @@ -1,13 +1,28 @@ package redisAgent -import "github.com/redis/go-redis/v9" +import ( + "github.com/OJ-lab/oj-lab-services/src/core" + "github.com/redis/go-redis/v9" +) + +const ( + redisHostProp = "redis.host" +) + +var ( + redisHost string +) + +func init() { + redisHost = core.AppConfig.GetString(redisHostProp) +} var redisClient *redis.Client func GetDefaultRedisClient() *redis.Client { if redisClient == nil { redisClient = redis.NewClient(&redis.Options{ - Addr: "localhost:6379", + Addr: redisHost, }) } return redisClient