Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ovcharenko-di committed Nov 14, 2024
1 parent 77f110c commit d016935
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 222 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ copy .onec.env.bat.example env.bat
* EDT_VERSION - версия EDT. Обязательно заполнять только при сборке образов с EDT или при использовании замеров покрытия (см. `COVERAGE41C_VERSION`)
* DOCKER_REGISTRY_URL - Адрес Docker-registry в котором будут храниться образы
* COVERAGE41C_VERSION - версия Coverage41C
Если заполнено, то при выполнении скриптов `build-base-*-agent.*` будет также собран образ `base-jenkins-coverage-agent`, подготовленный для сбора замеров покрытия с помощью Coverage41C. Требуется также указать значение для переменной EDT_VERSION.
Используется при сборке агента скриптами `build-base-*-jenkins-coverage-agent.*`.

Затем экспортируйте все необходимые переменные:

Expand All @@ -68,13 +68,13 @@ env.bat

1. Если вам нужны образы для использования в docker-swarm:

* build-base-swarm-jenkins-agent.sh
* build-base-swarm-jenkins-agent.sh (или build-base-swarm-jenkins-coverage-agent.sh с замерами покрытия)
* build-edt-swarm-agent.sh
* build-oscript-swarm-agent.sh

2. Если же вы планируете использовать k8s
2. Если же вы планируете использовать k8s:

* build-base-k8s-jenkins-agent.sh
* build-base-k8s-jenkins-agent.sh (или build-base-k8s-jenkins-coverage-agent.sh с замерами покрытия)
* build-edt-k8s-agent.sh
* build-oscript-k8s-agent.sh

Expand Down Expand Up @@ -216,6 +216,7 @@ docker build --build-arg DOCKER_REGISTRY_URL=${DOCKER_REGISTRY_URL} \
-t ${DOCKER_REGISTRY_URL}/runner:1.7.0 \
-f vanessa-runner/Dockerfile .
```

## EDT
[(Наверх)](#Оглавление)
```bash
Expand Down
21 changes: 2 additions & 19 deletions build-base-k8s-jenkins-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ if [ "${NO_CACHE}" = 'true' ] ; then
last_arg='--no-cache .'
fi

# если устанавливаем Coverage41C, то предварительно нужно собрать образы EDT
if [[ $COVERAGE41C_VERSION != "" ]] ; then
./build-edt-k8s-agent.sh
fi

docker build \
--pull \
$no_cache_arg \
Expand Down Expand Up @@ -92,18 +87,6 @@ docker build \
-f k8s-jenkins-agent/Dockerfile \
$last_arg

docker push $DOCKER_REGISTRY_URL/base-jenkins-agent:$ONEC_VERSION

if [[ $COVERAGE41C_VERSION != "" ]] ; then
docker build \
--build-arg DOCKER_REGISTRY_URL=$DOCKER_REGISTRY_URL \
--build-arg BASE_IMAGE=base-jenkins-agent \
--build-arg BASE_TAG=$ONEC_VERSION \
--build-arg EDT_VERSION=$EDT_VERSION \
--build-arg COVERAGE41C_VERSION=$COVERAGE41C_VERSION \
-t $DOCKER_REGISTRY_URL/base-jenkins-coverage-agent:$ONEC_VERSION \
-f coverage41C/Dockerfile \
$last_arg

docker push $DOCKER_REGISTRY_URL/base-jenkins-coverage-agent:$ONEC_VERSION
if [ -z "$1" ] ; then
docker push $DOCKER_REGISTRY_URL/base-jenkins-agent:$ONEC_VERSION
fi
35 changes: 35 additions & 0 deletions build-base-k8s-jenkins-coverage-agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -eo pipefail

if [ -n "${DOCKER_LOGIN}" ] && [ -n "${DOCKER_PASSWORD}" ] && [ -n "${DOCKER_REGISTRY_URL}" ]; then
if ! docker login -u "${DOCKER_LOGIN}" -p "${DOCKER_PASSWORD}" "${DOCKER_REGISTRY_URL}"; then
echo "Docker login failed"
exit 1
fi
else
echo "Skipping Docker login due to missing credentials"
fi

if [ "${DOCKER_SYSTEM_PRUNE}" = 'true' ] ; then
docker system prune -af
fi

last_arg='.'
if [ "${NO_CACHE}" = 'true' ] ; then
last_arg='--no-cache .'
fi

./build-edt.sh
./build-base-k8s-jenkins-agent.sh "do_not_push_agent"

docker build \
--build-arg DOCKER_REGISTRY_URL=$DOCKER_REGISTRY_URL \
--build-arg BASE_IMAGE=base-jenkins-agent \
--build-arg BASE_TAG=$ONEC_VERSION \
--build-arg EDT_VERSION=$EDT_VERSION \
--build-arg COVERAGE41C_VERSION=$COVERAGE41C_VERSION \
-t $DOCKER_REGISTRY_URL/base-jenkins-coverage-agent:$ONEC_VERSION \
-f coverage41C/Dockerfile \
$last_arg

docker push $DOCKER_REGISTRY_URL/base-jenkins-coverage-agent:$ONEC_VERSION
24 changes: 3 additions & 21 deletions build-base-swarm-jenkins-agent.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ if %ERRORLEVEL% neq 0 goto end

if %NO_CACHE%=="true" (SET last_arg="--no-cache .") else (SET last_arg=".")

# если устанавливаем Coverage41C, то предварительно нужно собрать образы EDT
if %COVERAGE41C_VERSION% neq "" (.\build-edt-swarm-agent.bat)

docker build ^
--pull ^
--build-arg DOCKER_REGISTRY_URL=library ^
Expand Down Expand Up @@ -97,26 +94,11 @@ docker build ^

if %ERRORLEVEL% neq 0 goto end

docker push %DOCKER_REGISTRY_URL%/base-jenkins-agent:%ONEC_VERSION%
IF "%~1"=="" (
docker push %DOCKER_REGISTRY_URL%/base-jenkins-agent:%ONEC_VERSION%
)

if %ERRORLEVEL% neq 0 goto end

if %COVERAGE41C_VERSION% neq "" (

docker build ^
--build-arg DOCKER_REGISTRY_URL=%DOCKER_REGISTRY_URL% ^
--build-arg BASE_IMAGE=base-jenkins-agent ^
--build-arg BASE_TAG=%ONEC_VERSION% ^
--build-arg EDT_VERSION=%EDT_VERSION% ^
--build-arg COVERAGE41C_VERSION=%COVERAGE41C_VERSION% ^
-t %DOCKER_REGISTRY_URL%/base-jenkins-coverage-agent:%ONEC_VERSION% ^
-f coverage41C/Dockerfile ^
%last_arg%


docker push %DOCKER_REGISTRY_URL%/base-jenkins-coverage-agent:%ONEC_VERSION%

)

:end
echo End of program.
21 changes: 2 additions & 19 deletions build-base-swarm-jenkins-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ if [ "${NO_CACHE}" = 'true' ] ; then
last_arg='--no-cache .'
fi

# если устанавливаем Coverage41C, то предварительно нужно собрать образы EDT
if [[ $COVERAGE41C_VERSION != "" ]] ; then
./build-edt-swarm-agent.sh
fi

docker build \
--pull \
$no_cache_arg \
Expand Down Expand Up @@ -92,18 +87,6 @@ docker build \
-f swarm-jenkins-agent/Dockerfile \
$last_arg

docker push $DOCKER_REGISTRY_URL/base-jenkins-agent:$ONEC_VERSION

if [[ $COVERAGE41C_VERSION != "" ]] ; then
docker build \
--build-arg DOCKER_REGISTRY_URL=$DOCKER_REGISTRY_URL \
--build-arg BASE_IMAGE=base-jenkins-agent \
--build-arg BASE_TAG=$ONEC_VERSION \
--build-arg EDT_VERSION=$EDT_VERSION \
--build-arg COVERAGE41C_VERSION=$COVERAGE41C_VERSION \
-t $DOCKER_REGISTRY_URL/base-jenkins-coverage-agent:$ONEC_VERSION \
-f coverage41C/Dockerfile \
$last_arg

docker push $DOCKER_REGISTRY_URL/base-jenkins-coverage-agent:$ONEC_VERSION
if [ -z "$1" ] ; then
docker push $DOCKER_REGISTRY_URL/base-jenkins-agent:$ONEC_VERSION
fi
27 changes: 27 additions & 0 deletions build-base-swarm-jenkins-coverage-agent.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@echo off

docker login -u %DOCKER_LOGIN% -p %DOCKER_PASSWORD% %DOCKER_REGISTRY_URL%

if %ERRORLEVEL% neq 0 goto end

if %DOCKER_SYSTEM_PRUNE%=="true" docker system prune -af

if %ERRORLEVEL% neq 0 goto end

if %NO_CACHE%=="true" (SET last_arg="--no-cache .") else (SET last_arg=".")

.\build-edt-swarm-agent.bat
.\build-base-swarm-jenkins-agent.bat "do_not_push_agent"

docker build ^
--build-arg DOCKER_REGISTRY_URL=%DOCKER_REGISTRY_URL% ^
--build-arg BASE_IMAGE=base-jenkins-agent ^
--build-arg BASE_TAG=%ONEC_VERSION% ^
--build-arg EDT_VERSION=%EDT_VERSION% ^
--build-arg COVERAGE41C_VERSION=%COVERAGE41C_VERSION% ^
-t %DOCKER_REGISTRY_URL%/base-jenkins-coverage-agent:%ONEC_VERSION% ^
-f coverage41C/Dockerfile ^
%last_arg%

docker push %DOCKER_REGISTRY_URL%/base-jenkins-coverage-agent:%ONEC_VERSION%

35 changes: 35 additions & 0 deletions build-base-swarm-jenkins-coverage-agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -eo pipefail

if [ -n "${DOCKER_LOGIN}" ] && [ -n "${DOCKER_PASSWORD}" ] && [ -n "${DOCKER_REGISTRY_URL}" ]; then
if ! docker login -u "${DOCKER_LOGIN}" -p "${DOCKER_PASSWORD}" "${DOCKER_REGISTRY_URL}"; then
echo "Docker login failed"
exit 1
fi
else
echo "Skipping Docker login due to missing credentials"
fi

if [ "${DOCKER_SYSTEM_PRUNE}" = 'true' ] ; then
docker system prune -af
fi

last_arg='.'
if [ "${NO_CACHE}" = 'true' ] ; then
last_arg='--no-cache .'
fi

./build-edt.sh
./build-base-swarm-jenkins-agent.sh "do_not_push_agent"

docker build \
--build-arg DOCKER_REGISTRY_URL=$DOCKER_REGISTRY_URL \
--build-arg BASE_IMAGE=base-jenkins-agent \
--build-arg BASE_TAG=$ONEC_VERSION \
--build-arg EDT_VERSION=$EDT_VERSION \
--build-arg COVERAGE41C_VERSION=$COVERAGE41C_VERSION \
-t $DOCKER_REGISTRY_URL/base-jenkins-coverage-agent:$ONEC_VERSION \
-f coverage41C/Dockerfile \
$last_arg

docker push $DOCKER_REGISTRY_URL/base-jenkins-coverage-agent:$ONEC_VERSION
57 changes: 1 addition & 56 deletions build-edt-k8s-agent.sh
Original file line number Diff line number Diff line change
@@ -1,59 +1,4 @@
#!/usr/bin/env bash
set -eo pipefail

if [ -n "${DOCKER_LOGIN}" ] && [ -n "${DOCKER_PASSWORD}" ] && [ -n "${DOCKER_REGISTRY_URL}" ]; then
if ! docker login -u "${DOCKER_LOGIN}" -p "${DOCKER_PASSWORD}" "${DOCKER_REGISTRY_URL}"; then
echo "Docker login failed"
exit 1
fi
else
echo "Skipping Docker login due to missing credentials"
fi

if [ "${DOCKER_SYSTEM_PRUNE}" = 'true' ] ; then
docker system prune -af
fi

#Если версия EDT >= 2024.1.0, использовать JDK 17
if [[ "$(printf "%s\n" "$EDT_VERSION" "2024" | sort -V | head -n 1)" == "2024" ]]; then
BASE_IMAGE="azul/zulu-openjdk"
BASE_TAG="17"
else
BASE_IMAGE="eclipse-temurin"
BASE_TAG="11"
fi

last_arg='.'
if [ "${NO_CACHE}" = 'true' ] ; then
last_arg='--no-cache .'
fi

edt_version=$EDT_VERSION
edt_escaped="${edt_version// /_}"

docker build \
--pull \
$no_cache_arg \
--build-arg DOCKER_REGISTRY_URL=library \
--build-arg BASE_IMAGE=ubuntu \
--build-arg BASE_TAG=20.04 \
--build-arg ONESCRIPT_PACKAGES="yard" \
-t $DOCKER_REGISTRY_URL/oscript-downloader:latest \
-f oscript/Dockerfile \
$last_arg

docker build \
--build-arg ONEC_USERNAME=$ONEC_USERNAME \
--build-arg ONEC_PASSWORD=$ONEC_PASSWORD \
--build-arg EDT_VERSION="$EDT_VERSION" \
--build-arg BASE_IMAGE=$BASE_IMAGE \
--build-arg BASE_TAG=$BASE_TAG \
--build-arg DOWNLOADER_REGISTRY_URL=$DOCKER_REGISTRY_URL \
--build-arg DOWNLOADER_IMAGE=oscript-downloader \
--build-arg DOWNLOADER_TAG=latest \
-t $DOCKER_REGISTRY_URL/edt:$edt_escaped \
-f edt/Dockerfile \
$last_arg
./build-edt.sh

docker build \
--build-arg DOCKER_REGISTRY_URL=$DOCKER_REGISTRY_URL \
Expand Down
49 changes: 1 addition & 48 deletions build-edt-swarm-agent.bat
Original file line number Diff line number Diff line change
@@ -1,53 +1,6 @@
@echo off

docker login -u %DOCKER_LOGIN% -p %DOCKER_PASSWORD% %DOCKER_REGISTRY_URL%

if %ERRORLEVEL% neq 0 goto end

if %DOCKER_SYSTEM_PRUNE%=="true" docker system prune -af

if %ERRORLEVEL% neq 0 goto end

for /f "delims=." %%a in ("%EDT_VERSION%") do set EDT_MAJOR_VERSION=%aa
if %EDT_MAJOR_VERSION% GEQ "2024" (
set BASE_IMAGE="azul/zulu-openjdk"
set BASE_TAG="17"
) else (
set BASE_IMAGE="eclipse-temurin"
set BASE_TAG="11"
)

if %ERRORLEVEL% neq 0 goto end

if %NO_CACHE%=="true" (SET last_arg="--no-cache .") else (SET last_arg=".")

set edt_version=%EDT_VERSION%
set edt_escaped=%edt_version: =_%

docker build ^
--pull ^
--build-arg DOCKER_REGISTRY_URL=library ^
--build-arg BASE_IMAGE=ubuntu ^
--build-arg BASE_TAG=20.04 ^
--build-arg ONESCRIPT_PACKAGES="yard" ^
-t %DOCKER_REGISTRY_URL%/oscript-downloader:latest ^
-f oscript/Dockerfile ^
%last_arg%

docker build ^
--build-arg ONEC_USERNAME=%ONEC_USERNAME% ^
--build-arg ONEC_PASSWORD=%ONEC_PASSWORD% ^
--build-arg EDT_VERSION=%EDT_VERSION% ^
--build-arg BASE_IMAGE=%BASE_IMAGE% ^
--build-arg BASE_TAG=%BASE_TAG% ^
--build-arg DOCKER_REGISTRY_URL=%DOCKER_REGISTRY_URL% ^
--build-arg DOWNLOADER_IMAGE=oscript-downloader ^
--build-arg DOWNLOADER_TAG=latest ^
-t %DOCKER_REGISTRY_URL%/onec-client:%edt_escaped% ^
-f edt/Dockerfile ^
%last_arg%

if %ERRORLEVEL% neq 0 goto end
.\build-edt.bat

docker build ^
--build-arg DOCKER_REGISTRY_URL=%DOCKER_REGISTRY_URL% ^
Expand Down
Loading

0 comments on commit d016935

Please sign in to comment.