From 7f810b2937942f31c78d3b6c7e66237e57d2914d Mon Sep 17 00:00:00 2001 From: Soubinan Date: Wed, 28 Feb 2024 02:45:02 -0500 Subject: [PATCH 1/7] update homarr action --- .github/workflows/build_template.yml | 40 +++++++++++++++++----------- templates/homarr.yaml | 1 - 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build_template.yml b/.github/workflows/build_template.yml index 8115f9b..ac9337a 100644 --- a/.github/workflows/build_template.yml +++ b/.github/workflows/build_template.yml @@ -4,12 +4,13 @@ on: push: branches: ["main"] pull_request: - branches: ["dev"] + branches: + - main + - dev env: PROJECT_URL: https://github.com/soubinan/homelab-lxc AUTHOR: https://github.com/soubinan - VERSION: 1.0.1 jobs: build: @@ -22,24 +23,33 @@ jobs: steps: - name: Install Distrobuilder run: | - apt update - apt install -y golang-go debootstrap rsync gpg squashfs-tools git make - mkdir -p $HOME/go/src/github.com/lxc/ - cd $HOME/go/src/github.com/lxc/ - git clone https://github.com/lxc/distrobuilder - cd ./distrobuilder - make - cp $HOME/go/bin/distrobuilder /usr/bin/distrobuilder - mkdir /output + sudo apt-get install debootstrap squashfs-tools + sudo snap install distrobuilder --classic + # sudo apt-get update -y + # sudo apt-get install -y golang-go debootstrap rsync gpg squashfs-tools git make + # mkdir -p $HOME/go/src/github.com/lxc/ + # cd $HOME/go/src/github.com/lxc/ + # git clone https://github.com/lxc/distrobuilder + # cd ./distrobuilder + # sudo make + # cp $HOME/go/bin/distrobuilder /usr/bin/distrobuilder + mkdir $HOME/output + + - name: Get Homarr version + run: | + echo "HOMARR_VERSION="$(curl -s https://raw.githubusercontent.com/ajnart/homarr/master/package.json | jq -r ".version") >> $GITHUB_ENV + + - name: Check out repository code + uses: actions/checkout@v4 - name: Build Image if: github.event_name == 'pull_request' run: | - pwd - distrobuilder build-lxc templates/homarr.yaml -o image.architecture=${{ matrix.architecture }} -o image.release=${{ matrix.release }} -o image.variant=cloud -o source.url="http://ftp.us.debian.org/debian" /output + sudo distrobuilder build-lxc ${{ github.workspace }}/templates/homarr.yaml -o image.architecture=${{ matrix.architecture }} -o image.release=${{ matrix.release }} -o image.variant=cloud -o source.url="http://ftp.us.debian.org/debian" $HOME/output + ls -lash $HOME/output - name: Publish Artefacts if: github.event_name == 'push' run: | - mv /output/rootfs.tar.xz /output/homarr-$VERSION.rootfs.tar.xz - mv /output/meta.tar.xz /output/homarr-$VERSION.meta.tar.xz + mv $HOME/output/rootfs.tar.xz /output/homarr-$HOMARR_VERSION.rootfs.tar.xz + mv $HOME/output/meta.tar.xz /output/homarr-$HOMARR_VERSION.meta.tar.xz diff --git a/templates/homarr.yaml b/templates/homarr.yaml index c3a11e2..c8b5921 100644 --- a/templates/homarr.yaml +++ b/templates/homarr.yaml @@ -1,4 +1,3 @@ -# -o image.architecture=amd64 -o image.release=bookworm -o image.variant=cloud -o source.url="http://ftp.us.debian.org/debian" image: distribution: debian release: stable From 1c2032ffb3977fea67e26aa89916e4cc8f1e67e1 Mon Sep 17 00:00:00 2001 From: Soubinan Date: Mon, 4 Mar 2024 23:46:28 -0500 Subject: [PATCH 2/7] Update homarr build workflow --- .github/workflows/build-homarr.yml | 58 ++++++++++++++++++++++++++++ .github/workflows/build_template.yml | 55 -------------------------- 2 files changed, 58 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/build-homarr.yml delete mode 100644 .github/workflows/build_template.yml diff --git a/.github/workflows/build-homarr.yml b/.github/workflows/build-homarr.yml new file mode 100644 index 0000000..0739ebe --- /dev/null +++ b/.github/workflows/build-homarr.yml @@ -0,0 +1,58 @@ +name: Homarr + +on: + pull_request: + branches: + - main + - dev + +env: + PROJECT_URL: https://github.com/soubinan/homelab-lxc + PROJECT_SOURCE: https://github.com/ajnart/homarr + AUTHOR: https://github.com/soubinan + APP_NAME: homarr + +jobs: + build: + strategy: + matrix: + distribution: + - debian + architecture: + - amd64 + release: + - bookworm + runs-on: ubuntu-latest + + steps: + - name: Install Distrobuilder + run: | + sudo apt-get install -y debootstrap squashfs-tools jq + sudo snap install distrobuilder --classic + mkdir $HOME/output/$APP_NAME + mkdir /tmp/cache/$APP_NAME + curl --location --remote-name --url "$(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 + + - name: Get application version + run: | + echo "APP_VERSION="$(curl -s $PROJECT_SOURCE/master/package.json | jq -r ".version") >> $GITHUB_ENV + + - name: Check out repository code + 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=$APP_VERSION -o source.url="http://ftp.us.debian.org/debian" $HOME/output/$APP_NAME/ + mv $HOME/output/$APP_NAME/rootfs.tar.xz $HOME/output/$APP_NAME/$APP_NAME-$APP_VERSION.tar.xz + mv $HOME/output/$APP_NAME/meta.tar.xz $HOME/output/$APP_NAME/$APP_NAME-$APP_VERSION-meta.tar.xz + ls -lash $HOME/output/* + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: $APP_NAME-$APP_VERSION + path: $HOME/output/$APP_NAME/$APP_NAME-$APP_VERSION* + retention-days: 45 + overwrite: true diff --git a/.github/workflows/build_template.yml b/.github/workflows/build_template.yml deleted file mode 100644 index ac9337a..0000000 --- a/.github/workflows/build_template.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Container Image Build and Sign - -on: - push: - branches: ["main"] - pull_request: - branches: - - main - - dev - -env: - PROJECT_URL: https://github.com/soubinan/homelab-lxc - AUTHOR: https://github.com/soubinan - -jobs: - build: - strategy: - matrix: - architecture: [amd64] - release: ['bookworm'] - runs-on: ubuntu-latest - - steps: - - name: Install Distrobuilder - run: | - sudo apt-get install debootstrap squashfs-tools - sudo snap install distrobuilder --classic - # sudo apt-get update -y - # sudo apt-get install -y golang-go debootstrap rsync gpg squashfs-tools git make - # mkdir -p $HOME/go/src/github.com/lxc/ - # cd $HOME/go/src/github.com/lxc/ - # git clone https://github.com/lxc/distrobuilder - # cd ./distrobuilder - # sudo make - # cp $HOME/go/bin/distrobuilder /usr/bin/distrobuilder - mkdir $HOME/output - - - name: Get Homarr version - run: | - echo "HOMARR_VERSION="$(curl -s https://raw.githubusercontent.com/ajnart/homarr/master/package.json | jq -r ".version") >> $GITHUB_ENV - - - name: Check out repository code - uses: actions/checkout@v4 - - - name: Build Image - if: github.event_name == 'pull_request' - run: | - sudo distrobuilder build-lxc ${{ github.workspace }}/templates/homarr.yaml -o image.architecture=${{ matrix.architecture }} -o image.release=${{ matrix.release }} -o image.variant=cloud -o source.url="http://ftp.us.debian.org/debian" $HOME/output - ls -lash $HOME/output - - - name: Publish Artefacts - if: github.event_name == 'push' - run: | - mv $HOME/output/rootfs.tar.xz /output/homarr-$HOMARR_VERSION.rootfs.tar.xz - mv $HOME/output/meta.tar.xz /output/homarr-$HOMARR_VERSION.meta.tar.xz From a43833b313a08bd0fa3c9546b6ea3fed3f823ab1 Mon Sep 17 00:00:00 2001 From: Soubinan Date: Mon, 4 Mar 2024 23:47:52 -0500 Subject: [PATCH 3/7] Update Homarr distrobuilder for clean install during the build --- templates/{homarr.yaml => homarr.yml} | 90 +++++++++++++-------------- 1 file changed, 43 insertions(+), 47 deletions(-) rename templates/{homarr.yaml => homarr.yml} (99%) diff --git a/templates/homarr.yaml b/templates/homarr.yml similarity index 99% rename from templates/homarr.yaml rename to templates/homarr.yml index c8b5921..822f182 100644 --- a/templates/homarr.yaml +++ b/templates/homarr.yml @@ -1,6 +1,7 @@ image: distribution: debian release: stable + variant: default source: downloader: debootstrap @@ -1056,51 +1057,13 @@ files: HOSTNAME="127.0.0.1" DEFAULT_COLOR_SCHEME="dark" -- path: /opt/homarr/install.sh - generator: dump - mode: 0777 - content: |- - #!/bin/bash - set -eux - - mkdir /data - git clone https://github.com/ajnart/homarr /app - - cd /app - yarn install - cp /opt/homarr/settings.env .env - yarn build - cp -r drizzle/migrate/ migrate/ - cp tsconfig.json migrate/tsconfig.json - yarn db:migrate - cp -r .next/standalone/* . - chmod +x scripts/run.sh - touch .installed__ - -- path: /etc/systemd/system/homarr-install.service - generator: dump - mode: 0440 - content: |- - [Unit] - Description=Homarr Installer - After=network.target - ConditionPathExists=!/app/.installed__ - - [Service] - Type=oneshot - RemainAfterExit=yes - ExecStart=/opt/homarr/install.sh - - [Install] - WantedBy=multi-user.target - - path: /etc/systemd/system/homarr.service generator: dump mode: 0440 content: |- [Unit] Description=Homarr Dashboard - After=network.target homarr-install.service + After=network.target ConditionPathExists=/app/.installed__ [Service] @@ -1121,6 +1084,7 @@ packages: sets: - packages: - fuse + - locales - systemd-resolved - openssh-client - openssl @@ -1445,6 +1409,46 @@ actions: # Cleanup temporary shadow paths rm /etc/*- +- trigger: post-files + pongo: true + action: |- + #!/bin/bash + set -eux + + mkdir /data + git clone https://github.com/ajnart/homarr -b {{ image.serial }} --depth 1 /app + + cd /app + yarn install + cp /opt/homarr/settings.env .env + yarn build + rm -rf node_modules + NODE_ENV=production + yarn install + cp -r drizzle/migrate/ migrate/ + cp tsconfig.json migrate/tsconfig.json + touch migrate/yarn.lock + yarn db:migrate + yarn cache clean + cp -r .next/standalone/* . + chmod +x scripts/run.sh + touch .installed__ + +- trigger: post-files + action: |- + #!/bin/bash + set -eux + + systemctl enable homarr.service + + apt-get autoremove --purge + apt-get clean + + rm -rf /var/cache/apt/archives/*.deb + rm -rf /var/log/* + rm -rf /tmp/* + rm -rf /var/tmp/* + - trigger: post-files action: |- #!/bin/bash @@ -1467,13 +1471,5 @@ actions: releases: - bullseye -- trigger: post-files - action: |- - #!/bin/bash - set -eux - - systemctl enable homarr-install.service - systemctl enable homarr.service - mappings: architecture_map: debian From 48f97d574f018946e0e45eaafe5834a6a06ce491 Mon Sep 17 00:00:00 2001 From: Soubinan Date: Mon, 4 Mar 2024 23:55:03 -0500 Subject: [PATCH 4/7] Add apt update in the homarr workflow create an output directory in / instead of $HOME fix directory deep creation --- .github/publish_build.hurl | 47 ++++++++++++++++++++++++++++ .github/workflows/build-homarr.yml | 49 ++++++++++++++++++++++-------- 2 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 .github/publish_build.hurl diff --git a/.github/publish_build.hurl b/.github/publish_build.hurl new file mode 100644 index 0000000..23e3902 --- /dev/null +++ b/.github/publish_build.hurl @@ -0,0 +1,47 @@ +### create application +POST {{endpoint_url}} +Authorization: Bearer {{token}} + +```graphql +mutation CreateApplication { + createApplication(data: {name: "{{app_name}}", source: "{{source}}"}) { + id + } +} +``` + +### publish application +POST {{endpoint_url}} +Authorization: Bearer {{token}} + +```graphql +mutation PublishApplication { + publishApplication(where: {name: "{{app_name}}"}) { + id + } +} +``` + +### create build +POST {{endpoint_url}} +Authorization: Bearer {{token}} + +```graphql +mutation CreateBuild { + createBuild(data: {buildId: "{{build_id}}", size: "{{size}}", version: "{{app_name}}-{{app_version}}", architecture: "{{arch}}", distribution: "{{dist}}", distRelease: "{{dist_release}}", application: {connect: {name: "{{app_name}}"}}}) { + id + } +} +``` + +### publish build +POST {{endpoint_url}} +Authorization: Bearer {{token}} + +```graphql +mutation PublishBuild { + publishBuild(where: {version: "{{app_name}}-{{app_version}}"}) { + id + } +} +``` diff --git a/.github/workflows/build-homarr.yml b/.github/workflows/build-homarr.yml index 0739ebe..e274798 100644 --- a/.github/workflows/build-homarr.yml +++ b/.github/workflows/build-homarr.yml @@ -5,6 +5,9 @@ on: branches: - main - dev + paths: + - '**homarr.yml' + - '**.hurl' env: PROJECT_URL: https://github.com/soubinan/homelab-lxc @@ -25,34 +28,54 @@ jobs: runs-on: ubuntu-latest steps: - - name: Install Distrobuilder + - name: Install Distrobuilder and tools run: | - sudo apt-get install -y debootstrap squashfs-tools jq + sudo apt-get update -y + sudo apt-get install -y debootstrap squashfs-tools jq wget sudo snap install distrobuilder --classic - mkdir $HOME/output/$APP_NAME - mkdir /tmp/cache/$APP_NAME - curl --location --remote-name --url "$(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 + 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 - name: Get application version run: | - echo "APP_VERSION="$(curl -s $PROJECT_SOURCE/master/package.json | jq -r ".version") >> $GITHUB_ENV + echo "APP_VERSION=$(curl -s https://raw.githubusercontent.com/ajnart/homarr/master/package.json | jq -r '.version')" >> $GITHUB_ENV - - name: Check out repository code + - 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=$APP_VERSION -o source.url="http://ftp.us.debian.org/debian" $HOME/output/$APP_NAME/ - mv $HOME/output/$APP_NAME/rootfs.tar.xz $HOME/output/$APP_NAME/$APP_NAME-$APP_VERSION.tar.xz - mv $HOME/output/$APP_NAME/meta.tar.xz $HOME/output/$APP_NAME/$APP_NAME-$APP_VERSION-meta.tar.xz - ls -lash $HOME/output/* + 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: Upload Artifacts uses: actions/upload-artifact@v4 + id: upload-artifact with: - name: $APP_NAME-$APP_VERSION - path: $HOME/output/$APP_NAME/$APP_NAME-$APP_VERSION* + name: ${{env.APP_NAME}}-${{env.APP_VERSION}}-${{matrix.architecture}} + path: | + ./${{env.APP_NAME}}-${{env.APP_VERSION}}.tar.xz + ./${{env.APP_NAME}}-${{env.APP_VERSION}}-meta.tar.xz retention-days: 45 overwrite: true + + - 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=$BUILD_ID \ + --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}} + BUILD_ID: ${{steps.upload-artifact.outputs.artifact-id}} From 4633fb3d63c46ee9c9d270c61def72942675ca25 Mon Sep 17 00:00:00 2001 From: Soubinan Date: Thu, 7 Mar 2024 01:53:04 -0500 Subject: [PATCH 5/7] replace GH artifacts with R2 --- .github/workflows/build-homarr.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-homarr.yml b/.github/workflows/build-homarr.yml index e274798..08c9cdc 100644 --- a/.github/workflows/build-homarr.yml +++ b/.github/workflows/build-homarr.yml @@ -54,23 +54,25 @@ jobs: echo "ARTIFACT_SIZE=$(du -sh ./$APP_NAME-$APP_VERSION.tar.xz| cut -f 1)" >> $GITHUB_ENV pwd && ls -lash - - name: Upload Artifacts - uses: actions/upload-artifact@v4 - id: upload-artifact + - name: Store RootFS file + uses: cloudflare/wrangler-action@v3 with: - name: ${{env.APP_NAME}}-${{env.APP_VERSION}}-${{matrix.architecture}} - path: | - ./${{env.APP_NAME}}-${{env.APP_VERSION}}.tar.xz - ./${{env.APP_NAME}}-${{env.APP_VERSION}}-meta.tar.xz - retention-days: 45 - overwrite: true + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + command: r2 object put lxc-images/${{env.APP_NAME}}-${{env.APP_VERSION}}.tar.xz -f ./${{env.APP_NAME}}-${{env.APP_VERSION}}.tar.xz + postCommands: + + - name: Store Meta file + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + command: r2 object put lxc-images/${{env.APP_NAME}}-${{env.APP_VERSION}}-meta.tar.xz -f ./${{env.APP_NAME}}-${{env.APP_VERSION}}-meta.tar.xz - 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=$BUILD_ID \ + --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 @@ -78,4 +80,3 @@ jobs: env: HOMELAB_LXC_EP: ${{secrets.HOMELAB_LXC_EP}} HOMELAB_LXC_TOKEN: ${{secrets.HOMELAB_LXC_TOKEN}} - BUILD_ID: ${{steps.upload-artifact.outputs.artifact-id}} From c870609a662422d58873b6777cc205ce7deedc14 Mon Sep 17 00:00:00 2001 From: Soubinan Date: Thu, 7 Mar 2024 04:29:05 -0500 Subject: [PATCH 6/7] Use RClone for image pushes --- .github/workflows/build-homarr.yml | 31 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-homarr.yml b/.github/workflows/build-homarr.yml index 08c9cdc..580fbd3 100644 --- a/.github/workflows/build-homarr.yml +++ b/.github/workflows/build-homarr.yml @@ -28,15 +28,22 @@ jobs: runs-on: ubuntu-latest steps: - - name: Install Distrobuilder and tools + - name: Install Distrobuilder and other tools run: | sudo apt-get update -y - sudo apt-get install -y debootstrap squashfs-tools jq wget + 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: | @@ -54,18 +61,14 @@ jobs: echo "ARTIFACT_SIZE=$(du -sh ./$APP_NAME-$APP_VERSION.tar.xz| cut -f 1)" >> $GITHUB_ENV pwd && ls -lash - - name: Store RootFS file - uses: cloudflare/wrangler-action@v3 - with: - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - command: r2 object put lxc-images/${{env.APP_NAME}}-${{env.APP_VERSION}}.tar.xz -f ./${{env.APP_NAME}}-${{env.APP_VERSION}}.tar.xz - postCommands: - - - name: Store Meta file - uses: cloudflare/wrangler-action@v3 - with: - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - command: r2 object put lxc-images/${{env.APP_NAME}}-${{env.APP_VERSION}}-meta.tar.xz -f ./${{env.APP_NAME}}-${{env.APP_VERSION}}-meta.tar.xz + - 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: | From c63827a9775319d56abea967e97992595b10dcf2 Mon Sep 17 00:00:00 2001 From: Soubinan Date: Fri, 8 Mar 2024 03:54:49 -0500 Subject: [PATCH 7/7] Transform the build workflow into a reusable one and add callers --- .github/workflows/build-homarr.yml | 102 +++++++++-------------------- .github/workflows/build-tester.yml | 25 +++++++ .github/workflows/builder.yml | 91 +++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 72 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..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}}