woj-server/resource/runner/scripts/prepare_container.sh

60 lines
1.7 KiB
Bash
Raw Normal View History

2022-10-20 18:21:11 +08:00
#!/usr/bin/env bash
. common.sh
cd "$(dirname "$0")"/../ || exit 1
2022-10-28 21:57:28 +08:00
# Check Mark
if [ -f ./.mark.container ]; then
2022-10-20 18:21:11 +08:00
log_warn "Docker containers already prepared"
2022-10-28 21:57:28 +08:00
log_warn "If you want to re-prepare the containers, please remove the file $(pwd)/.mark.container"
2022-10-20 18:21:11 +08:00
exit 1
fi
2022-10-28 21:57:28 +08:00
log_info "Preparing container..."
log_info "Using $DOCKER - $($DOCKER --version)"
2022-10-20 18:21:11 +08:00
# Full
2022-10-28 21:57:28 +08:00
log_info "Building Full Image"
2022-10-20 18:21:11 +08:00
cat <<EOF >ubuntu-full.Dockerfile
2022-10-28 21:57:28 +08:00
FROM docker.io/library/ubuntu:22.04
2022-10-20 18:21:11 +08:00
WORKDIR /woj/
# Install dependencies
2022-10-28 21:57:28 +08:00
RUN apt-get update && apt-get upgrade -y && apt-get install -y gcc g++ clang make cmake autoconf m4 libtool gperf git parallel python3 && apt-get clean && rm -rf /var/lib/apt/lists
2022-10-20 18:21:11 +08:00
# Copy source code
RUN mkdir -p /woj/framework && mkdir -p /woj/problem
COPY framework /woj/framework
# Build
RUN cd /woj/framework/template && ./setup.sh
RUN cd /woj/framework/scripts && ./setup.sh
# Environment
ENV WOJ_LAUNCHER=/woj/framework/scripts/woj_launcher
ENV WOJ_SANDBOX=/woj/framework/scripts/libwoj_sandbox.so
ENV TEMPLATE=/woj/framework/template
ENV TESTLIB=/woj/framework/template/testlib
ENV PREFIX=/woj/problem
EOF
2022-10-28 21:57:28 +08:00
$DOCKER build -t woj/ubuntu-full -f ubuntu-full.Dockerfile . || exit 1
2022-10-20 18:21:11 +08:00
rm ubuntu-full.Dockerfile
# Tiny
2022-10-28 21:57:28 +08:00
log_info "Building Tiny Image"
2022-10-20 18:21:11 +08:00
cat <<EOF >ubuntu-run.Dockerfile
FROM woj/ubuntu-full:latest AS builder
2022-10-28 21:57:28 +08:00
FROM docker.io/library/ubuntu:22.04
2022-10-20 18:21:11 +08:00
WORKDIR /woj/problem
RUN mkdir -p /woj/framework/scripts
COPY --from=builder /woj/framework/scripts/libwoj_sandbox.so /woj/framework/scripts/
COPY --from=builder /woj/framework/scripts/woj_launcher /woj/framework/scripts/
EOF
2022-10-28 21:57:28 +08:00
$DOCKER build -t woj/ubuntu-run -f ubuntu-run.Dockerfile . || exit 1
2022-10-20 18:21:11 +08:00
rm ubuntu-run.Dockerfile
2022-10-28 21:57:28 +08:00
touch ./.mark.container
log_info "Done"