Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update homarr action #2

Merged
merged 7 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/publish_build.hurl
Original file line number Diff line number Diff line change
@@ -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
}
}
```
43 changes: 43 additions & 0 deletions .github/workflows/build-homarr.yml
Original file line number Diff line number Diff line change
@@ -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}}
25 changes: 25 additions & 0 deletions .github/workflows/build-tester.yml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 0 additions & 45 deletions .github/workflows/build_template.yml

This file was deleted.

91 changes: 91 additions & 0 deletions .github/workflows/builder.yml
Original file line number Diff line number Diff line change
@@ -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 <<EOF > /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}}
91 changes: 43 additions & 48 deletions templates/homarr.yaml → templates/homarr.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -1122,6 +1084,7 @@ packages:
sets:
- packages:
- fuse
- locales
- systemd-resolved
- openssh-client
- openssl
Expand Down Expand Up @@ -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
Expand All @@ -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