feat: add podman support
This commit is contained in:
parent
26a81652b3
commit
97c05a836c
@ -36,6 +36,10 @@ func (s *service) execute(script string, args ...string) error {
|
||||
p := filepath.Join(ScriptsDir, script)
|
||||
cmd := exec.Command(p, args...)
|
||||
cmd.Dir = ScriptsDir
|
||||
if s.verbose {
|
||||
cmd.Stdout = os.Stderr
|
||||
cmd.Stderr = os.Stderr
|
||||
}
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *service) EnsureDeps(force bool) e.Status {
|
||||
mark := filepath.Join(Prefix, ".mark.docker")
|
||||
mark := filepath.Join(Prefix, ".mark.container")
|
||||
|
||||
if force {
|
||||
_ = os.Remove(mark)
|
||||
|
@ -26,11 +26,13 @@ type Service interface {
|
||||
}
|
||||
|
||||
type service struct {
|
||||
log *zap.Logger
|
||||
log *zap.Logger
|
||||
verbose bool
|
||||
}
|
||||
|
||||
func NewService(g *global.Global) Service {
|
||||
return &service{
|
||||
log: g.Log,
|
||||
log: g.Log,
|
||||
verbose: g.Conf.Development,
|
||||
}
|
||||
}
|
||||
|
@ -8,3 +8,7 @@ COLOR_NONE="\e[0m"
|
||||
function log_info() { echo -e "${COLOR_GREEN}$*${COLOR_NONE}" 1>&2; }
|
||||
function log_warn() { echo -e "${COLOR_YELLOW}$*${COLOR_NONE}" 1>&2; }
|
||||
function log_error() { echo -e "${COLOR_RED}$*${COLOR_NONE}" 1>&2; }
|
||||
|
||||
# Docker or Podman
|
||||
DOCKER="docker"
|
||||
if [ "$USE_PODMAN" ]; then DOCKER="podman"; fi
|
||||
|
@ -4,19 +4,24 @@
|
||||
|
||||
cd "$(dirname "$0")"/../ || exit 1
|
||||
|
||||
if [ -f ./.mark.docker ]; then
|
||||
# Check Mark
|
||||
if [ -f ./.mark.container ]; then
|
||||
log_warn "Docker containers already prepared"
|
||||
log_warn "If you want to re-prepare the containers, please remove the file $(pwd)/.mark.docker"
|
||||
log_warn "If you want to re-prepare the containers, please remove the file $(pwd)/.mark.container"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "Preparing container..."
|
||||
log_info "Using $DOCKER - $($DOCKER --version)"
|
||||
|
||||
# Full
|
||||
log_info "Building Full Image"
|
||||
cat <<EOF >ubuntu-full.Dockerfile
|
||||
FROM ubuntu:22.04
|
||||
FROM docker.io/library/ubuntu:22.04
|
||||
WORKDIR /woj/
|
||||
|
||||
# Install dependencies
|
||||
RUN apt-get update && 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
|
||||
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
|
||||
|
||||
# Copy source code
|
||||
RUN mkdir -p /woj/framework && mkdir -p /woj/problem
|
||||
@ -33,19 +38,22 @@ ENV TEMPLATE=/woj/framework/template
|
||||
ENV TESTLIB=/woj/framework/template/testlib
|
||||
ENV PREFIX=/woj/problem
|
||||
EOF
|
||||
docker build -t woj/ubuntu-full -f ubuntu-full.Dockerfile . || exit 1
|
||||
$DOCKER build -t woj/ubuntu-full -f ubuntu-full.Dockerfile . || exit 1
|
||||
rm ubuntu-full.Dockerfile
|
||||
|
||||
# Tiny
|
||||
log_info "Building Tiny Image"
|
||||
cat <<EOF >ubuntu-run.Dockerfile
|
||||
FROM woj/ubuntu-full:latest AS builder
|
||||
FROM ubuntu:22.04
|
||||
FROM docker.io/library/ubuntu:22.04
|
||||
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
|
||||
docker build -t woj/ubuntu-run -f ubuntu-run.Dockerfile . || exit 1
|
||||
$DOCKER build -t woj/ubuntu-run -f ubuntu-run.Dockerfile . || exit 1
|
||||
rm ubuntu-run.Dockerfile
|
||||
|
||||
touch ./.mark.docker
|
||||
touch ./.mark.container
|
||||
|
||||
log_info "Done"
|
||||
|
@ -4,13 +4,15 @@
|
||||
|
||||
function docker_run() {
|
||||
local timeout=${TIMEOUT:-10}
|
||||
local log_file=${LOG_FILE:-/dev/stderr}
|
||||
log_info "Docker run with timeout $timeout"
|
||||
local log_file=${LOG_FILE:-"/dev/stderr"}
|
||||
local log_limit=${LOG_LIMIT:-1K}
|
||||
log_info "$DOCKER run with timeout $timeout"
|
||||
CONTAINER_NAME=$(uuidgen)
|
||||
(
|
||||
sleep "$timeout"
|
||||
docker kill "$CONTAINER_NAME"
|
||||
$DOCKER kill "$CONTAINER_NAME"
|
||||
) &
|
||||
docker run --rm --name "$CONTAINER_NAME" "$@" > "$log_file" 2>&1
|
||||
$DOCKER run --rm --name "$CONTAINER_NAME" "$@" 2>&1 | head -c "$log_limit" >"$log_file"
|
||||
pkill -P $$
|
||||
$DOCKER kill "$CONTAINER_NAME" >/dev/null 2>&1
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user