From bc094b8954b79d35fba6bf97814f4a18ebd7274e Mon Sep 17 00:00:00 2001 From: Roberto Berto Date: Sat, 8 Jun 2024 17:14:58 -0300 Subject: added a simple project starting point --- .env.example | 3 +++ Jenkinsfile | 39 +++++++++++++++++++++++++++++++++++++++ README.md | 44 +++++++++++++++++++++++++++++++++++++++++++- conf/distributions | 4 ++++ scripts/build_packages.sh | 23 +++++++++++++++++++++++ scripts/update_repo.sh | 21 +++++++++++++++++++++ scripts/upload_repo.sh | 22 ++++++++++++++++++++++ 7 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 .env.example create mode 100644 Jenkinsfile create mode 100644 conf/distributions create mode 100644 scripts/build_packages.sh create mode 100644 scripts/update_repo.sh create mode 100644 scripts/upload_repo.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d0327f1 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +BUCKET_NAME=your-bucket-name +AWS_PROFILE=vyos-apt +REPO_URL=https://github.com/vyos-contrib/vyos-apt.git diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..7dd07b7 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,39 @@ +pipeline { + agent any + triggers { + cron('0 18 * * *') // run daily on 18:00 + } + environment { + REPO_URL = credentials('repo-url') + } + stages { + stage('Checkout') { + steps { + git "${REPO_URL}" + } + } + stage('Build Packages') { + steps { + sh 'scripts/build_packages.sh' + } + } + stage('Update APT Repo') { + steps { + sh 'scripts/update_repo.sh' + } + } + stage('Upload to R2') { + steps { + withCredentials([string(credentialsId: 'aws-profile', variable: 'AWS_PROFILE')]) { + sh 'scripts/upload_repo.sh' + } + } + } + } + post { + always { + archiveArtifacts artifacts: '**/output/**/*.deb', allowEmptyArchive: true + cleanWs() + } + } +} diff --git a/README.md b/README.md index aa8b082..1016d3c 100644 --- a/README.md +++ b/README.md @@ -1 +1,43 @@ -# vyos-apt \ No newline at end of file +# vyos-apt + +This repository contains the configuration and scripts necessary to build VyOS packages and update an APT repository automatically using Jenkins. It also includes steps to upload the repository to Cloudflare R2. + +## Directory Structure + +- `Jenkinsfile`: Jenkins pipeline configuration. +- `scripts/build_packages.sh`: Script to build VyOS packages. +- `scripts/update_repo.sh`: Script to update the APT repository. +- `scripts/upload_repo.sh`: Script to upload the repository to Cloudflare R2. +- `conf/distributions`: APT repository configuration. +- `.env.example`: Example environment configuration file. + +## How to Use + +1. **Set Up a Jenkins Server:** + Install Jenkins on your server. Follow the [Jenkins installation guide](https://www.jenkins.io/doc/book/installing/) for detailed instructions. + +2. **Create a New Pipeline Job in Jenkins:** + - In Jenkins, create a new pipeline job and point it to this repository. + - Configure the job to use the `Jenkinsfile` provided in this repository. + +3. **Configure Cloudflare R2:** + - Set up a Cloudflare R2 bucket. + - Configure your AWS CLI with a profile for Cloudflare R2. + +4. **Create a `.env` File:** + - Create a `.env` file in the root of this repository based on the `.env.example` file. + - Fill in the necessary details such as `BUCKET_NAME`, `AWS_PROFILE`, and `REPO_URL`. + +5. **Run the Pipeline:** + - The pipeline will automatically build the VyOS packages daily, update the APT repository, and upload the repository to Cloudflare R2. + +## Dependencies + +- Jenkins +- reprepro +- debuild +- AWS CLI + +## Contributions + +Feel free to contribute improvements and new packages! diff --git a/conf/distributions b/conf/distributions new file mode 100644 index 0000000..b5bcfba --- /dev/null +++ b/conf/distributions @@ -0,0 +1,4 @@ +Codename: debian-12 +Suite: stable +Components: main +Architectures: amd64 diff --git a/scripts/build_packages.sh b/scripts/build_packages.sh new file mode 100644 index 0000000..3141a32 --- /dev/null +++ b/scripts/build_packages.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +# packages to build +packages=("keepalived" "ethtool") + +WORKDIR=$(pwd) + +git clone https://github.com/vyos/vyos-build.git +cd vyos-build/packages + + +# build each package +for pkg in "${packages[@]}"; do + cd "$pkg" + debuild -b -us -uc + cd .. +done + +# copy the packages to the output directory +mkdir -p "$WORKDIR/output" +cp ../*.deb "$WORKDIR/output" diff --git a/scripts/update_repo.sh b/scripts/update_repo.sh new file mode 100644 index 0000000..606bf43 --- /dev/null +++ b/scripts/update_repo.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e + +WORKDIR=$(pwd) + +REPO_DIR="$WORKDIR/apt-repo" + +# create necessary directories +mkdir -p "$REPO_DIR/{conf,dists,incoming,indices,pool,db}" + +# repo configuration +cat > "$REPO_DIR/conf/distributions" < /dev/null +then + echo "AWS CLI not found, installing..." + pip install awscli +fi + +# Configure AWS CLI to use the specified profile +export AWS_PROFILE=$AWS_PROFILE + +# Upload the APT repository to Cloudflare R2 +aws s3 sync "$WORKDIR/apt-repo" "s3://$BUCKET_NAME" --delete \ No newline at end of file -- cgit v1.2.3