|
| 1 | +#========================================================================== |
| 2 | +# Description: Build Armbian x86 server image |
| 3 | +# Copyright (C) 2021 https://github.com/ophub/amlogic-s9xxx-armbian |
| 4 | +#========================================================================== |
| 5 | + |
| 6 | +name: Build Armbian x86 server image |
| 7 | + |
| 8 | +on: |
| 9 | + repository_dispatch: |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + set_release: |
| 13 | + description: "Select OS Release." |
| 14 | + required: false |
| 15 | + default: "noble" |
| 16 | + type: choice |
| 17 | + options: |
| 18 | + - trixie |
| 19 | + - bookworm |
| 20 | + - noble |
| 21 | + - jammy |
| 22 | + publish_docker: |
| 23 | + description: "Publish Docker image" |
| 24 | + required: false |
| 25 | + default: "none" |
| 26 | + type: choice |
| 27 | + options: |
| 28 | + - ophub/armbian |
| 29 | + - none |
| 30 | + |
| 31 | +env: |
| 32 | + TZ: Etc/UTC |
| 33 | + ROOTFS_SCRIPT: compile-kernel/tools/script/docker/build_armbian_rootfs_file.sh |
| 34 | + MAKE_DOCKER_SH: compile-kernel/tools/script/docker/build_armbian_docker_image.sh |
| 35 | + DOCKER_OUTPATH: out |
| 36 | + |
| 37 | +jobs: |
| 38 | + build: |
| 39 | + runs-on: ubuntu-24.04 |
| 40 | + if: ${{ github.event.repository.owner.id }} == ${{ github.event.sender.id }} |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Initialization environment |
| 47 | + id: init |
| 48 | + env: |
| 49 | + DEBIAN_FRONTEND: noninteractive |
| 50 | + run: | |
| 51 | + docker rmi -f $(docker images -q) 2>/dev/null || true |
| 52 | + [[ -n "${AGENT_TOOLSDIRECTORY}" ]] && sudo rm -rf "${AGENT_TOOLSDIRECTORY}" |
| 53 | + sudo rm -rf /usr/share/dotnet /usr/local/lib/android 2>/dev/null |
| 54 | + sudo swapoff -a |
| 55 | + sudo rm -f /swapfile /mnt/swapfile |
| 56 | + sudo -E apt-get -y update |
| 57 | + sudo -E apt-get -y purge azure-cli ghc* zulu* llvm* firefox google* dotnet* powershell openjdk* mongodb* moby* || true |
| 58 | + sudo -E apt-get -y install $(curl -fsSL https://ophub.org/ubuntu2404-build-armbian-depends) |
| 59 | + sudo -E systemctl daemon-reload |
| 60 | + #sudo -E apt-get -y full-upgrade |
| 61 | + sudo -E apt-get -y autoremove --purge |
| 62 | + sudo -E apt-get clean |
| 63 | + sudo sed -i '/NVM_DIR/d;/skel/d' /root/{.bashrc,.profile} |
| 64 | + sudo rm -rf ~/{.cargo,.dotnet,.rustup} |
| 65 | + sudo -E timedatectl set-timezone "${TZ:-Etc/UTC}" |
| 66 | + sudo -E ntpdate ntp.ubuntu.com 0.pool.ntp.org || true |
| 67 | + sudo -E timedatectl set-ntp true |
| 68 | + date -u |
| 69 | + timedatectl status || true |
| 70 | + echo "status=success" >> ${GITHUB_OUTPUT} |
| 71 | +
|
| 72 | + - name: Create simulated physical disk |
| 73 | + run: | |
| 74 | + mnt_size=$(expr $(df -h /mnt | tail -1 | awk '{print $4}' | sed 's/[[:alpha:]]//g' | sed 's/\..*//') - 1) |
| 75 | + root_size=$(expr $(df -h / | tail -1 | awk '{print $4}' | sed 's/[[:alpha:]]//g' | sed 's/\..*//') - 4) |
| 76 | + sudo truncate -s "${mnt_size}"G /mnt/mnt.img |
| 77 | + sudo truncate -s "${root_size}"G /root.img |
| 78 | + sudo losetup /dev/loop6 /mnt/mnt.img |
| 79 | + sudo losetup /dev/loop7 /root.img |
| 80 | + sudo pvcreate /dev/loop6 |
| 81 | + sudo pvcreate /dev/loop7 |
| 82 | + sudo vgcreate github /dev/loop6 /dev/loop7 |
| 83 | + sudo lvcreate -n runner -l 100%FREE github |
| 84 | + sudo mkfs.xfs -f -i sparse=0 -b size=4096 /dev/github/runner |
| 85 | + sudo mkdir -p /builder |
| 86 | + sudo mount /dev/github/runner /builder |
| 87 | + sudo chown -R runner:runner /builder |
| 88 | + # Prepare cached directory |
| 89 | + echo "Preparing cached directory..." |
| 90 | + sudo cp -af /home/runner/actions-runner/cached /builder/cached |
| 91 | + rm -rf /home/runner/actions-runner/cached |
| 92 | + sudo ln -sf /builder/cached /home/runner/actions-runner/cached |
| 93 | + echo "_diag directory content:" |
| 94 | + ls -lh /home/runner/actions-runner/cached/_diag/ 2>/dev/null |
| 95 | + echo "Verifying the symbolic link..." |
| 96 | + ls -ld /home/runner/actions-runner/cached |
| 97 | + df -Th /home/runner/actions-runner/cached |
| 98 | + echo "Server disk layout:" |
| 99 | + df -Th |
| 100 | + echo "status=success" >> ${GITHUB_OUTPUT} |
| 101 | +
|
| 102 | + - name: Download source code |
| 103 | + id: down |
| 104 | + working-directory: /builder |
| 105 | + if: ${{ steps.init.outputs.status }} == 'success' && !cancelled() |
| 106 | + run: | |
| 107 | + df -hT ${PWD} |
| 108 | + git clone -q --single-branch --depth=1 --branch=main https://github.com/armbian/build.git build |
| 109 | + ln -sf /builder/build ${{ github.workspace }}/build |
| 110 | + echo "status=success" >> ${GITHUB_OUTPUT} |
| 111 | +
|
| 112 | + - name: Compile Armbian [ ${{ inputs.set_release }} ] |
| 113 | + id: compile |
| 114 | + working-directory: /builder |
| 115 | + if: ${{ steps.down.outputs.status }} == 'success' && !cancelled() |
| 116 | + run: | |
| 117 | + # Compile method and parameter description: https://docs.armbian.com/Developer-Guide_Build-Options |
| 118 | + cd build/ |
| 119 | + ./compile.sh RELEASE=${{ inputs.set_release }} BOARD=uefi-x86 BRANCH=current BUILD_MINIMAL=no \ |
| 120 | + BUILD_ONLY=default HOST=armbian BUILD_DESKTOP=no EXPERT=yes KERNEL_CONFIGURE=no \ |
| 121 | + COMPRESS_OUTPUTIMAGE="sha" SHARE_LOG=yes |
| 122 | + echo "status=success" >> ${GITHUB_OUTPUT} |
| 123 | +
|
| 124 | + - name: Organize files and clear space |
| 125 | + id: clean |
| 126 | + if: ${{ steps.compile.outputs.status }} == 'success' && !cancelled() |
| 127 | + run: | |
| 128 | + # Organize and keep essential files, delete unnecessary files |
| 129 | + chmod +x ${ROOTFS_SCRIPT} |
| 130 | + ${ROOTFS_SCRIPT} -v ${{ inputs.set_release }} -s true -c true -k false -p amd64 |
| 131 | + # Clean build directory except output folder |
| 132 | + [[ -d "armbian" ]] || mkdir armbian |
| 133 | + cp -af build/output/images/* armbian/ |
| 134 | + rm -rf build |
| 135 | + # Output cleaning result information |
| 136 | + df -hT ${PWD} |
| 137 | + echo "build_tag=Armbian_${{ inputs.set_release }}_amd64_server_$(date +"%Y.%m")" >> ${GITHUB_OUTPUT} |
| 138 | + echo "status=success" >> ${GITHUB_OUTPUT} |
| 139 | +
|
| 140 | + - name: Upload Armbian image to Release |
| 141 | + uses: ncipollo/release-action@main |
| 142 | + if: ${{ steps.clean.outputs.status }} == 'success' && !cancelled() |
| 143 | + with: |
| 144 | + tag: ${{ steps.clean.outputs.build_tag }} |
| 145 | + artifacts: armbian/* |
| 146 | + allowUpdates: true |
| 147 | + makeLatest: true |
| 148 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 149 | + body: | |
| 150 | + ### Armbian Image information |
| 151 | + - Default username: root |
| 152 | + - Default password: 1234 |
| 153 | + ### Applicable platform |
| 154 | + - amd64(uefi-x86) |
| 155 | +
|
| 156 | + - name: Build the Docker image |
| 157 | + id: makedocker |
| 158 | + if: ${{ inputs.publish_docker != 'none' && !cancelled() }} |
| 159 | + run: | |
| 160 | + chmod +x ${MAKE_DOCKER_SH} |
| 161 | + ${MAKE_DOCKER_SH} |
| 162 | + echo "status=success" >> ${GITHUB_OUTPUT} |
| 163 | +
|
| 164 | + - name: Set up Docker Buildx |
| 165 | + id: buildx |
| 166 | + if: ${{ steps.makedocker.outputs.status == 'success' && !cancelled() }} |
| 167 | + uses: docker/setup-buildx-action@v3 |
| 168 | + |
| 169 | + - name: Login to Docker Hub |
| 170 | + id: login |
| 171 | + if: ${{ steps.makedocker.outputs.status == 'success' && !cancelled() }} |
| 172 | + uses: docker/login-action@v3 |
| 173 | + with: |
| 174 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 175 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 176 | + |
| 177 | + - name: Push to Docker Hub |
| 178 | + id: push |
| 179 | + if: ${{ steps.makedocker.outputs.status == 'success' && !cancelled() }} |
| 180 | + uses: docker/build-push-action@v5 |
| 181 | + with: |
| 182 | + push: true |
| 183 | + platforms: linux/amd64 |
| 184 | + context: ${{ env.DOCKER_OUTPATH }} |
| 185 | + tags: | |
| 186 | + "${{ inputs.publish_docker }}-${{ inputs.set_release }}:amd64" |
0 commit comments