Skip to content

Commit

Permalink
Simplify Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Sep 14, 2024
1 parent bef9d82 commit 2e02623
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
9 changes: 2 additions & 7 deletions program/cpp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ FROM ubuntu:24.04
# Install dependencies
RUN apt-get update && apt-get install -y \
g++-14-riscv64-linux-gnu \
g++ git cmake

# Clone and build mold
WORKDIR /usr/mold
RUN git clone https://github.com/rui314/mold.git /usr/mold
RUN mkdir -p /usr/mold/build && cd /usr/mold/build && cmake .. && make -j8
RUN cd /usr/mold/build && make install && rm -rf /usr/mold
git cmake mold

# Enter the shared directory
WORKDIR /usr/src
# Copy API files
RUN mkdir -p /usr/api
COPY build.sh api/* /usr/api/

# Set the entrypoint to the build script
#ENTRYPOINT "/usr/api/build.sh" "$0" "$@"
CMD ["/bin/bash", "-c", "tail -f /dev/null"]
2 changes: 1 addition & 1 deletion program/cpp/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ wait
if [ "$locally" = true ]; then
riscv64-unknown-elf-g++ -static $CPPFLAGS $LINKEROPS $@.o $API/*.cpp.o -o $output
else
LINKEROPS="$LINKEROPS -fuse-ld=mold -Wl,--execute-only"
LINKEROPS="$LINKEROPS -fuse-ld=mold"
riscv64-linux-gnu-g++-14 -static $CPPFLAGS -march=rv64gc_zba_zbb_zbs_zbc -mabi=lp64d $LINKEROPS $@.o $API/*.cpp.o -o $output
fi
9 changes: 1 addition & 8 deletions program/rust/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ FROM ubuntu:24.04

RUN apt-get -qq update && \
apt-get install -y -q \
build-essential \
curl \
g++-14-riscv64-linux-gnu \
g++ git cmake

# Clone and build mold
WORKDIR /usr/mold
RUN git clone https://github.com/rui314/mold.git /usr/mold
RUN mkdir -p /usr/mold/build && cd /usr/mold/build && cmake .. && make -j8
RUN cd /usr/mold/build && make install && rm -rf /usr/mold
git cmake mold

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
Expand Down
19 changes: 19 additions & 0 deletions src/docker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

#include "sandbox_project_settings.h"
#include <godot_cpp/classes/os.hpp>
//#define ENABLE_TIMINGS 1
#ifdef ENABLE_TIMINGS
#include <time.h>
#endif

static constexpr bool VERBOSE_CMD = true;
using namespace godot;


static bool ContainerIsAlreadyRunning(String container_name) {
godot::OS *OS = godot::OS::get_singleton();
PackedStringArray arguments = { "container", "inspect", "-f", "{{.State.Running}}", container_name };
Expand Down Expand Up @@ -64,6 +70,11 @@ Array Docker::ContainerStop(String container_name) {
}

bool Docker::ContainerExecute(String container_name, const PackedStringArray &p_arguments, Array &output, bool verbose) {
#ifdef ENABLE_TIMINGS
timespec start;
clock_gettime(CLOCK_MONOTONIC, &start);
#endif

godot::OS *OS = godot::OS::get_singleton();
PackedStringArray arguments = { "exec", "-t", container_name, "bash" };
for (int i = 0; i < p_arguments.size(); i++) {
Expand All @@ -73,6 +84,14 @@ bool Docker::ContainerExecute(String container_name, const PackedStringArray &p_
UtilityFunctions::print(SandboxProjectSettings::get_docker_path(), arguments);
}
const int res = OS->execute(SandboxProjectSettings::get_docker_path(), arguments, output);

#ifdef ENABLE_TIMINGS
timespec end;
clock_gettime(CLOCK_MONOTONIC, &end);
const double elapsed = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1e9;
fprintf(stderr, "Docker::ContainerExecute: %f seconds\n", elapsed);
#endif

return res == 0;
}

Expand Down

0 comments on commit 2e02623

Please sign in to comment.