From 05dba4cc8624588cf65bca26c84efeb5dab108b4 Mon Sep 17 00:00:00 2001 From: Soubinan Date: Fri, 8 Mar 2024 03:54:49 -0500 Subject: [PATCH] Transform the build workflow into a reusable one and add callers --- .github/workflows/build-homarr.yml | 82 ++++++------------------- .github/workflows/build-tester.yml | 35 +++++++++++ .github/workflows/builder.yml | 99 ++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+), 63 deletions(-) create mode 100644 .github/workflows/build-tester.yml create mode 100644 .github/workflows/builder.yml diff --git a/.github/workflows/build-homarr.yml b/.github/workflows/build-homarr.yml index 580fbd3..cf2e238 100644 --- a/.github/workflows/build-homarr.yml +++ b/.github/workflows/build-homarr.yml @@ -1,4 +1,4 @@ -name: Homarr +name: Build Homarr LXC Image on: pull_request: @@ -8,78 +8,34 @@ on: paths: - '**homarr.yml' - '**.hurl' - -env: - PROJECT_URL: https://github.com/soubinan/homelab-lxc - PROJECT_SOURCE: https://github.com/ajnart/homarr - AUTHOR: https://github.com/soubinan - APP_NAME: homarr + # schedule: + # - cron: '0 */23 * * *' jobs: - build: + image-build: strategy: matrix: - distribution: + distributions: - debian - architecture: + architectures: - amd64 - release: + releases: - bookworm runs-on: ubuntu-latest - steps: - - name: Install Distrobuilder and other tools - run: | - sudo apt-get update -y - sudo apt-get install -y debootstrap squashfs-tools jq wget curl unzip - sudo snap install distrobuilder --classic - mkdir -p /tmp/output/$APP_NAME - mkdir -p /tmp/cache/$APP_NAME - wget $(curl -s https://api.github.com/repos/Orange-OpenSource/hurl/releases/latest |jq -r '.assets[] | select(.name|test("amd64.deb")) | .browser_download_url') -O /tmp/hurl_amd64.deb - sudo apt-get install -y /tmp/hurl_amd64.deb - sudo -v ; curl https://rclone.org/install.sh | sudo bash - - cat < /tmp/rclone.conf - $RCLONE_CONFIG - EOF - env: - RCLONE_CONFIG: ${{secrets.RCLONE_CONFIG}} - - name: Get application version run: | echo "APP_VERSION=$(curl -s https://raw.githubusercontent.com/ajnart/homarr/master/package.json | jq -r '.version')" >> $GITHUB_ENV - - name: Check out repository - uses: actions/checkout@v4 - - - name: Build Image - if: github.event_name == 'pull_request' - run: | - sudo distrobuilder --cache-dir /tmp/cache/$APP_NAME build-lxc ${{github.workspace}}/templates/${APP_NAME}.yml -o image.distribution=${{matrix.distribution}} -o image.architecture=${{matrix.architecture}} -o image.release=${{matrix.release}} -o image.serial="v${APP_VERSION}" -o source.url="http://ftp.us.debian.org/debian" /tmp/output/$APP_NAME/ - mv /tmp/output/$APP_NAME/rootfs.tar.xz ./$APP_NAME-$APP_VERSION.tar.xz - mv /tmp/output/$APP_NAME/meta.tar.xz ./$APP_NAME-$APP_VERSION-meta.tar.xz - echo "ARTIFACT_SIZE=$(du -sh ./$APP_NAME-$APP_VERSION.tar.xz| cut -f 1)" >> $GITHUB_ENV - pwd && ls -lash - - - name: Publish Image files - run: | - rclone copy ./$APP_NAME-$APP_VERSION.tar.xz cloudflare:lxc-images --config /tmp/rclone.conf - rclone copy ./$APP_NAME-$APP_VERSION-meta.tar.xz cloudflare:lxc-images --config /tmp/rclone.conf - echo - echo 'LXC Image published successfully !' - env: - RCLONE_CONFIG_PASS: ${{secrets.RCLONE_CONFIG_PASS}} - - - name: Publish build info - run: | - hurl --variable endpoint_url=$HOMELAB_LXC_EP --variable token=$HOMELAB_LXC_TOKEN \ - --variable app_name=$APP_NAME --variable app_version=$APP_VERSION \ - --variable arch=${{matrix.architecture}} --variable dist=${{matrix.distribution}} \ - --variable dist_release=${{matrix.release}} --variable build_id=${{env.APP_NAME}}-${{env.APP_VERSION}}.tar.xz\ - --variable size=$ARTIFACT_SIZE --variable source=$PROJECT_SOURCE\ - .github/publish_build.hurl - echo - echo 'LXC build published successfully !' - env: - HOMELAB_LXC_EP: ${{secrets.HOMELAB_LXC_EP}} - HOMELAB_LXC_TOKEN: ${{secrets.HOMELAB_LXC_TOKEN}} + - name: Build LXC Image + uses: ./.github/workflows/builder.yml + with: + config_path: templates/homarr.yml + app_name: homarr + app_version: $APP_VERSION + project_source: https://github.com/ajnart/homarr + distribution: ${{matrix.distributions}} + architecture: ${{matrix.architectures}} + release: ${{matrix.releases}} + branch_name: ${{github.event.pull_request.base.ref}} + is_merged: ${{github.event.pull_request.merged}} diff --git a/.github/workflows/build-tester.yml b/.github/workflows/build-tester.yml new file mode 100644 index 0000000..998f5c0 --- /dev/null +++ b/.github/workflows/build-tester.yml @@ -0,0 +1,35 @@ +name: Test Build + +on: + pull_request: + branches: + - main + - dev + paths: + - 'builder.yml' + - '**tester.yml' + +jobs: + image-build: + strategy: + matrix: + distributions: + - debian + architectures: + - amd64 + releases: + - bookworm + runs-on: ubuntu-latest + steps: + - name: Build LXC Image + uses: soubinan/homelab-lxc/.github/workflows/builder.yml + with: + config_path: templates/homarr.yml + app_name: dummy_app + app_version: 0.0.1 + project_source: https://github.com/soubinan/homelab-lxc + distribution: ${{matrix.distributions}} + architecture: ${{matrix.architectures}} + release: ${{matrix.releases}} + branch_name: dev + is_merged: false diff --git a/.github/workflows/builder.yml b/.github/workflows/builder.yml new file mode 100644 index 0000000..9c28376 --- /dev/null +++ b/.github/workflows/builder.yml @@ -0,0 +1,99 @@ +name: LXC Image Builder + +on: + workflow_call: + inputs: + config_path: + required: true + type: string + app_name: + required: true + type: string + app_version: + required: true + type: string + project_source: + required: true + type: string + distribution: + required: true + type: string + architecture: + required: true + type: string + release: + required: true + type: string + branch_name: + required: true + type: string + is_merged: + required: true + type: boolean + +jobs: + image-build: + runs-on: ubuntu-latest + steps: + - name: Install Distrobuilder and other tools + run: | + sudo apt-get update -y + sudo apt-get install -y debootstrap squashfs-tools jq wget curl unzip + sudo snap install distrobuilder --classic + mkdir -p /tmp/output/$APP_NAME + mkdir -p /tmp/cache/$APP_NAME + wget $(curl -s https://api.github.com/repos/Orange-OpenSource/hurl/releases/latest |jq -r '.assets[] | select(.name|test("amd64.deb")) | .browser_download_url') -O /tmp/hurl_amd64.deb + sudo apt-get install -y /tmp/hurl_amd64.deb + sudo -v ; curl https://rclone.org/install.sh | sudo bash + + cat < /tmp/rclone.conf + $RCLONE_CONFIG + EOF + env: + RCLONE_CONFIG: ${{secrets.RCLONE_CONFIG}} + APP_NAME: ${{inputs.app_name}} + + - name: Check out repository + uses: actions/checkout@v4 + + - name: Build Image + run: | + sudo distrobuilder --cache-dir /tmp/cache/$APP_NAME build-lxc ${{github.workspace}}/${CONFIG_PATH} -o image.distribution=${{inputs.distribution}} -o image.architecture=${{inputs.architecture}} -o image.release=${{inputs.release}} -o image.serial="v${APP_VERSION}" -o source.url="http://ftp.us.debian.org/debian" /tmp/output/$APP_NAME/ + mv /tmp/output/$APP_NAME/rootfs.tar.xz ./$APP_NAME-$APP_VERSION.tar.xz + mv /tmp/output/$APP_NAME/meta.tar.xz ./$APP_NAME-$APP_VERSION-meta.tar.xz + echo "ARTIFACT_SIZE=$(du -sh ./$APP_NAME-$APP_VERSION.tar.xz| cut -f 1)" >> $GITHUB_ENV + pwd && ls -lash + env: + CONFIG_PATH: ${{inputs.config_path}} + APP_NAME: ${{inputs.app_name}} + APP_VERSION: ${{inputs.app_version}} + + - name: Publish Image files + if: github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true + run: | + rclone copy ./$APP_NAME-$APP_VERSION.tar.xz cloudflare:lxc-images --config /tmp/rclone.conf + rclone copy ./$APP_NAME-$APP_VERSION-meta.tar.xz cloudflare:lxc-images --config /tmp/rclone.conf + echo + echo 'LXC Image published successfully !' + env: + RCLONE_CONFIG_PASS: ${{secrets.RCLONE_CONFIG_PASS}} + APP_NAME: ${{inputs.app_name}} + APP_VERSION: ${{inputs.app_version}} + + - name: Publish build info + if: inputs.branch_name == 'main' && inputs.is_merged == true + run: | + hurl --variable endpoint_url=$HOMELAB_LXC_EP --variable token=$HOMELAB_LXC_TOKEN \ + --variable app_name=$APP_NAME --variable app_version=$APP_VERSION \ + --variable arch=${{inputs.architecture}} --variable dist=${{inputs.distribution}} \ + --variable dist_release=${{inputs.release}} --variable build_id=${{env.APP_NAME}}-${{env.APP_VERSION}}.tar.xz\ + --variable size=$ARTIFACT_SIZE --variable source=$PROJECT_SOURCE\ + .github/publish_build.hurl + echo + echo 'LXC build published successfully !' + env: + HOMELAB_LXC_EP: ${{secrets.HOMELAB_LXC_EP}} + HOMELAB_LXC_TOKEN: ${{secrets.HOMELAB_LXC_TOKEN}} + PROJECT_SOURCE: ${{inputs.project_source}} + APP_NAME: ${{inputs.app_name}} + APP_VERSION: ${{inputs.app_version}}