From 51ad707018a808acae9f47691de9f58fbf301789 Mon Sep 17 00:00:00 2001 From: dernasherbrezon Date: Mon, 24 Jun 2024 22:01:17 +0100 Subject: [PATCH] migrate main build to jenkins --- .github/workflows/cmake.yml | 44 -------------- Jenkinsfile | 114 ++++++++++++++++++++++++++---------- build_and_deploy.sh | 25 -------- configure_agent.sh | 17 ------ docker/bionic.Dockerfile | 6 ++ docker/bookworm.Dockerfile | 6 ++ docker/build_all.sh | 10 +++- docker/bullseye.Dockerfile | 6 ++ docker/buster.Dockerfile | 2 +- docker/focal.Dockerfile | 6 ++ docker/jammy.Dockerfile | 6 ++ docker/stretch.Dockerfile | 2 +- 12 files changed, 122 insertions(+), 122 deletions(-) delete mode 100755 build_and_deploy.sh delete mode 100755 configure_agent.sh create mode 100644 docker/bionic.Dockerfile create mode 100644 docker/bookworm.Dockerfile create mode 100644 docker/bullseye.Dockerfile create mode 100644 docker/focal.Dockerfile create mode 100644 docker/jammy.Dockerfile diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index dfdf088..ad19925 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -3,14 +3,6 @@ name: CMake on: push: branches: [ "main" ] - pull_request: - branches: [ "main" ] - -env: - BASE_VERSION: "1.1" - DEBEMAIL: "gpg@r2cloud.ru" - DEBFULLNAME: "r2cloud" - jobs: build: name: Build and analyze @@ -50,39 +42,3 @@ jobs: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" - - name: Merge into OS-specific branches - run: | - git config user.email "$GITHUB_ACTOR@users.noreply.github.com" - git config user.name "$GITHUB_ACTOR" - git tag ${{ env.BASE_VERSION }}.${{ github.run_number }} - git push origin ${{ env.BASE_VERSION }}.${{ github.run_number }} - deploy: - name: Build, package and deploy - needs: build - strategy: - matrix: - hosts: [ubuntu-20.04, ubuntu-22.04] - cpu: ["nocpuspecific"] - runs-on: ${{ matrix.hosts }} - steps: - - name: Import GPG key - uses: crazy-max/ghaction-import-gpg@v5 - with: - gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.PASSPHRASE }} - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - name: Set env - run: echo "OS_CODENAME=$(lsb_release --codename --short)" >> $GITHUB_ENV - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - ref: '${{ env.OS_CODENAME }}' - - name: Configure agent - run: bash ./configure_agent.sh - - name: Build and deploy - run: bash ./build_and_deploy.sh ${{ matrix.cpu }} ${{ env.OS_CODENAME }} ${{ env.BASE_VERSION }} ${{ github.run_number }} F2DCBFDCA5A70917 diff --git a/Jenkinsfile b/Jenkinsfile index eef7660..f554511 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,45 +1,95 @@ pipeline { - agent none + agent any parameters { string(name: 'BASE_VERSION', defaultValue: '1.1', description: 'From https://github.com/dernasherbrezon/sdr-server/actions') string(name: 'BUILD_NUMBER', defaultValue: '77', description: 'From https://github.com/dernasherbrezon/sdr-server/actions') - } - environment { - GPG = credentials("GPG") - DEBEMAIL = 'gpg@r2cloud.ru' - DEBFULLNAME = 'r2cloud' + choice(name: 'DOCKER_IMAGE', choices: ['debian:stretch-slim', 'debian:buster-slim', 'debian:bullseye-slim', 'debian:bookworm-slim', 'ubuntu:jammy', 'ubuntu:bionic', 'ubuntu:focal'], description: 'From https://github.com/dernasherbrezon/sdr-server/actions') + choice(name: 'OS_ARCHITECTURE', choices: ['armhf', 'arm64', 'amd64'], description: 'From https://github.com/dernasherbrezon/sdr-server/actions') } stages { - stage('Package and deploy') { - matrix { - axes { - axis { - name 'OS_CODENAME' - values 'bullseye', 'stretch', 'buster', 'bookworm' - } - axis { - name 'CPU' - values 'nocpuspecific' - } + stage('Checkout') { + steps { + script { + env.OS_CODENAME = "${DOCKER_IMAGE}".split(':')[1].split('-')[0] } - agent { - label "${OS_CODENAME}" + git(url: 'git@github.com:dernasherbrezon/sdr-server.git', branch: "${OS_CODENAME}", credentialsId: 'github', changelog: false) + sh ''' + git config user.email "gpg@r2cloud.ru" + git config user.name "r2cloud" + git merge origin/main --no-edit + ''' + withCredentials([sshUserPrivateKey(credentialsId: 'github', keyFileVariable: 'SSH_KEY')]) { + sh ''' + GIT_SSH_COMMAND="ssh -i ${SSH_KEY}" git push --set-upstream origin ${OS_CODENAME} + ''' } - stages { - stage('Checkout') { - steps { - git(url: 'git@github.com:dernasherbrezon/sdr-server.git', branch: "${OS_CODENAME}", credentialsId: '5c8b3e93-0551-475c-9e54-1266242c8ff5', changelog: false) - } - } - stage('build and deploy') { - steps { - sh 'echo $GPG_PSW | /usr/lib/gnupg2/gpg-preset-passphrase -c C4646FB23638AE9010EB1F7F37A0505CF4C5B746' - sh 'echo $GPG_PSW | /usr/lib/gnupg2/gpg-preset-passphrase -c 9B66E29FF6DDAD62FA3F2570E02775B6EFAF6609' - sh "bash ./build_and_deploy.sh ${CPU} ${OS_CODENAME} ${params.BASE_VERSION} ${params.BUILD_NUMBER} ${GPG_USR}" - } - } + } + } + stage('build') { + agent { + docker { + image "sdrserver-${OS_CODENAME}-${OS_ARCHITECTURE}" + reuseNode true + args "--platform=linux/${OS_ARCHITECTURE}" } } + steps { + sh '''#!/bin/bash + set -e + . ./configure_flags.sh nocpuspecific + rm -rf build + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCPACK_DEBIAN_PACKAGE_VERSION=${BASE_VERSION}.${BUILD_NUMBER}~${OS_CODENAME} -DCUSTOM_ARCHITECTURE=${OS_ARCHITECTURE} .. + VERBOSE=1 make -j $(nproc) + cpack + ''' + } + } + stage('deploy') { + steps { + withCredentials([ + usernamePassword(credentialsId: 'gpg_pass', usernameVariable: 'gpg_pass_keyid', passwordVariable: 'gpg_pass'), + file(credentialsId: 'gpg', variable: 'gpg_file'), + file(credentialsId: 'gpg_passphrase', variable: 'gpg_passphrase'), + aws(credentialsId: 'aws')]) { + sh '''#!/bin/bash + set -e + . ./configure_flags.sh nocpuspecific + APT_CLI_VERSION="apt-cli-1.11" + if [ ! -f ${HOME}/${APT_CLI_VERSION}.jar ]; then + wget -O ${APT_CLI_VERSION}.jar.temp https://github.com/dernasherbrezon/apt-cli/releases/download/${APT_CLI_VERSION}/apt-cli.jar + mv ${APT_CLI_VERSION}.jar.temp ${HOME}/${APT_CLI_VERSION}.jar + fi + + java -jar ${HOME}/${APT_CLI_VERSION}.jar --url s3://${BUCKET} --component main --codename ${OS_CODENAME} --gpg-keyfile ${gpg_file} --gpg-keyname ${gpg_pass_keyid} --gpg-passphrase-file ${gpg_passphrase} save --patterns ./build/*.deb,./build/*.ddeb + + ''' + } + } + } + stage('test') { + agent { + docker { + image "${DOCKER_IMAGE}" + reuseNode true + args "--platform=linux/${OS_ARCHITECTURE} --pull always --user root" + } + } + steps { + sh '''#!/bin/bash + export DEBIAN_FRONTEND=noninteractive + cp ./docker/r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg + chmod 644 /etc/apt/trusted.gpg.d/r2cloud.gpg + if [ ${OS_CODENAME} == stretch ]; then + echo 'deb http://archive.debian.org/debian/ stretch main non-free contrib' > /etc/apt/sources.list + echo 'deb http://archive.debian.org/debian-security/ stretch/updates main non-free contrib' >> /etc/apt/sources.list + fi + echo "deb http://r2cloud.s3.amazonaws.com ${OS_CODENAME} main" >> /etc/apt/sources.list + echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic ${OS_CODENAME} main" >> /etc/apt/sources.list + apt update && apt-get install --no-install-recommends -y sdr-server + ''' + } } } } diff --git a/build_and_deploy.sh b/build_and_deploy.sh deleted file mode 100755 index e3beafc..0000000 --- a/build_and_deploy.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -set -e - -CPU=$1 -OS_CODENAME=$2 -BASE_VERSION=$3 -BUILD_NUMBER=$4 -GPG_KEYNAME=$5 -APT_CLI_VERSION="apt-cli-1.8" - -. ./configure_flags.sh ${CPU} - -git config user.email "gpg@r2cloud.ru" -git config user.name "r2cloud" -git merge origin/main --no-edit - -rm -f ../sdr-server_* -rm -f ../sdr-server-* -gbp dch --auto --debian-branch=${OS_CODENAME} --upstream-branch=main --new-version=${BASE_VERSION}.${BUILD_NUMBER}-${BUILD_NUMBER}~${OS_CODENAME} --git-author --distribution=unstable --commit < /dev/null -git push --set-upstream origin ${OS_CODENAME} -gbp buildpackage --git-ignore-new --git-upstream-tag=${BASE_VERSION}.${BUILD_NUMBER} --git-keyid=${GPG_KEYNAME} - -cd .. -java -jar ${HOME}/${APT_CLI_VERSION}.jar --url s3://${BUCKET} --component main --codename ${OS_CODENAME} --gpg-keyname ${GPG_KEYNAME} --gpg-arguments "--pinentry-mode,loopback" save --patterns ./*.deb,./*.ddeb diff --git a/configure_agent.sh b/configure_agent.sh deleted file mode 100755 index 1eaf47a..0000000 --- a/configure_agent.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -sudo apt-get update -sudo apt-get install -y dirmngr lsb-release -sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A5A70917 -sudo bash -c "echo \"deb http://r2cloud.s3.amazonaws.com $(lsb_release --codename --short) main\" > /etc/apt/sources.list.d/r2cloud.list" -sudo bash -c "echo \"deb http://r2cloud.s3.amazonaws.com/cpu-generic $(lsb_release --codename --short) main\" > /etc/apt/sources.list.d/r2cloud-generic.list" -sudo apt-get update -sudo apt-get install -y debhelper git-buildpackage cmake libconfig-dev valgrind check cmake pkg-config libvolk2-dev librtlsdr-dev - -APT_CLI_VERSION="apt-cli-1.8" -if [ ! -f ${HOME}/${APT_CLI_VERSION}.jar ]; then - wget -O ${APT_CLI_VERSION}.jar.temp https://github.com/dernasherbrezon/apt-cli/releases/download/${APT_CLI_VERSION}/apt-cli.jar - mv ${APT_CLI_VERSION}.jar.temp ${HOME}/${APT_CLI_VERSION}.jar -fi diff --git a/docker/bionic.Dockerfile b/docker/bionic.Dockerfile new file mode 100644 index 0000000..021cdf4 --- /dev/null +++ b/docker/bionic.Dockerfile @@ -0,0 +1,6 @@ +FROM ubuntu:bionic +ENV DEBIAN_FRONTEND noninteractive +COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg +RUN echo "deb http://r2cloud.s3.amazonaws.com bionic main" >> /etc/apt/sources.list +RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic bionic main" >> /etc/apt/sources.list +RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker/bookworm.Dockerfile b/docker/bookworm.Dockerfile new file mode 100644 index 0000000..eddceeb --- /dev/null +++ b/docker/bookworm.Dockerfile @@ -0,0 +1,6 @@ +FROM debian:bookworm-slim +ENV DEBIAN_FRONTEND noninteractive +COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg +RUN echo "deb http://r2cloud.s3.amazonaws.com bookworm main" >> /etc/apt/sources.list +RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic bookworm main" >> /etc/apt/sources.list +RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker/build_all.sh b/docker/build_all.sh index e6b891b..3630553 100644 --- a/docker/build_all.sh +++ b/docker/build_all.sh @@ -1,4 +1,10 @@ #!/usr/bin/env bash -docker build --platform=armhf -t sdrserver-buster -f buster.Dockerfile . -docker build --platform=armhf -t sdrserver-stretch -f stretch.Dockerfile . \ No newline at end of file +docker buildx build --load --platform=armhf -t sdrserver-buster-armhf -f buster.Dockerfile . +docker buildx build --load --platform=armhf -t sdrserver-stretch-armhf -f stretch.Dockerfile . +docker buildx build --load --platform=armhf -t sdrserver-bullseye-armhf -f bullseye.Dockerfile . +docker buildx build --load --platform=armhf -t sdrserver-bookworm-armhf -f bookworm.Dockerfile . +docker buildx build --load --platform=arm64 -t sdrserver-bookworm-arm64 -f bookworm.Dockerfile . +docker buildx build --load --platform=amd64 -t sdrserver-bionic-amd64 -f bionic.Dockerfile . +docker buildx build --load --platform=amd64 -t sdrserver-focal-amd64 -f focal.Dockerfile . +docker buildx build --load --platform=amd64 -t sdrserver-jammy-amd64 -f jammy.Dockerfile . diff --git a/docker/bullseye.Dockerfile b/docker/bullseye.Dockerfile new file mode 100644 index 0000000..0686c7a --- /dev/null +++ b/docker/bullseye.Dockerfile @@ -0,0 +1,6 @@ +FROM debian:bullseye-slim +ENV DEBIAN_FRONTEND noninteractive +COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg +RUN echo "deb http://r2cloud.s3.amazonaws.com bullseye main" >> /etc/apt/sources.list +RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic bullseye main" >> /etc/apt/sources.list +RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker/buster.Dockerfile b/docker/buster.Dockerfile index 43b9519..7eddc7f 100644 --- a/docker/buster.Dockerfile +++ b/docker/buster.Dockerfile @@ -3,4 +3,4 @@ ENV DEBIAN_FRONTEND noninteractive COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg RUN echo "deb http://r2cloud.s3.amazonaws.com buster main" >> /etc/apt/sources.list RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic buster main" >> /etc/apt/sources.list -RUN apt-get update && apt-get install --no-install-recommends -y build-essential valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/* \ No newline at end of file +RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker/focal.Dockerfile b/docker/focal.Dockerfile new file mode 100644 index 0000000..91bb05b --- /dev/null +++ b/docker/focal.Dockerfile @@ -0,0 +1,6 @@ +FROM ubuntu:focal +ENV DEBIAN_FRONTEND noninteractive +COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg +RUN echo "deb http://r2cloud.s3.amazonaws.com focal main" >> /etc/apt/sources.list +RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic focal main" >> /etc/apt/sources.list +RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker/jammy.Dockerfile b/docker/jammy.Dockerfile new file mode 100644 index 0000000..0f287b2 --- /dev/null +++ b/docker/jammy.Dockerfile @@ -0,0 +1,6 @@ +FROM ubuntu:jammy +ENV DEBIAN_FRONTEND noninteractive +COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg +RUN echo "deb http://r2cloud.s3.amazonaws.com jammy main" >> /etc/apt/sources.list +RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic jammy main" >> /etc/apt/sources.list +RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker/stretch.Dockerfile b/docker/stretch.Dockerfile index d1f717f..68c794d 100644 --- a/docker/stretch.Dockerfile +++ b/docker/stretch.Dockerfile @@ -5,4 +5,4 @@ RUN echo 'deb http://archive.debian.org/debian/ stretch main non-free contrib' > RUN echo 'deb http://archive.debian.org/debian-security/ stretch/updates main non-free contrib' >> /etc/apt/sources.list RUN echo "deb http://r2cloud.s3.amazonaws.com stretch main" >> /etc/apt/sources.list RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic stretch main" >> /etc/apt/sources.list -RUN apt-get update && apt-get install --no-install-recommends -y build-essential valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/* \ No newline at end of file +RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/* \ No newline at end of file