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 new file mode 100644 index 0000000..8be9eda --- /dev/null +++ b/.github/workflows/build-homarr.yml @@ -0,0 +1,43 @@ +name: Build Homarr LXC Image + +on: + pull_request: + branches: + - main + - dev + paths: + - '.github/workflows/builder.yml' + - '.github/publish_build.hurl' + - '.github/workflows/build-homarr.yml' + - 'templates/homarr.yml' + schedule: + - cron: '0 */23 * * *' + +jobs: + init: + runs-on: ubuntu-latest + steps: + - name: Get Application version + id: get-app-version + run: | + 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}} + + 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/build_template.yml b/.github/workflows/build_template.yml deleted file mode 100644 index 8115f9b..0000000 --- a/.github/workflows/build_template.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Container Image Build and Sign - -on: - push: - branches: ["main"] - pull_request: - branches: ["dev"] - -env: - PROJECT_URL: https://github.com/soubinan/homelab-lxc - AUTHOR: https://github.com/soubinan - VERSION: 1.0.1 - -jobs: - build: - strategy: - matrix: - architecture: [amd64] - release: ['bookworm'] - runs-on: ubuntu-latest - - 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 - - - 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 - - - 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 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}} diff --git a/templates/homarr.yaml b/templates/homarr.yml similarity index 99% rename from templates/homarr.yaml rename to templates/homarr.yml index c3a11e2..822f182 100644 --- a/templates/homarr.yaml +++ b/templates/homarr.yml @@ -1,7 +1,7 @@ -# -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 + variant: default source: downloader: debootstrap @@ -1057,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] @@ -1122,6 +1084,7 @@ packages: sets: - packages: - fuse + - locales - systemd-resolved - openssh-client - openssl @@ -1446,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 @@ -1468,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