-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transform the build workflow into a reusable one and add callers
- Loading branch information
Soubinan
committed
Mar 8, 2024
1 parent
c870609
commit a8ef843
Showing
3 changed files
with
153 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <<EOF > /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}} |