-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathbuild-armbian-x86-server-image.yml
More file actions
181 lines (164 loc) · 7.36 KB
/
build-armbian-x86-server-image.yml
File metadata and controls
181 lines (164 loc) · 7.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#==========================================================================
# Description: Build Armbian x86 server image
# Copyright (C) 2021 https://github.com/ophub/amlogic-s9xxx-armbian
#==========================================================================
name: Build Armbian x86 server image
on:
repository_dispatch:
workflow_dispatch:
inputs:
set_release:
description: "Select OS Release."
required: false
default: "noble"
type: choice
options:
- trixie
- bookworm
- resolute
- noble
- jammy
publish_docker:
description: "Publish Docker image"
required: false
default: "ophub/armbian"
type: choice
options:
- ophub/armbian
- none
env:
TZ: Etc/UTC
ROOTFS_SCRIPT: compile-kernel/tools/script/docker/build_armbian_rootfs_file.sh
MAKE_DOCKER_SH: compile-kernel/tools/script/docker/build_armbian_docker_image.sh
jobs:
build:
runs-on: ubuntu-24.04
if: ${{ github.event.repository.owner.id == github.event.sender.id }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Initialize the build environment
id: init
env:
DEBIAN_FRONTEND: noninteractive
run: |
docker rmi -f $(docker images -q) 2>/dev/null || true
[[ -n "${AGENT_TOOLSDIRECTORY}" ]] && sudo rm -rf "${AGENT_TOOLSDIRECTORY}"
sudo rm -rf /usr/share/dotnet /usr/local/lib/android 2>/dev/null
sudo swapoff -a
sudo rm -f /swapfile /mnt/swapfile
sudo -E apt-get -y update
sudo -E apt-get -y purge azure-cli ghc* zulu* llvm* firefox google* dotnet* powershell openjdk* mongodb* moby* || true
sudo -E apt-get -y install $(curl -fsSL https://ophub.org/ubuntu2404-build-armbian-depends)
sudo -E systemctl daemon-reload
#sudo -E apt-get -y full-upgrade
sudo -E apt-get -y autoremove --purge
sudo -E apt-get clean
sudo sed -i '/NVM_DIR/d;/skel/d' /root/{.bashrc,.profile}
sudo rm -rf ~/{.cargo,.dotnet,.rustup}
sudo -E timedatectl set-timezone "${TZ:-Etc/UTC}"
sudo -E ntpdate ntp.ubuntu.com 0.pool.ntp.org || true
sudo -E timedatectl set-ntp true
date -u
timedatectl status || true
echo "status=success" >> ${GITHUB_OUTPUT}
- name: Create virtual disk for extended storage
run: |
mnt_size=$(expr $(df -h /mnt | tail -1 | awk '{print $4}' | sed 's/[[:alpha:]]//g' | sed 's/\..*//') - 1)
root_size=$(expr $(df -h / | tail -1 | awk '{print $4}' | sed 's/[[:alpha:]]//g' | sed 's/\..*//') - 4)
sudo truncate -s "${mnt_size}"G /mnt/mnt.img
sudo truncate -s "${root_size}"G /root.img
sudo losetup /dev/loop6 /mnt/mnt.img
sudo losetup /dev/loop7 /root.img
sudo pvcreate /dev/loop6
sudo pvcreate /dev/loop7
sudo vgcreate github /dev/loop6 /dev/loop7
sudo lvcreate -n runner -l 100%FREE github
sudo mkfs.xfs -f -i sparse=0 -b size=4096 /dev/github/runner
sudo mkdir -p /builder
sudo mount /dev/github/runner /builder
sudo chown -R runner:runner /builder
df -Th
echo "status=success" >> ${GITHUB_OUTPUT}
- name: Download source code
id: down
working-directory: /builder
if: ${{ steps.init.outputs.status == 'success' && !cancelled() }}
run: |
df -hT ${PWD}
git clone -q --single-branch --depth=1 --branch=main https://github.com/armbian/build.git build
ln -sf /builder/build ${{ github.workspace }}/build
echo "status=success" >> ${GITHUB_OUTPUT}
- name: Compile Armbian [ ${{ inputs.set_release }} ]
id: compile
working-directory: /builder
if: ${{ steps.down.outputs.status == 'success' && !cancelled() }}
run: |
# Enable QEMU emulation for ARM cross-compilation
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes 2>/dev/null || true
# Compile options reference: https://docs.armbian.com/Developer-Guide_Build-Options
cd build/
./compile.sh RELEASE=${{ inputs.set_release }} BOARD=uefi-x86 BRANCH=current BUILD_MINIMAL=no \
BUILD_ONLY=default HOST=armbian BUILD_DESKTOP=no EXPERT=yes KERNEL_CONFIGURE=no \
COMPRESS_OUTPUTIMAGE="sha" SHARE_LOG=yes
echo "status=success" >> ${GITHUB_OUTPUT}
- name: Organize output files and reclaim disk space
id: clean
if: ${{ steps.compile.outputs.status == 'success' && !cancelled() }}
run: |
# Extract essential artifacts and remove build files
chmod +x ${ROOTFS_SCRIPT}
${ROOTFS_SCRIPT} -v ${{ inputs.set_release }} -s true -c true -k false -p amd64
# Remove build files while preserving output
[[ -d "armbian" ]] || mkdir armbian
cp -af build/output/images/* armbian/
rm -rf build
# Display disk usage after cleanup
df -hT ${PWD}
echo "build_tag=Armbian_${{ inputs.set_release }}_amd64_server_$(date +"%Y.%m")" >> ${GITHUB_ENV}
echo "status=success" >> ${GITHUB_OUTPUT}
- name: Build the Docker image
id: makedocker
if: ${{ inputs.publish_docker != 'none' && !cancelled() }}
run: |
chmod +x ${MAKE_DOCKER_SH}
${MAKE_DOCKER_SH} ${{ inputs.set_release }} amd64
echo "status=success" >> ${GITHUB_OUTPUT}
- name: Upload Armbian image to Release
uses: ncipollo/release-action@main
if: ${{ steps.clean.outputs.status == 'success' && !cancelled() }}
with:
tag: ${{ env.build_tag }}
artifacts: "armbian/*,out/*"
allowUpdates: true
makeLatest: false
token: ${{ secrets.GITHUB_TOKEN }}
body: |
### Armbian Image Information
- Default username: `root`
- Default password: `1234`
### Applicable Platform
- 💻 `amd64(uefi-x86)`
- 🐋 Docker image: https://hub.docker.com/u/ophub
- name: Login to Docker Hub
id: login
if: ${{ steps.makedocker.outputs.status == 'success' && !cancelled() }}
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Load and push image to Docker Hub
id: push
if: ${{ steps.makedocker.outputs.status == 'success' && !cancelled() }}
run: |
# Load the offline Docker image built by build_armbian_docker_image.sh
offline_image="$(ls out/*.tar.gz 2>/dev/null | head -n 1)"
[[ -z "${offline_image}" ]] && echo "Error: No offline image found." && exit 1
loaded_image="$(docker load -i "${offline_image}" | grep -oP 'Loaded image: \K.*')"
[[ -z "${loaded_image}" ]] && echo "Error: Failed to load Docker image." && exit 1
echo "Loaded image: ${loaded_image}"
# Tag for Docker Hub
docker tag "${loaded_image}" "${{ inputs.publish_docker }}-${{ inputs.set_release }}:amd64"
# Push to Docker Hub
docker push "${{ inputs.publish_docker }}-${{ inputs.set_release }}:amd64"
echo "status=success" >> ${GITHUB_OUTPUT}