Skip to content

Commit

Permalink
Merge pull request #2 from senjun-team/actual-images
Browse files Browse the repository at this point in the history
SENJUN-23: add actual images
  • Loading branch information
ShipilovDmitry authored Jan 25, 2025
2 parents 018d56c + fa124c2 commit 3389c1a
Show file tree
Hide file tree
Showing 28 changed files with 4,116 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: C/C++ CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
services:
docker:
image: docker:dind
options: --privileged --shm-size=2g
ports:
- 2375:2375

steps:
- uses: actions/checkout@v4
- name: update_system
run: sudo apt update
- name: test_docker
run: docker version && docker info
- name: build_images
run: sh create_images.sh
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# senjun-images
# senjun-images
Репозиторий с docker-образами для языков программирования на senjun.ru
36 changes: 36 additions & 0 deletions cpp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM silkeh/clang:19
LABEL ru.senjun.image.authors="Shipilov Dmitry"

RUN apt-get update \
&& apt install -y ninja-build \
&& apt-get purge -y cmake

ARG CMAKE_VERSION=3.31.2

RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh \
-q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& mkdir /usr/bin/cmake \
&& /tmp/cmake-install.sh --skip-license --prefix=/usr/bin/cmake \
&& rm /tmp/cmake-install.sh

ENV PATH="/usr/bin/cmake/bin:${PATH}"

WORKDIR /home/code_runner

# Directory for task launching
RUN mkdir /home/code_runner/task
COPY task/run-task.sh task/CMakeLists.txt task/ut.hpp /home/code_runner/task/

# Directory for playground
RUN mkdir /home/code_runner/playground
COPY playground/run-playground.sh /home/code_runner/playground

# Change access write for code_runner home directory to root recursively
RUN useradd -ms /bin/bash code_runner \
&& chown -R code_runner:code_runner /home/code_runner \
&& chmod -R 1750 /home/code_runner

USER code_runner

ENTRYPOINT ["bash"]
1 change: 1 addition & 0 deletions cpp/build_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -t senjun_cpp .
36 changes: 36 additions & 0 deletions cpp/playground/run-playground.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

# parse flags - single letters prefixed with hyphen before each argument
# example: sh run.sh -f project_dir
while getopts f: flag
do
case "${flag}" in
f) project=${OPTARG};;
esac
done

f="$(basename -- $project)"

cd /home/code_runner/playground/$f

# configure project
if ! ( timeout 5s cmake -Bbuild -Wno-dev -GNinja > /tmp/configure.txt ); then
cat /tmp/configure.txt
echo user_solution_error_f936a25e
exit
fi

# build cpp project
if ! ( timeout 10s cmake --build build/ -- -j4 > /tmp/build.txt ); then
cat /tmp/build.txt
echo user_solution_error_f936a25e
exit
fi

# run cpp project
if ! ( timeout 5s ./build/cpp_experiments ); then
echo user_solution_error_f936a25e
exit
fi

echo user_solution_ok_f936a25e
36 changes: 36 additions & 0 deletions cpp/task/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.30.0 FATAL_ERROR)

# Включаем флаг для возможности `import std`.
# Эта строка должна идти ДО объявления, что проект на C++ (значение CXX).
SET(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
"0e5b6991-d74f-4b3d-a41c-cf096e0b2508")

# Для всех целей сборки устанавливаем возможность импорта std в 1.
SET(CMAKE_CXX_MODULE_STD 1)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Werror -Wall")

PROJECT(task_solution LANGUAGES CXX)

# TODO hardcode path is fragile!
IF (EXISTS "/home/code_runner/task/main.cpp")
add_executable(main)

target_sources(main
PRIVATE
main.cpp)

target_compile_features(main
PRIVATE cxx_std_23
INTERFACE cxx_std_23)
ENDIF()

add_executable(tests)

target_sources(tests
PRIVATE
tests.cpp)

target_compile_features(tests
PRIVATE cxx_std_23
INTERFACE cxx_std_23)
53 changes: 53 additions & 0 deletions cpp/task/run-task.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

# parse flags - single letters prefixed with hyphen before each argument
# example: sh run.sh -f task
while getopts f:v: flag
do
case "${flag}" in
f) file=${OPTARG};;
v) task_type=${OPTARG};;
esac
done

# go to the task dir
cd /home/code_runner/task

# if exists file with user code
if [ $task_type = "code" ]; then
touch main.cpp
cp $file main.cpp
fi

cp ${file}_tests tests.cpp

# configure project
if ! ( timeout 10s cmake -Wno-dev -Bbuild -GNinja > /tmp/configure.txt ); then
cat /tmp/configure.txt
echo user_solution_error_f936a25e
exit
fi

# build cpp project
if ! ( timeout 20s cmake --build build/ -- -j4 > /tmp/build.txt ); then
cat /tmp/build.txt
echo user_solution_error_f936a25e
exit
fi

# check task "what will this code output?"
if [ $task_type = "code" ]; then
if ! ( timeout 4s ./build/main ); then
echo user_solution_error_f936a25e
exit
fi
fi

echo user_code_ok_f936a25e

if ! ( timeout 4s ./build/tests ); then
echo tests_cases_error_f936a25e
exit
fi

echo user_solution_ok_f936a25e
Loading

0 comments on commit 3389c1a

Please sign in to comment.