1
0
mirror of https://github.com/pravets/oscript-images.git synced 2025-10-08 23:01:52 +02:00

feat: добавил образ и тест winow

This commit is contained in:
Iosif Pravets
2025-07-25 10:34:59 +00:00
committed by GitHub
parent 0aeef90868
commit 4fb184772f
4 changed files with 202 additions and 0 deletions

57
src/build-winow.sh Executable file
View File

@@ -0,0 +1,57 @@
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -z w"${CI:-}" ]; then
echo "The script is not running in CI"
source "${SCRIPT_DIR}/../scripts/load_env.sh"
else
echo "The script is running in CI";
fi
source "${SCRIPT_DIR}/../scripts/docker_login.sh"
source "${SCRIPT_DIR}/../tools/assert.sh"
if [[ "${DOCKER_SYSTEM_PRUNE:-}" = "true" ]] ;
then
docker system prune -af
fi
last_arg="."
if [[ ${NO_CACHE:-} = "true" ]] ; then
last_arg="--no-cache ."
fi
winow_version="latest"
docker build \
--pull \
--build-arg WINOW_VERSION="${winow_version}" \
--build-arg DOCKER_REGISTRY_URL="${DOCKER_REGISTRY_URL}" \
--build-arg DOCKER_LOGIN="${DOCKER_LOGIN}" \
-t "${DOCKER_REGISTRY_URL}/${DOCKER_LOGIN}/winow:${winow_version}" \
-f "${SCRIPT_DIR}/winow/Dockerfile" \
${last_arg}
if ./tests/test-winow.sh; then
opm_output=$(docker run --rm --entrypoint "opm" "${DOCKER_REGISTRY_URL}/${DOCKER_LOGIN}/winow:${winow_version}" ls)
container_version=$(echo "$opm_output" | awk -F '|' '/^winow[[:space:]]+\|/ {gsub(/ /, "", $2); print $2}')
if [[ -n "${container_version}" ]]; then
docker push "${DOCKER_REGISTRY_URL}/${DOCKER_LOGIN}/winow:${winow_version}"
docker tag "${DOCKER_REGISTRY_URL}/${DOCKER_LOGIN}/winow:${winow_version}" "${DOCKER_REGISTRY_URL}/${DOCKER_LOGIN}/winow:${container_version}"
docker push "${DOCKER_REGISTRY_URL}/${DOCKER_LOGIN}/winow:${container_version}"
else
log_failure "Не удалось получить версию из контейнера"
exit 1
fi
source "${SCRIPT_DIR}/../scripts/cleanup.sh"
else
log_failure "ERROR: Тесты провалены. Образ не был запушен."
source "${SCRIPT_DIR}/../scripts/cleanup.sh"
exit 1
fi
exit 0

16
src/winow/Dockerfile Normal file
View File

@@ -0,0 +1,16 @@
ARG DOCKER_REGISTRY_URL=docker.io
ARG DOCKER_LOGIN=sleemp
ARG BASE_IMAGE=oscript
ARG BASE_TAG=dev
FROM ${DOCKER_REGISTRY_URL}/${DOCKER_LOGIN}/${BASE_IMAGE}:${BASE_TAG}
LABEL maintainer="Iosif Pravets <i@pravets.ru>"
RUN opm i winow winow-cli
WORKDIR /app
COPY ./src/winow/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
VOLUME [ "/app" ]
EXPOSE 3333
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

23
src/winow/entrypoint.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# Проверяем наличие параметра -deps
check_deps=false
for arg in "$@"; do
if [ "$arg" = "-deps" ]; then
check_deps=true
break
fi
done
# Если передан -deps И существует packagedef, выполняем opm i
if [ "$check_deps" = true ]; then
if [ -f "packagedef" ]; then
echo "Файл packagedef найден. Устанавливаем зависимости с помощью opm i."
opm i
else
echo "Файл packagedef НЕ найден. Параметр -deps не может быть использован без него."
exit 1
fi
fi
winow start

106
tests/test-winow.sh Executable file
View File

@@ -0,0 +1,106 @@
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -z "${CI-}" ]; then
echo "The script is not running in CI"
source "${SCRIPT_DIR}/../.env"
else
echo "The script is running in CI"
fi
source "${SCRIPT_DIR}/../tools/assert.sh"
test_winow_is_running() {
log_header "Test :: winow is running"
local expected actual
local container_name="winow_test_running_$(date +%s)"
expected="ИНФОРМАЦИЯ - Используется нативный веб-сервер"
actual=$(docker run --rm --name $container_name ${DOCKER_REGISTRY_URL}/${DOCKER_LOGIN}/winow:latest 2>/dev/null | head -n1)
if assert_eq "$expected" "$actual"; then
log_success "winow is running test passed"
else
log_failure "winow is running test failed"
fi
docker stop $container_name > /dev/null 2>&1
}
test_winow_is_responsible() {
log_header "Test :: winow is responsible"
local expected actual
local container_name="winow_test_responsible_$(date +%s)"
expected="hello"
docker run \
--rm \
--name $container_name \
-p 3333:3333 \
-v "${SCRIPT_DIR}/../tests/winow/hello:/app" \
-d \
${DOCKER_REGISTRY_URL}/${DOCKER_LOGIN}/winow:latest > /dev/null 2>&1
sleep 5
actual=$(curl -s http://localhost:3333/)
if assert_eq "$expected" "$actual"; then
log_success "winow is responsible test passed"
else
log_failure "winow is responsible test failed"
fi
docker stop $container_name > /dev/null 2>&1
}
test_winow_is_stopped_without_packagedef() {
log_header "Test :: winow is stopped without packagedef"
local expected actual
local container_name="winow_test_stopped_without_packagedef_$(date +%s)"
expected="Файл packagedef НЕ найден. Параметр -deps не может быть использован без него."
actual=$(docker run --rm --name $container_name ${DOCKER_REGISTRY_URL}/${DOCKER_LOGIN}/winow:latest -deps 2>/dev/null | head -n1)
if assert_eq "$expected" "$actual"; then
log_success "winow is stopped without packagedef test passed"
else
log_failure "winow is stopped without packagedef test failed"
fi
}
test_winow_is_installing_deps() {
log_header "Test :: winow is installing deps"
local expected actual
local container_name="winow_test_installing_deps_$(date +%s)"
expected="Файл packagedef найден. Устанавливаем зависимости с помощью opm i."
actual=$(docker run \
--rm \
--name $container_name \
-v "${SCRIPT_DIR}/../tests/winow/hello:/app" \
${DOCKER_REGISTRY_URL}/${DOCKER_LOGIN}/winow:latest -deps 2>/dev/null | head -n1)
if assert_eq "$expected" "$actual"; then
log_success "winow is installing deps test passed"
else
log_failure "winow is installing deps test failed"
fi
docker stop $container_name > /dev/null 2>&1
}
# test calls
test_winow_is_running
test_winow_is_responsible
test_winow_is_stopped_without_packagedef
test_winow_is_installing_deps