diff --git a/.github/workflows/build-homarr.yml b/.github/workflows/build-homarr.yml index 580fbd3..8be9eda 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: @@ -6,80 +6,38 @@ on: - main - dev 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 + - '.github/workflows/builder.yml' + - '.github/publish_build.hurl' + - '.github/workflows/build-homarr.yml' + - 'templates/homarr.yml' + schedule: + - cron: '0 */23 * * *' jobs: - build: - strategy: - matrix: - distribution: - - debian - architecture: - - amd64 - release: - - bookworm + init: runs-on: ubuntu-latest - steps: - - name: Install Distrobuilder and other tools + - name: Get Application version + id: get-app-version 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 + echo "APP_VERSION=$(curl -s https://raw.githubusercontent.com/ajnart/homarr/master/package.json | jq -r '.version')" >> $GITHUB_OUTPUT + outputs: + app_version: ${{steps.get-app-version.outputs.APP_VERSION}} - - 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}} + image-build: + needs: init + strategy: + matrix: + architectures: + - amd64 + uses: ./.github/workflows/builder.yml + with: + config_path: templates/homarr.yml + app_name: homarr + app_version: ${{needs.init.outputs.app_version}} + project_source: https://github.com/ajnart/homarr + distribution: debian + release: bookworm + architecture: ${{matrix.architectures}} + 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..f95664a --- /dev/null +++ b/.github/workflows/build-tester.yml @@ -0,0 +1,25 @@ +name: Test Build + +on: + pull_request: + branches: + - main + - dev + paths: + - '.github/workflows/builder.yml' + - '.github/publish_build.hurl' + - '.github/workflows/tester.yml' + +jobs: + image-build: + uses: ./.github/workflows/builder.yml + with: + config_path: templates/homarr.yml + app_name: dummy_app # using the homarr config for tests + app_version: '0.15.0' + project_source: https://github.com/soubinan/homelab-lxc + distribution: debian + release: bookworm + architecture: amd64 + branch_name: dev + is_merged: false diff --git a/.github/workflows/builder.yml b/.github/workflows/builder.yml new file mode 100644 index 0000000..9746c26 --- /dev/null +++ b/.github/workflows/builder.yml @@ -0,0 +1,91 @@ +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/${{inputs.app_name}} + mkdir -p /tmp/cache/${{inputs.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: Check out repository + uses: actions/checkout@v4 + + - name: Build Image + run: | + sudo distrobuilder --cache-dir /tmp/cache/${{inputs.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${{inputs.app_version}}" -o source.url="http://ftp.us.debian.org/debian" /tmp/output/${{inputs.app_name}}/ + mv /tmp/output/${{inputs.app_name}}/rootfs.tar.xz ./${{inputs.app_name}}-${{inputs.app_version}}-${{inputs.architecture}}.tar.xz + mv /tmp/output/${{inputs.app_name}}/meta.tar.xz ./${{inputs.app_name}}-${{inputs.app_version}}-${{inputs.architecture}}-meta.tar.xz + echo "ARTIFACT_SIZE=$(du -sh ./${{inputs.app_name}}-${{inputs.app_version}}-${{inputs.architecture}}.tar.xz| cut -f 1)" >> $GITHUB_ENV + pwd && ls -lash + env: + CONFIG_PATH: ${{inputs.config_path}} + + - name: Publish Image files + if: github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true + run: | + rclone copy ./${{inputs.app_name}}-${{inputs.app_version}}-${{inputs.architecture}}.tar.xz cloudflare:lxc-images --config /tmp/rclone.conf + rclone copy ./${{inputs.app_name}}-${{inputs.app_version}}-${{inputs.architecture}}-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 + 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=${{inputs.app_name}} --variable app_version=${{inputs.app_version}} \ + --variable arch=${{inputs.architecture}} --variable dist=${{inputs.distribution}} \ + --variable dist_release=${{inputs.release}} --variable build_id=${{inputs.app_name}}-${{inputs.app_version}}-${{inputs.architecture}}.tar.xz\ + --variable size=$ARTIFACT_SIZE --variable source=${{inputs.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}}