Skip to content

Commit 0f2c4e8

Browse files
committed
Add script to create docker image
1 parent ecaee60 commit 0f2c4e8

File tree

6 files changed

+265
-14
lines changed

6 files changed

+265
-14
lines changed

.github/workflows/build-armbian.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ on:
242242

243243
env:
244244
TZ: America/New_York
245-
ROOTFS_SCRIPT: compile-kernel/tools/script/armbian_rootfs.sh
245+
ROOTFS_SCRIPT: compile-kernel/tools/script/docker/armbian_rootfs.sh
246246

247247
jobs:
248248
build:

.github/workflows/build-homeassistant.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ on:
243243

244244
env:
245245
TZ: America/New_York
246-
ROOTFS_SCRIPT: compile-kernel/tools/script/armbian_rootfs.sh
246+
ROOTFS_SCRIPT: compile-kernel/tools/script/docker/armbian_rootfs.sh
247247

248248
jobs:
249249
build:
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#=====================================================================================
2+
# https://github.com/ophub/amlogic-s9xxx-armbian
3+
# Description: Build the Docker image of Armbian
4+
# Instructions: https://github.com/docker/build-push-action
5+
# Build and Push to: https://hub.docker.com/
6+
#=====================================================================================
7+
8+
name: Build the Docker image of Armbian
9+
10+
on:
11+
repository_dispatch:
12+
workflow_dispatch:
13+
inputs:
14+
source_branch:
15+
description: "Select the source branch"
16+
required: false
17+
default: "official"
18+
type: choice
19+
options:
20+
- jammy
21+
- noble
22+
- bookworm
23+
- bullseye
24+
docker_img:
25+
description: "Set the docker image"
26+
required: false
27+
default: "ophub/armbian"
28+
type: choice
29+
options:
30+
- ophub/armbian
31+
32+
env:
33+
TZ: America/New_York
34+
MAKE_DOCKER_SH: compile-kernel/tools/script/docker/armbian_docker.sh
35+
DOCKER_OUTPATH: out
36+
37+
jobs:
38+
build:
39+
runs-on: ubuntu-22.04-arm
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: Download Armbian rootfs file [ ${{ inputs.source_branch }} ]
47+
id: down
48+
if: (!cancelled())
49+
run: |
50+
# Get Armbian file
51+
armbian_url="$(curl \
52+
--header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
53+
-s "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases?per_page=100" |
54+
grep -o "Armbian_.*${{ inputs.source_branch }}.*/.*rootfs.tar.gz" |
55+
head -n 1
56+
)"
57+
[[ -z "${armbian_url}" ]] && echo -e "Armbian file not found!" && exit 1
58+
59+
[[ -d "armbian" ]] || mkdir -p armbian
60+
curl -fsSL "https://github.com/${GITHUB_REPOSITORY}/releases/download/${armbian_url}" -o "armbian/$(basename ${armbian_url})"
61+
[[ "${?}" -ne "0" ]] && echo "Armbian file download failed." && exit 1
62+
echo "status=success" >> ${GITHUB_OUTPUT}
63+
64+
- name: Build the Docker image
65+
id: make
66+
if: ${{ steps.down.outputs.status }} == 'success' && !cancelled()
67+
run: |
68+
chmod +x ${MAKE_DOCKER_SH}
69+
${MAKE_DOCKER_SH}
70+
echo "status=success" >> ${GITHUB_OUTPUT}
71+
72+
- name: Set up QEMU
73+
id: qemu
74+
if: ${{ steps.make.outputs.status }} == 'success' && !cancelled()
75+
uses: docker/setup-qemu-action@v3
76+
77+
- name: Set up Docker Buildx
78+
id: buildx
79+
if: (!cancelled())
80+
uses: docker/setup-buildx-action@v3
81+
82+
- name: Login to Docker Hub
83+
id: login
84+
if: (!cancelled())
85+
uses: docker/login-action@v3
86+
with:
87+
username: ${{ secrets.DOCKERHUB_USERNAME }}
88+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
89+
90+
- name: Push to Docker Hub
91+
id: push
92+
if: (!cancelled())
93+
uses: docker/build-push-action@v5
94+
with:
95+
push: true
96+
platforms: linux/arm64
97+
context: ${{ env.DOCKER_OUTPATH }}
98+
tags: "${{ inputs.docker_img }}-${{ inputs.source_branch }}:latest"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM scratch
2+
ADD armbian-rootfs.tar.gz /
3+
EXPOSE 22
4+
CMD ["/bin/bash"]
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#!/bin/bash
2+
#================================================================================================
3+
#
4+
# This file is licensed under the terms of the GNU General Public
5+
# License version 2. This program is licensed "as is" without any
6+
# warranty of any kind, whether express or implied.
7+
#
8+
# This file is a part of the Rebuild Armbian
9+
# https://github.com/ophub/amlogic-s9xxx-armbian
10+
#
11+
# Description: Make a docker version of Armbian.
12+
# Copyright (C) 2021~ https://github.com/ophub/amlogic-s9xxx-armbian
13+
#
14+
#
15+
# Command: ./compile-kernel/tools/script/docker/armbian_docker.sh
16+
#
17+
#======================================== Functions list ========================================
18+
#
19+
# error_msg : Output error message
20+
# check_depends : Check dependencies
21+
# find_armbian : Find Armbian file (armbian/*rootfs.tar.gz)
22+
# adjust_settings : Adjust related file settings
23+
# make_dockerimg : make docker image
24+
#
25+
#================================ Set make environment variables ================================
26+
#
27+
# Set default parameters
28+
current_path="${PWD}"
29+
armbian_path="${current_path}/armbian"
30+
armbian_rootfs_file="*rootfs.tar.gz"
31+
docker_path="${current_path}/compile-kernel/tools/script/docker"
32+
tmp_path="${current_path}/tmp"
33+
out_path="${current_path}/out"
34+
compile_path="${current_path}/compile-kernel"
35+
kernel_script="${compile_path}/tools/script/armbian_compile_kernel_script.sh"
36+
37+
# Set default parameters
38+
STEPS="[\033[95m STEPS \033[0m]"
39+
INFO="[\033[94m INFO \033[0m]"
40+
SUCCESS="[\033[92m SUCCESS \033[0m]"
41+
WARNING="[\033[93m WARNING \033[0m]"
42+
ERROR="[\033[91m ERROR \033[0m]"
43+
#
44+
#================================================================================================
45+
46+
error_msg() {
47+
echo -e "${ERROR} ${1}"
48+
exit 1
49+
}
50+
51+
check_depends() {
52+
# Check the necessary dependencies
53+
is_dpkg="0"
54+
dpkg_packages=("tar" "gzip")
55+
i="1"
56+
for package in ${dpkg_packages[*]}; do
57+
[[ -n "$(dpkg -l | awk '{print $2}' | grep -w "^${package}$" 2>/dev/null)" ]] || is_dpkg="1"
58+
let i++
59+
done
60+
61+
# Install missing packages
62+
if [[ "${is_dpkg}" -eq "1" ]]; then
63+
echo -e "${STEPS} Start installing the necessary dependencies..."
64+
sudo apt-get update
65+
sudo apt-get install -y ${dpkg_packages[*]}
66+
[[ "${?}" -ne "0" ]] && error_msg "Dependency installation failed."
67+
fi
68+
}
69+
70+
find_armbian() {
71+
cd ${current_path}
72+
echo -e "${STEPS} Start searching for Armbian file..."
73+
74+
# Find whether the Armbian file exists
75+
armbian_file_name="$(ls ${armbian_path}/${armbian_rootfs_file} 2>/dev/null | head -n 1 | awk -F "/" '{print $NF}')"
76+
if [[ -n "${armbian_file_name}" ]]; then
77+
version_codename="$(echo "${armbian_file_name}" | awk -F'[_-]' '{print $3}')"
78+
echo -e "${INFO} Armbian file: [ ${armbian_file_name} ], version codename: [ ${version_codename} ]"
79+
else
80+
error_msg "There is no [ ${armbian_rootfs_file} ] file in the [ ${armbian_path} ] directory."
81+
fi
82+
83+
# Check whether the Dockerfile exists
84+
[[ -f "${docker_path}/Dockerfile" ]] || error_msg "Missing Dockerfile."
85+
}
86+
87+
make_dockerimg() {
88+
cd ${current_path}
89+
echo -e "${STEPS} Start making docker image..."
90+
91+
# Make docker image
92+
echo -e "${INFO} Unpack Armbian."
93+
rm -rf ${tmp_path} && mkdir -p ${tmp_path}
94+
tar -xzf ${armbian_path}/${armbian_file_name} -C ${tmp_path}
95+
96+
cd ${tmp_path}
97+
# Add script for compile kernel
98+
cp -af --no-preserve=ownership ${compile_path} opt/
99+
cp -f --no-preserve=ownership ${kernel_script} opt/recompile
100+
101+
tar -czf armbian-${version_codename}-rootfs.tar.gz *
102+
[[ "${?}" -eq "0" ]] || error_msg "Docker image creation failed."
103+
104+
# Move the docker image to the output directory
105+
rm -rf ${out_path} && mkdir -p ${out_path}
106+
mv -f armbian-${version_codename}-rootfs.tar.gz ${out_path}
107+
[[ "${?}" -eq "0" ]] || error_msg "Docker image move failed."
108+
echo -e "${INFO} Docker image packaging succeeded."
109+
110+
cd ${current_path}
111+
112+
# Add Dockerfile
113+
cp -f ${docker_path}/Dockerfile ${out_path}
114+
[[ "${?}" -eq "0" ]] || error_msg "Dockerfile addition failed."
115+
sed -i "s|armbian-rootfs.tar.gz|armbian-${version_codename}-rootfs.tar.gz|g" ${out_path}/Dockerfile
116+
[[ "${?}" -eq "0" ]] || error_msg "Dockerfile version codename replacement failed."
117+
echo -e "${INFO} Dockerfile added successfully."
118+
119+
# Remove temporary directory
120+
rm -rf ${tmp_path}
121+
122+
sync && sleep 3
123+
echo -e "${INFO} Docker files list: \n$(ls -lh ${out_path})"
124+
echo -e "${SUCCESS} Docker image successfully created."
125+
}
126+
127+
# Show welcome message
128+
echo -e "${STEPS} Welcome to the Docker Image Maker Tool."
129+
echo -e "${INFO} Make path: [ ${PWD} ]"
130+
#
131+
check_depends
132+
find_armbian
133+
make_dockerimg
134+
#
135+
# All process completed
136+
wait

compile-kernel/tools/script/armbian_rootfs.sh renamed to compile-kernel/tools/script/docker/armbian_rootfs.sh

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# Description: Redo the Armbian rootfs file.
1212
# Copyright (C) 2021- https://github.com/ophub/amlogic-s9xxx-armbian
1313
#
14-
# Command: ./compile-kernel/tools/script/redo_armbian_rootfs.sh -v <VERSION_CODENAME>
15-
# ./compile-kernel/tools/script/redo_armbian_rootfs.sh -v bookworm
14+
# Command: ./compile-kernel/tools/script/docker/armbian_rootfs.sh -v <VERSION_CODENAME>
15+
# ./compile-kernel/tools/script/docker/armbian_rootfs.sh -v bookworm
1616
#
1717
#===================== Set make environment variables =====================
1818
#
@@ -22,6 +22,7 @@ build_path="${current_path}/build"
2222
image_path="${build_path}/output/images"
2323
cache_path="${build_path}/cache/rootfs"
2424
tmp_rootfs="${image_path}/tmp_rootfs"
25+
2526
#
2627
# Set font color
2728
STEPS="[\033[95m STEPS \033[0m]"
@@ -41,23 +42,30 @@ init_var() {
4142
echo -e "${STEPS} Start Initializing Variables..."
4243

4344
# If it is followed by [ : ], it means that the option requires a parameter value
44-
get_all_ver="$(getopt "v:" "${@}")"
45+
local options="v:"
46+
parsed_args=$(getopt -o "${options}" -- "${@}")
47+
[[ ${?} -ne 0 ]] && error_msg "Parameter parsing failed."
48+
eval set -- "${parsed_args}"
4549

46-
while [[ -n "${1}" ]]; do
50+
while true; do
4751
case "${1}" in
4852
-v | --VERSION_CODENAME)
4953
if [[ -n "${2}" ]]; then
5054
version_codename="${2}"
51-
shift
55+
shift 2
5256
else
5357
error_msg "Invalid -v parameter [ ${2} ]!"
5458
fi
5559
;;
60+
--)
61+
shift
62+
break
63+
;;
5664
*)
57-
error_msg "Invalid option [ ${1} ]!"
65+
[[ -n "${1}" ]] && error_msg "Invalid option [ ${1} ]!"
66+
break
5867
;;
5968
esac
60-
shift
6169
done
6270

6371
echo -e "${INFO} VERSION CODENAME: [ ${version_codename} ]"
@@ -82,27 +90,32 @@ redo_rootfs() {
8290
[[ "${?}" == "0" ]] && echo -e "${INFO} 01. Temporary directory creation completed." || error_msg "01. Failed to create directory!"
8391

8492
# Redo Armbian rootfs
85-
[[ -n "${rootfs_file}" ]] && {
93+
if [[ -n "${rootfs_file}" ]]; then
8694
sudo tar -mxf ${rootfs_file} -C ${tmp_rootfs}/
95+
8796
cd ${tmp_rootfs}/
8897
sudo tar -czf ${rootfs_save_name}.tar.gz *
8998
sudo mv -f ${rootfs_save_name}.tar.gz ../
9099
[[ "${?}" == "0" ]] && echo -e "${INFO} 02. Making Armbian rootfs completed." || error_msg "02. Failed to redo rootfs!"
91-
} || error_msg "02. Failed to find rootfs file!"
100+
else
101+
error_msg "02. Failed to find rootfs file!"
102+
fi
92103

93104
# Rename Armbian image
94-
[[ -n "${image_file}" ]] && {
105+
if [[ -n "${image_file}" ]]; then
95106
cd ${image_path}/
96107
mv -f ${image_file} ${image_save_name}
97108
pigz -qf *.img || gzip -qf *.img
98109
[[ "${?}" == "0" ]] && echo -e "${INFO} 03. Renaming Armbian image completed." || error_msg "03. Failed to rename the image!"
99-
} || error_msg "03. Failed to find Armbian image!"
110+
else
111+
error_msg "03. Failed to find Armbian image!"
112+
fi
100113

101114
# Add sha256sum verification files
102115
cd ${image_path}/
103116
sudo rm -rf $(ls . | grep -vE ".img.gz|.tar.gz" | xargs) 2>/dev/null
104117
for file in *; do [[ ! -d "${file}" ]] && sha256sum "${file}" >"${file}.sha"; done
105-
[[ "${?}" == "0" ]] && echo -e "${INFO} 04. The files in the current directory:\n$(ls -l .)" || error_msg "04. Failed to add sha256sum!"
118+
[[ "${?}" == "0" ]] && echo -e "${INFO} 04. The files in the current directory:\n$(ls -lh .)" || error_msg "04. Failed to add sha256sum!"
106119

107120
# Delete Armbian build source codes and temporary files
108121
cd ${build_path}/

0 commit comments

Comments
 (0)