-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize scripts and add autobuild scripts
- Loading branch information
1 parent
5adf576
commit f68cbd8
Showing
18 changed files
with
414 additions
and
343 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Auto build image | ||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
jobs: | ||
issue_comment: | ||
name: Auto build image | ||
if: startswith(github.event.comment.body, '/autobuild') | ||
runs-on: ubuntu-latest | ||
permissions: | ||
issues: write | ||
steps: | ||
|
||
- name: Auto build image | ||
id: autobuild | ||
run: | | ||
commentbody="${{github.event.comment.body}}" | ||
commentbody=$(echo $commentbody | sed "s/\/imagebuild//g") | ||
sudo git clone https://github.com/sealerio/basefs.git && cd basefs | ||
sudo touch autobuild.log && sudo chmod 666 autobuild.log && sudo bash auto-build-main.sh --username="${{secrets.REGISTRY_USERNAME}}" --password="${{secrets.REGISTRY_PASSWORD}}" $commentbody > autobuild.log && cat autobuild.log | ||
echo "::set-output name=info::$(grep 'cri:' autobuild.log))" | ||
- name: Success Commit | ||
uses: peter-evans/create-or-update-comment@v1 | ||
with: | ||
issue-number: ${{ github.event.issue.number }} | ||
body: | | ||
${{ steps.autobuild.outputs.info }} |
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,110 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
for i in "$@"; do | ||
case $i in | ||
-c=* | --cri=*) | ||
cri="${i#*=}" | ||
if [ "$cri" != "docker" ] && [ "$cri" != "containerd" ]; then | ||
echo "Unsupported container runtime: ${cri}" | ||
exit 1 | ||
fi | ||
shift # past argument=value | ||
;; | ||
-n=* | --buildName=*) | ||
buildName="${i#*=}" | ||
shift # past argument=value | ||
;; | ||
--platform=*) | ||
platform="${i#*=}" | ||
shift # past argument=value | ||
;; | ||
--push) | ||
push="true" | ||
shift # past argument=value | ||
;; | ||
-p=* | --password=*) | ||
password="${i#*=}" | ||
shift # past argument=value | ||
;; | ||
-u=* | --username=*) | ||
username="${i#*=}" | ||
shift # past argument=value | ||
;; | ||
--k8s-version=*) | ||
k8s_version="${i#*=}" | ||
shift # past argument=value | ||
;; | ||
-h | --help) | ||
echo " | ||
### Options | ||
--k8s-version set the kubernetes k8s_version of the Clusterimage, k8s_version must be greater than 1.13 | ||
-c, --cri cri can be set to docker or containerd between kubernetes 1.20-1.24 versions | ||
-n, --buildName set build image name, default is 'registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:${k8s_version}' | ||
--platform set the build mirror platform, the default is linux/amd64,linux/arm64 | ||
--push push clusterimage after building the clusterimage. The image name must contain the full name of the repository, and use -u and -p to specify the username and password. | ||
-u, --username specify the user's username for pushing the Clusterimage | ||
-p, --password specify the user's password for pushing the Clusterimage | ||
-d, --debug show all script logs | ||
-h, --help help for auto build shell scripts" | ||
exit 0 | ||
;; | ||
-d | --debug) | ||
set -x | ||
shift | ||
;; | ||
-*) | ||
echo "Unknown option $i" | ||
exit 1 | ||
;; | ||
*) ;; | ||
|
||
esac | ||
done | ||
|
||
version_compare() { printf '%s\n%s\n' "$2" "$1" | sort -V -C; } ## version_compare $a $b: a>=b | ||
|
||
ARCH=$(case "$(uname -m)" in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo "unsupported architecture" "$(uname -m)" && exit 1 ;; esac) | ||
|
||
if [ "$k8s_version" = "" ]; then echo "pls use --k8s-version to set Clusterimage kubernetes version" && exit 1; else echo "$k8s_version" | grep "v" || k8s_version="v${k8s_version}"; fi | ||
#cri=$([[ -n "$cri" ]] && echo "$cri" || echo docker) | ||
cri=$( (version_compare "$k8s_version" "v1.24.0" && echo "containerd") || ([[ -n "$cri" ]] && echo "$cri" || echo "docker")) | ||
if [[ -z "$buildName" ]]; then | ||
buildName="docker.io/sealerio/kubernetes:${k8s_version}" | ||
if [[ "$cri" == "containerd" ]] && ! version_compare "$k8s_version" "v1.24.0"; then buildName=${buildName}-containerd; fi | ||
fi | ||
platform=$(if [[ -z "$platform" ]]; then echo "linux/arm64,linux/amd64"; else echo "$platform"; fi) | ||
echo "cri: ${cri}, kubernetes version: ${k8s_version}, build image name: ${buildName}" | ||
|
||
kubeadmApiVersion=$( (version_compare "$k8s_version" "v1.23.0" && echo 'kubeadm.k8s.io\/v1beta3') || (version_compare "$k8s_version" "v1.15.0" && echo 'kubeadm.k8s.io\/v1beta2') || | ||
(version_compare "$k8s_version" "v1.13.0" && echo 'kubeadm.k8s.io\/v1beta1') || (echo "Version must be greater than 1.13: ${k8s_version}" && exit 1)) | ||
|
||
workdir="$(mktemp -d auto-build-XXXXX)" && sudo cp -r context "${workdir}" && cd "${workdir}/context" && sudo cp -rf "${cri}"/* . | ||
|
||
# shellcheck disable=SC1091 | ||
sudo chmod +x version.sh download.sh && export kube_install_version="$k8s_version" && source version.sh | ||
./download.sh "${cri}" | ||
|
||
sudo chmod +x amd64/bin/kube* && sudo chmod +x arm64/bin/kube* | ||
#Download the latest version of sealer | ||
sudo git clone https://github.com/sealerio/sealer && cd sealer && git checkout main && make build-in-docker && cp _output/bin/sealer/linux_amd64/sealer /usr/bin/ && cd .. | ||
sudo sed -i "s/v1.19.8/$k8s_version/g" rootfs/etc/kubeadm.yml ##change k8s_version | ||
if [[ "$cri" == "containerd" ]]; then sudo sed -i "s/\/var\/run\/dockershim.sock/\/run\/containerd\/containerd.sock/g" rootfs/etc/kubeadm.yml; fi | ||
sudo sed -i "s/kubeadm.k8s.io\/v1beta2/$kubeadmApiVersion/g" rootfs/etc/kubeadm.yml | ||
sudo ./"${ARCH}"/bin/kubeadm config images list --config "rootfs/etc/kubeadm.yml" | ||
sudo mkdir manifests | ||
sudo ./"${ARCH}"/bin/kubeadm config images list --config "rootfs/etc/kubeadm.yml" 2>/dev/null | sed "/WARNING/d" >>imageList | ||
if [ "$(sudo ./"${ARCH}"/bin/kubeadm config images list --config rootfs/etc/kubeadm.yml 2>/dev/null | grep -c "coredns/coredns")" -gt 0 ]; then sudo sed -i "s/#imageRepository/imageRepository/g" rootfs/etc/kubeadm.yml; fi | ||
sudo sed -i "s/k8s.gcr.io/sea.hub:5000/g" rootfs/etc/kubeadm.yml | ||
pauseImage=$(./"${ARCH}"/bin/kubeadm config images list --config "rootfs/etc/kubeadm.yml" 2>/dev/null | sed "/WARNING/d" | grep pause) | ||
if [ -f "rootfs/etc/dump-config.toml" ]; then sudo sed -i "s/sea.hub:5000\/pause:3.6/$(echo "$pauseImage" | sed 's/\//\\\//g')/g" rootfs/etc/dump-config.toml; fi | ||
#sudo sed -i "s/v1.19.8/${k8s_version}/g" {arm64,amd64}/etc/Metadata | ||
##linux/arm64,linux/amd64 | ||
sudo sealer build -t "docker.io/sealerio/kubernetes:${k8s_version}" -f Kubefile | ||
if [[ "$push" == "true" ]]; then | ||
if [[ -n "$username" ]] && [[ -n "$password" ]]; then | ||
sudo sealer login "$(echo "docker.io" | cut -d "/" -f1)" -u "${username}" -p "${password}" | ||
fi | ||
sudo sealer push "docker.io/sealerio/kubernetes:${k8s_version}" | ||
fi |
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 |
---|---|---|
@@ -1,21 +1,19 @@ | ||
{ | ||
"experimental": true, | ||
"oom-score-adjust": -1000, | ||
"max-concurrent-downloads": 20, | ||
"log-driver": "json-file", | ||
"log-level": "warn", | ||
"log-opts": { | ||
"max-size": "10m", | ||
"max-file": "3" | ||
}, | ||
"mirror-registries": [ | ||
{ | ||
"domain": "*", | ||
"mirrors": [ | ||
"https://sea.hub:5000" | ||
] | ||
} | ||
], | ||
"exec-opts": [ | ||
"native.cgroupdriver=systemd" | ||
], | ||
"insecure-registries": ["0.0.0.0/0", "::/0"], | ||
"storage-driver": "overlay2", | ||
"storage-opts":["overlay2.override_kernel_check=true"], | ||
"live-restore": true, | ||
"data-root": "/var/lib/docker" | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
ack-agility-registry.cn-shanghai.cr.aliyuncs.com/sealer/lvscare:v1.1.3-beta.8 | ||
ack-agility-registry.cn-shanghai.cr.aliyuncs.com/sealer/lvscare:v1.1.3-beta.8 |
Oops, something went wrong.