diff --git a/builder_docker/Dockerfile b/builder_docker/Dockerfile deleted file mode 100644 index 0024e09a..00000000 --- a/builder_docker/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -# for alpine use apk - -FROM debian - -ENV DEBIAN_FRONTEND 'noninteractive' -ENV LANG 'C.UTF-8' -ENV LC_ALL 'C.UTF-8' - -RUN apt-get update -qq > /dev/null -RUN apt-get install -y --no-install-recommends -qq bc jq unzip wget parted apt-utils git ca-certificates gawk > /dev/null -RUN apt-get clean - -COPY ./*.sh /builder/ -COPY ./qemu-arm-resin /builder/qemu-arm-resin - -WORKDIR /builder -CMD ./repo/builder/image-build.sh diff --git a/builder_docker/README.md b/builder_docker/README.md deleted file mode 100644 index c9f48ec3..00000000 --- a/builder_docker/README.md +++ /dev/null @@ -1,130 +0,0 @@ -## Setup your builder - -1. Install requirements - ```bash - sudo apt-get install unzip zip git python-pip jq curl - sudo pip install YaDiskClient - ``` -2. Mount HDD - ```bash - nano /etc/fstab - ``` - ``` - proc /proc proc defaults 0 0 - PARTUUID=37665771-01 /boot vfat defaults 0 2 - PARTUUID=37665771-02 / ext4 defaults,noatime 0 1 - # a swapfile is not a swap partition, no line here - # use dphys-swapfile swap[on|off] for that - /dev/sdb1 none swap sw 0 0 - /dev/sdb2 /mnt/hdd_system ext4 defaults,acl 0 0 - /dev/sdb3 /mnt/hdd_builder ext4 defaults,acl 0 0 - ``` - -3. Enable swap on HDD - > TODO -4. And disable `dphys-swapfile` - ```bash - sudo systemctl stop dphys-swapfile - sudo systemctl disable dphys-swapfile - ``` -5. Create /mnt/hdd_builder/workspace/coex-ci.json - ```(json) - { - "yadisk": - { - "login":"LOGIN", - "password":"PASS", - "server_dir":"/clever_images" - }, - "github": - { - "login":"LOGIN", - "password":"PASS", - "url":"https://api.github.com/repos/CopterExpress/clever/releases/" - } - } - ``` -6. Add webhook to release on your github project - > TODO -7. Install Jenkins - > Manual https://www.digitalocean.com/community/tutorials/how-to-install-jenkins-on-ubuntu-16-04 -8. Change user & group invoked Jenkins - ```bash - sudo sed -i 's/JENKINS_USER=$NAME/JENKINS_USER=root/' /etc/default/jenkins - sudo sed -i 's/JENKINS_GROUP=$NAME/JENKINS_GROUP=root/' /etc/default/jenkins - ``` -9. Install Jenikins plugins - > Pipeline, Git SCM, Matrix Authorization, github-webhook-build-trigger-plugin -10. Create Jenkins pipeline job - > TODO -11. Configure Jenkins - > TODO: Matrix autorization, GIT Token -12. Add Jenkins service to autostart - ```bash - sudo systemctl enable jenkins - ``` -13. Start service - ```bash - sudo systemctl start jenkins - ``` - -## Requirements - -* Jenkins (BlueOcean plugin, optional) - -## Troubleshooting - -If JDK not installed: - -```bash -sudo apt-get install default-jdk -``` - -## Для использования execute в качестве mount_image - -```bash -./image_config.sh execute $IMAGE_PATH << EOF -uname -a -EOF -``` - -## Running the Docker - -```bash -docker run --privileged -it --rm -v /dev:/dev -v $(pwd)/image:/builder/image smirart/builder -``` - -## TODO - -* Change http на https в jenkins plugins -* Add finally block for disconnect image -* In Jenkins build call by name - change - -**image-chroot** - -* Добавить отмонтирование образа при возникновении ошибке -* проверка на существование образа и скрипта если тот задан (кстати скрипт копируется перед исполнением, модет подумать как сопрягать с copytochroot) - -**image-build** - -* должна смотреть в текущую папку -* проверка на существование файла инструкций -* Тоесть по сути должен быть отдельный скрипт для скачивания репы, если таковой не имеется -* Идея для билдера: добавить в Volume репу с инструкциями. И делать лишь git fetch, git pull, git checkout -* Сделать так, чтобы в текущей папке все собиралось и работало: - 1. Если это репозиторий (как передавать доступ в папку?) - 2. Брать имя репы, ветку или бренчу и коммит из файлов репы - 3. Обеспечить возможность работы с удаленным репозиторием в качестве источника инструкций (может сделать переход по коммиту или еще что-то подобное) - -**image-resize free-space** - -## Варнинги Jenkins - -```log -[WARNING] The POM for org.jenkins-ci.tools:maven-hpi-plugin:jar:2.0 is missing, no dependency information available -[WARNING] Failed to build parent project for io.codeclou.jenkins.github.webhook.build.trigger.plugin:github-webhook-build-trigger-plugin:hpi:1.2.0 -``` - -* https://yandex.ru/search/?text=The%20POM%20for%20org.jenkins-ci.tools%3Amaven-hpi-plugin%3Ajar%3A2.0%20is%20missing%2C%20no%20dependency%20information%20available&&lr=213 -* http://jenkins-ci.361315.n4.nabble.com/Plugin-org-jenkins-ci-tools-maven-hpi-plugin-td4751140.html -* http://qaru.site/questions/1460710/maven-jenkins-plugin-poms-missing-for-dependency-information-on-jars diff --git a/builder_docker/image-chroot.sh b/builder_docker/image-chroot.sh deleted file mode 100755 index 82ed37d2..00000000 --- a/builder_docker/image-chroot.sh +++ /dev/null @@ -1,184 +0,0 @@ -#! /usr/bin/env bash - -# -# Script for upload the image to yadisk & change the release message on GitHub -# Copyright (C) 2018 Copter Express Technologies -# -# Author: Artem Smirnov -# Author: Andrey Dvornikov -# -# Distributed under MIT License (available at https://opensource.org/licenses/MIT). -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# - -set -e # Exit immidiately on non-zero result - -echo_stamp() { - # TEMPLATE: echo_stamp - # TYPE: SUCCESS, ERROR, INFO - - # More info there https://www.shellhacks.com/ru/bash-colors/ - - TEXT="$(date '+[%Y-%m-%d %H:%M:%S]') $1" - TEXT="\e[1m$TEXT\e[0m" # BOLD - - case "$2" in - SUCCESS) - TEXT="\e[32m${TEXT}\e[0m";; # GREEN - ERROR) - TEXT="\e[31m${TEXT}\e[0m";; # RED - *) - TEXT="\e[34m${TEXT}\e[0m";; # BLUE - esac - echo -e ${TEXT} -} - -# This script doesn't work on Ubuntu because OS`s losetup does not consist --partscan (-P). - -# Idea: use `mount -o loop,offset` -# https://stefanoprenna.com/blog/2014/09/22/tutorial-how-to-mount-raw-images-img-images-on-linux/ -# REPO_DIR=$(mktemp -d --suffix=.builder_repo) -# mount -t ext4 -o loop,offset=$((94208 * 512)) image/clever_qemu_test_2_20180822_163141.img "$REPO_DIR" -# mount -t vfat -o loop,offset=$((8192 * 512)) image/clever_qemu_test_2_20180822_163141.img "$REPO_DIR/boot" - -execute() { - # execute [ [...]] - - echo_stamp "Mount loop-image: $1" - local DEV_IMAGE=$(losetup -Pf $1 --show) - sleep 0.5 - - local MOUNT_POINT=$(mktemp -d --suffix=.builder_image) - echo_stamp "Mount dirs ${MOUNT_POINT} & ${MOUNT_POINT}/boot" - mount "${DEV_IMAGE}p2" ${MOUNT_POINT} - mount "${DEV_IMAGE}p1" ${MOUNT_POINT}/boot - - REGISTER=':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' - if [[ $(arch) != 'armv7l' ]]; then - echo_stamp "Enable qemu-arm-static" - mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc 2> /dev/null || true - echo ${REGISTER} > /proc/sys/fs/binfmt_misc/register 2> /dev/null || true - cp './qemu-arm-resin' "${MOUNT_POINT}/usr/bin/qemu-arm-static" - else echo_stamp "qemu-arm-static is not need" - fi - - echo_stamp "Bind system dirs" - - echo_stamp "Mounting /proc in chroot... " - if [ ! -d ${MOUNT_POINT}/proc ]; then - mkdir -p ${MOUNT_POINT}/proc \ - && mount -t proc -o nosuid,noexec,nodev proc ${MOUNT_POINT}/proc \ - && echo_stamp "OK" "SUCCESS" \ - || (echo_stamp "Failed" "ERROR"; exit 1) - else echo_stamp "/proc already exist" "SUCCESS"; fi - - echo_stamp "Mounting /sys in chroot... " - if [ ! -d ${MOUNT_POINT}/sys ]; then - mkdir -p ${MOUNT_POINT}/sys \ - && mount -t sysfs -o nosuid,noexec,nodev sysfs ${MOUNT_POINT}/sys \ - && echo_stamp "OK" "SUCCESS" \ - || (echo_stamp "Failed" "ERROR"; exit 1) - else echo_stamp "/sys already exist" "SUCCESS"; fi - - echo_stamp "Mounting /dev/ and /dev/pts in chroot... " \ - && mkdir -p -m 755 ${MOUNT_POINT}/dev/pts \ - && mount -t devtmpfs -o mode=0755,nosuid devtmpfs ${MOUNT_POINT}/dev \ - && mount -t devpts -o gid=5,mode=620 devpts ${MOUNT_POINT}/dev/pts \ - && echo_stamp "OK" "SUCCESS" \ - || (echo_stamp "Failed" "ERROR"; exit 1) - - echo_stamp "Copy DNS records" \ - && cp -L /etc/resolv.conf ${MOUNT_POINT}/etc/resolv.conf \ - && echo_stamp "OK" "SUCCESS" \ - || (echo_stamp "Failed" "ERROR"; exit 1) - - if [[ $# > 1 ]]; then - echo_stamp "Copy script to chroot fs" - - local SCRIPT_NAME="$(basename $2).$(tr -dc 'A-F0-9' < /dev/urandom | dd bs=1 count=7 2>/dev/null)" - local SCRIPT_DIR="${MOUNT_POINT}/root" - - cp "$2" "${SCRIPT_DIR}/${SCRIPT_NAME}" - # Run script in chroot with additional arguments - chroot ${MOUNT_POINT} /bin/sh -c "/root/${SCRIPT_NAME} ${@:3}" - # Removing script from chroot fs - rm "${SCRIPT_DIR}/${SCRIPT_NAME}" - else - # https://wiki.archlinux.org/index.php/Change_root_(%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9) - # http://www.unix-lab.org/posts/chroot/ - # https://habrahabr.ru/post/141012/ - # https://losst.ru/vosstanovlenie-grub2 - # http://unixteam.ru/content/virtualizaciya-ili-zapuskaem-prilozhenie-v-chroot-okruzhenii-razmyshleniya - # http://help.ubuntu.ru/wiki/%D0%B2%D0%BE%D1%81%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5_grub - echo_stamp "Entering to chroot" \ - && chroot ${MOUNT_POINT} /bin/bash - fi - - umount_system ${MOUNT_POINT} ${DEV_IMAGE} -} - -umount_system() { - # TEMPLATE: umount_system - - echo_stamp "Unmount chroot rootfs and boot partition: $1" - umount_ok=false - # Repeat 5 times - for i in {1..5}; do - umount -fR $1 \ - && umount_ok=true && break \ - || (echo_stamp "Failed #$i (try 5 times)" "ERROR"; sleep 2) - done - [[ "$umount_ok" == true ]] && echo_stamp "OK" "SUCCESS" \ - || (echo_stamp "Umount loop-image was failed" "ERROR"; exit 1) - losetup -d $2 -} - -copy_to_chroot() { - # copy_to_chroot - - echo_stamp "Mount loop-image: $1" - local DEV_IMAGE=$(losetup -Pf $1 --show) - sleep 0.5 - - local MOUNT_POINT=$(mktemp -d --suffix=.builder_image) - echo_stamp "Mount dirs ${MOUNT_POINT} & ${MOUNT_POINT}/boot" - mount "${DEV_IMAGE}p2" ${MOUNT_POINT} - mount "${DEV_IMAGE}p1" ${MOUNT_POINT}/boot - - local dir_name=$(dirname "${MOUNT_POINT}$3 /") - - [[ ! -d ${dir_name} ]] && mkdir -p ${dir_name} \ - && echo_stamp "Created ${dir_name}" "SUCCESS" - - cp -r "$2" "${MOUNT_POINT}$3" - umount_system ${MOUNT_POINT} ${DEV_IMAGE} -} - -if [ $(whoami) != "root" ]; then - echo "" - echo "********************************************************************" - echo "******************** This should be run as root ********************" - echo "********************************************************************" - echo "" - exit 1 -fi - -echo "================================================================================" -for ((i=0; i<=$#; i++)); do echo "\$$i: ${!i}"; done -echo "================================================================================" - -if [[ $# > 0 ]]; then - [[ -f $1 ]] || (echo_stamp "$1 does not exist" "ERROR"; echo "Template: image-chroot.sh [ exec