Compare commits
3 Commits
ed6713d5c0
...
a193dee410
Author | SHA1 | Date | |
---|---|---|---|
a193dee410 | |||
db16b3e76f | |||
967970fc38 |
30
.github/workflows/docker.yml
vendored
Normal file
30
.github/workflows/docker.yml
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
name: Build Docker Image
|
||||
on: [ push ]
|
||||
jobs:
|
||||
image:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Login to Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.0x7f.app
|
||||
username: ${{ secrets.CONTAINER_USERNAME }}
|
||||
password: ${{ secrets.CONTAINER_PASSWORD }}
|
||||
- name: Write Sentry DSN
|
||||
run: echo -n "$SENTRY_DSN" > dsn.txt
|
||||
env:
|
||||
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
|
||||
- name: Build Base Image
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: ./build_image.sh base
|
||||
env:
|
||||
DOCKER: docker
|
||||
- name: Build Server Image
|
||||
run: ./build_image.sh server
|
||||
env:
|
||||
DOCKER: docker
|
||||
- name: Build Runner Image
|
||||
run: ./build_image.sh runner
|
||||
env:
|
||||
DOCKER: docker
|
2
Makefile
2
Makefile
@ -9,6 +9,8 @@ LDFLAGS += -X $(PKG_BASE)/cmd.BuildTime=$(BUILD_TIME)
|
||||
LDFLAGS += -X $(PKG_BASE)/cmd.Version=$(VERSION)
|
||||
LDFLAGS += -X $(PKG_BASE)/cmd.GitCommit=$(GIT_COMMIT)
|
||||
LDFLAGS += -X $(PKG_BASE)/cmd.SentryDSN=$(shell cat dsn.txt)
|
||||
LDFLAGS += -X $(PKG_BASE)/internal/service/runner.ContainerImageFull=$(CONTAINER_IMAGE_FULL)
|
||||
LDFLAGS += -X $(PKG_BASE)/internal/service/runner.ContainerImageRun=$(CONTAINER_IMAGE_RUN)
|
||||
LDFLAGS += -s -w
|
||||
|
||||
GOBUILD := $(GO) build -ldflags '$(LDFLAGS)'
|
||||
|
@ -8,6 +8,10 @@ WORKDIR /builder
|
||||
RUN apk add --no-cache git make
|
||||
RUN --mount=type=cache,id=golang,target=/go/pkg go install github.com/swaggo/swag/cmd/swag@latest
|
||||
|
||||
ARG IMAGE_PREFIX=git.0x7f.app/woj
|
||||
ENV CONTAINER_IMAGE_FULL=${IMAGE_PREFIX}/ubuntu-full:latest
|
||||
ENV CONTAINER_IMAGE_RUN=${IMAGE_PREFIX}/ubuntu-run:latest
|
||||
|
||||
COPY go.mod /builder/go.mod
|
||||
COPY go.sum /builder/go.sum
|
||||
RUN --mount=type=cache,id=golang,target=/go/pkg go mod download
|
||||
|
@ -2,54 +2,63 @@
|
||||
|
||||
. resource/runner/scripts/common.sh
|
||||
|
||||
# version
|
||||
# Version
|
||||
VERSION="$(cat VERSION)"
|
||||
log_info "VERSION: $VERSION"
|
||||
|
||||
# Image Prefix
|
||||
IMAGE_PREFIX=${IMAGE_PREFIX:-"git.0x7f.app/woj"}
|
||||
|
||||
function docker_build() {
|
||||
tag_name="$IMAGE_PREFIX/$1"
|
||||
docker_file="$2"
|
||||
shift 2
|
||||
$DOCKER build -t "$tag_name" -f "$docker_file" --build-arg "IMAGE_PREFIX=$IMAGE_PREFIX" "$@" . ||
|
||||
{ log_error "[!] Failed to build $tag_name"; exit 1; }
|
||||
}
|
||||
|
||||
function build_base() {
|
||||
log_info "[+] Building Base Images"
|
||||
pushd resource/runner || exit 1
|
||||
$DOCKER build -t git.0x7f.app/woj/ubuntu-full:latest -f scripts/ubuntu-full.Dockerfile . ||
|
||||
(log_error "Build Full Image failed" && exit 1)
|
||||
$DOCKER build -t git.0x7f.app/woj/ubuntu-run:latest -f scripts/ubuntu-run.Dockerfile . ||
|
||||
(log_error "Build Tiny Image failed" && exit 1)
|
||||
docker_build "ubuntu-full:latest" "scripts/ubuntu-full.Dockerfile"
|
||||
docker_build "ubuntu-run:latest" "scripts/ubuntu-run.Dockerfile"
|
||||
popd || exit 1
|
||||
}
|
||||
|
||||
function push_base() {
|
||||
log_info "[+] Pushing Base Images"
|
||||
$DOCKER push "git.0x7f.app/woj/ubuntu-full:latest"
|
||||
$DOCKER push "git.0x7f.app/woj/ubuntu-run:latest"
|
||||
$DOCKER push "$IMAGE_PREFIX/ubuntu-full:latest"
|
||||
$DOCKER push "$IMAGE_PREFIX/ubuntu-run:latest"
|
||||
}
|
||||
|
||||
function build_server() {
|
||||
log_info "[+] Building Server"
|
||||
$DOCKER build -t "git.0x7f.app/woj/woj-server:latest" -f Server.Dockerfile . ||
|
||||
(log_error "[!] Failed to build Server" && exit 1)
|
||||
docker_build "woj-server:latest" "Server.Dockerfile"
|
||||
}
|
||||
|
||||
function build_runner() {
|
||||
log_info "[+] Building Runner"
|
||||
$DOCKER build \
|
||||
--cap-add=sys_admin \
|
||||
--security-opt label=disable \
|
||||
-t "git.0x7f.app/woj/woj-runner:latest" \
|
||||
-f Runner.Dockerfile . ||
|
||||
(log_error "[!] Failed to build Runner" && exit 1)
|
||||
if [[ "$DOCKER" == "docker" ]]; then
|
||||
# docker do not support --cap-add during build time
|
||||
docker_build "woj-runner:latest" "Runner.Dockerfile" --allow security.insecure
|
||||
else
|
||||
# podman
|
||||
docker_build "woj-runner:latest" "Runner.Dockerfile" --cap-add=sys_admin --security-opt label=disable
|
||||
fi
|
||||
}
|
||||
|
||||
function push_server() {
|
||||
log_info "[+] Pushing Server Images"
|
||||
$DOCKER push "git.0x7f.app/woj/woj-server:latest"
|
||||
$DOCKER tag "git.0x7f.app/woj/woj-server:latest" "git.0x7f.app/woj/woj-server:$VERSION"
|
||||
$DOCKER push "git.0x7f.app/woj/woj-server:$VERSION"
|
||||
$DOCKER push "$IMAGE_PREFIX/woj-server:latest"
|
||||
$DOCKER tag "$IMAGE_PREFIX/woj-server:latest" "$IMAGE_PREFIX/woj-server:$VERSION"
|
||||
$DOCKER push "$IMAGE_PREFIX/woj-server:$VERSION"
|
||||
}
|
||||
|
||||
function push_runner() {
|
||||
log_info "[+] Pushing Runner Images"
|
||||
$DOCKER push "git.0x7f.app/woj/woj-runner:latest"
|
||||
$DOCKER tag "git.0x7f.app/woj/woj-runner:latest" "git.0x7f.app/woj/woj-runner:$VERSION"
|
||||
$DOCKER push "git.0x7f.app/woj/woj-runner:$VERSION"
|
||||
$DOCKER push "$IMAGE_PREFIX/woj-runner:latest"
|
||||
$DOCKER tag "$IMAGE_PREFIX/woj-runner:latest" "$IMAGE_PREFIX/woj-runner:$VERSION"
|
||||
$DOCKER push "$IMAGE_PREFIX/woj-runner:$VERSION"
|
||||
}
|
||||
|
||||
if [ "$1" == "base" ]; then
|
||||
|
@ -17,9 +17,9 @@ var (
|
||||
TmpDir = "./tmp/"
|
||||
)
|
||||
|
||||
const (
|
||||
ContainerImageFull = "git.0x7f.app/woj/ubuntu-full:latest"
|
||||
ContainerImageRun = "git.0x7f.app/woj/ubuntu-run:latest"
|
||||
var (
|
||||
ContainerImageFull string
|
||||
ContainerImageRun string
|
||||
)
|
||||
|
||||
type JudgeMetaRun struct {
|
||||
@ -48,6 +48,16 @@ func init() {
|
||||
ProblemDir = path.Join(Prefix, ProblemDir)
|
||||
UserDir = path.Join(Prefix, UserDir)
|
||||
TmpDir = path.Join(Prefix, TmpDir)
|
||||
|
||||
fmt.Println("ImageFull:", ContainerImageFull)
|
||||
fmt.Println("ImageRun:", ContainerImageRun)
|
||||
|
||||
if ContainerImageFull == "" {
|
||||
ContainerImageFull = "git.0x7f.app/woj/ubuntu-full:latest"
|
||||
}
|
||||
if ContainerImageRun == "" {
|
||||
ContainerImageRun = "git.0x7f.app/woj/ubuntu-run:latest"
|
||||
}
|
||||
}
|
||||
|
||||
func (s *service) ProblemExists(meta *JudgeMeta) bool {
|
||||
|
@ -9,7 +9,7 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y software-prope
|
||||
gcc g++ clang make cmake autoconf m4 libtool gperf \
|
||||
python3 pypy3 \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists
|
||||
RUN wget https://go.dev/dl/go1.21.6.linux-amd64.tar.gz && rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz && rm go1.21.6.linux-amd64.tar.gz
|
||||
RUN wget https://go.dev/dl/go1.22.0.linux-amd64.tar.gz && rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz && rm go1.22.0.linux-amd64.tar.gz
|
||||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||
ENV PATH=/usr/local/go/bin:/root/.cargo/bin:$PATH
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
FROM git.0x7f.app/woj/ubuntu-full:latest AS builder
|
||||
ARG IMAGE_PREFIX=git.0x7f.app/woj
|
||||
|
||||
FROM ${IMAGE_PREFIX}/ubuntu-full:latest AS builder
|
||||
FROM docker.io/library/ubuntu:22.04
|
||||
|
||||
RUN apt-get update && apt-get upgrade -y \
|
||||
|
Loading…
Reference in New Issue
Block a user