-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
230 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
FROM golang:latest as build | ||
|
||
COPY . /oj-lab-platform-build | ||
WORKDIR /workdir | ||
|
||
COPY . /workdir | ||
|
||
WORKDIR /oj-lab-platform-build | ||
RUN apt update && apt install -y make zip curl | ||
RUN make build | ||
RUN ./scripts/update-frontend-dist.sh /oj-lab-platform-build/frontend_dist | ||
RUN make get-front | ||
|
||
|
||
FROM ubuntu:latest | ||
|
||
WORKDIR /workdir | ||
WORKDIR /oj-lab-platform | ||
|
||
COPY --from=build /workdir/bin/web_server /usr/local/bin/web_server | ||
COPY --from=build /workdir/frontend/dist ./frontend_dist | ||
|
||
COPY --from=build /oj-lab-platform-build/bin/web_server /usr/local/bin/web_server | ||
COPY --from=build /oj-lab-platform-build/frontend_dist /workdir/frontend_dist | ||
COPY config.toml ./config.toml | ||
|
||
COPY workdirs/docker/config.toml /workdir/config.toml | ||
ENV OJ_LAB_SERVICE_ENV='production' | ||
ENV DATABASE_DSN='user=postgres password=postgres host=host.docker.internal port=5432 dbname=oj_lab sslmode=disable TimeZone=Asia/Shanghai' | ||
ENV REDIS_HOSTS='["host.docker.internal:6379"]' | ||
ENV MINIO_ENDPOINT='http://host.docker.internal:9000' | ||
|
||
ENV OJ_LAB_SERVICE_ENV=production | ||
ENV OJ_LAB_WORKDIR=/workdir | ||
EXPOSE 8080 | ||
CMD [ "web_server" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
OS := $(shell uname -s) | ||
|
||
DEV_WORKDIR := workdirs/development | ||
DB_DOCKER_COMPOSE_FILE := $(DEV_WORKDIR)/docker-compose.yml | ||
JUDGER_DOCKER_COMPOSE_FILE := $(DEV_WORKDIR)/judger/docker-compose.yml | ||
FRONTEND_DIST_DIR := $(DEV_WORKDIR)/frontend_dist | ||
FRONTEND_DIST_DIR := frontend/dist | ||
FRONTEND_DIST_URL := https://github.com/oj-lab/oj-lab-front/releases/download/v0.0.3/dist.zip | ||
ICPC_PROBLEM_PACKAGES_DIR := problem_packages/icpc | ||
ICPC_PROBLEM_PACKAGES_URL := https://github.com/oj-lab/problem-packages/releases/download/v0.0.1/icpc_problem.zip | ||
|
||
.PHONY: help | ||
help: | ||
@echo "Usage: make [target]" | ||
@echo "" | ||
@echo "Targets:" | ||
@echo " build - Build the application, swagger document will be generated" | ||
@echo " run - Run the application" | ||
@echo " clean - Clean the build" | ||
@echo " check - Run go vet" | ||
@echo " test - Run tests, database will be setup" | ||
@echo " gen-swagger - Generate swagger document" | ||
@echo " setup-dependencies - Setup the dependencies docker image" | ||
@echo " unset-dependencies - Unset the dependencies docker image" | ||
@echo " get-front - Get the frontend files" | ||
@echo " build - Build the application, swagger document will be generated" | ||
@echo " run - Run the application" | ||
@echo " clean - Clean the build" | ||
@echo " check - Run go vet" | ||
@echo " test - Run tests, database will be setup" | ||
@echo " gen-swagger - Generate swagger document" | ||
@echo " setup-dependencies - Setup the dependencies docker image" | ||
@echo " unset-dependencies - Unset the dependencies docker image" | ||
@echo " get-front - Get the frontend files" | ||
@echo " update-front - Update the frontend files" | ||
@echo " get-problem-packages - Get the problem packages" | ||
@echo " update-problem-packages - Update the problem packages" | ||
|
||
.PHONY: build | ||
build: gen-swagger gen-proto | ||
@echo "Building on $(OS)" | ||
go mod tidy | ||
go build -o bin/init_db cmd/init_db/main.go | ||
go build -o bin/web_server cmd/web_server/main.go | ||
go build -o bin/schedule cmd/schedule/main.go | ||
go build -o bin/problem_loader cmd/problem_loader/main.go | ||
go build -o bin/ ./cmd/... | ||
|
||
.PHONY: run | ||
run: build | ||
|
@@ -56,23 +56,35 @@ gen-proto: install-proto | |
|
||
.PHONY: unset-dependencies | ||
unset-dependencies: | ||
docker compose -f $(JUDGER_DOCKER_COMPOSE_FILE) -p oj-lab-judger stop | ||
docker compose -f $(JUDGER_DOCKER_COMPOSE_FILE) -p oj-lab-judger rm -f | ||
docker compose -f $(DB_DOCKER_COMPOSE_FILE) -p oj-lab-dbs stop | ||
docker compose -f $(DB_DOCKER_COMPOSE_FILE) -p oj-lab-dbs rm -f | ||
docker compose stop | ||
docker compose rm -f | ||
|
||
.PHONY: setup-dependencies | ||
setup-dependencies: unset-dependencies build | ||
docker compose -f $(DB_DOCKER_COMPOSE_FILE) -p oj-lab-dbs up -d | ||
setup-dependencies: unset-dependencies build get-front get-problem-packages | ||
docker compose up -d postgres redis minio clickhouse adminer | ||
@echo "Wait 10 seconds for db setup" | ||
sleep 10s | ||
./bin/init_db | ||
./bin/problem_loader | ||
docker compose -f $(JUDGER_DOCKER_COMPOSE_FILE) -p oj-lab-judger up -d | ||
./bin/init | ||
|
||
.PHONY: get-front | ||
get-front: | ||
./scripts/update-frontend-dist.sh $(FRONTEND_DIST_DIR) | ||
./scripts/download_and_unzip.sh $(FRONTEND_DIST_DIR) $(FRONTEND_DIST_URL) \ | ||
OVERRIDE=false | ||
|
||
.PHONY: update-front | ||
update-front: | ||
./scripts/download_and_unzip.sh $(FRONTEND_DIST_DIR) $(FRONTEND_DIST_URL) \ | ||
OVERRIDE=true | ||
|
||
.PHONY: get-problem-packages | ||
get-problem-packages: | ||
./scripts/download_and_unzip.sh $(ICPC_PROBLEM_PACKAGES_DIR) $(ICPC_PROBLEM_PACKAGES_URL) \ | ||
OVERRIDE=false | ||
|
||
.PHONY: update-problem-packages | ||
update-problem-packages: | ||
./scripts/download_and_unzip.sh $(ICPC_PROBLEM_PACKAGES_DIR) $(ICPC_PROBLEM_PACKAGES_URL) \ | ||
OVERRIDE=true | ||
|
||
.PHONY: check | ||
check: gen-proto install-cilint | ||
|
@@ -101,7 +113,7 @@ install-cilint: | |
.PHONY: install-proto | ||
install-proto: | ||
@# Referencing https://grpc.io/docs/protoc-installation/ | ||
@./scripts/install-protoc.sh | ||
@./scripts/install_protoc.sh | ||
@# Track https://grpc.io/docs/languages/go/quickstart/ for update | ||
go install google.golang.org/protobuf/cmd/[email protected] | ||
go install google.golang.org/grpc/cmd/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
casbin_agent "github.com/oj-lab/oj-lab-platform/modules/agent/casbin" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
initDB() | ||
loadProblemPackages(ctx) | ||
err := casbin_agent.LoadDefaultCasbinPolicies() | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to load default casbin policies: %v", err)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.