153 lines
4.9 KiB
YAML
153 lines
4.9 KiB
YAML
name: Build Offline Nginx Ingress Installer
|
||
|
||
on:
|
||
push:
|
||
paths:
|
||
- 'scripts/ingress-installer.sh'
|
||
- '.github/workflows/build-offline-package.yaml'
|
||
workflow_dispatch:
|
||
|
||
jobs:
|
||
build-offline-installer:
|
||
strategy:
|
||
matrix:
|
||
arch: [amd64, arm64]
|
||
runs-on: ubuntu-latest
|
||
outputs:
|
||
artifact-name: ${{ steps.upload-artifact.outputs.artifact-name }}
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
|
||
- name: Prepare directories
|
||
run: |
|
||
mkdir -p offline-installer/{images,charts,scripts,bin}
|
||
|
||
- name: Download nerdctl binary for ${{ matrix.arch }}
|
||
run: |
|
||
wget https://github.com/containerd/nerdctl/releases/download/v2.0.3/nerdctl-2.0.3-linux-${{ matrix.arch }}.tar.gz \
|
||
-O offline-installer/nerdctl.tar.gz
|
||
|
||
- name: Pull & export required images
|
||
run: |
|
||
docker pull nginx/nginx-ingress:2.4.0
|
||
docker pull registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20230407
|
||
|
||
docker save nginx/nginx-ingress:2.4.0 \
|
||
-o offline-installer/images/nginx-ingress.tar
|
||
|
||
docker save registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20230407 \
|
||
-o offline-installer/images/kube-webhook-certgen.tar
|
||
|
||
- name: Download Helm Chart (nginx-stable/nginx-ingress v0.15.0)
|
||
run: |
|
||
helm repo add nginx-stable https://helm.nginx.com/stable
|
||
helm repo update
|
||
helm pull nginx-stable/nginx-ingress --version=0.15.0 --untar --untardir offline-installer/charts
|
||
|
||
- name: Copy installer script
|
||
run: |
|
||
cp scripts/ingress-installer.sh offline-installer/scripts/
|
||
chmod +x offline-installer/scripts/ingress-installer.sh
|
||
|
||
- name: Package offline installer
|
||
run: |
|
||
cd offline-installer
|
||
tar czvf ../offline-setup-nginx-ingress-${{ matrix.arch }}.tar.gz ./
|
||
cd ..
|
||
|
||
- name: Upload artifact
|
||
id: upload-artifact
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: offline-setup-nginx-ingress-${{ matrix.arch }}
|
||
path: offline-setup-nginx-ingress-${{ matrix.arch }}.tar.gz
|
||
|
||
test-offline-installer:
|
||
needs: build-offline-installer
|
||
strategy:
|
||
matrix:
|
||
arch: [amd64]
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
|
||
- name: Download offline installer artifact for ${{ matrix.arch }}
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
name: offline-setup-nginx-ingress-${{ matrix.arch }}
|
||
path: offline-test
|
||
|
||
- name: Setup K3s and KUBECONFIG for user
|
||
run: |
|
||
curl -sfL https://get.k3s.io | sudo sh -
|
||
# 配置当前用户的 kubeconfig
|
||
mkdir -p $HOME/.kube
|
||
sudo cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
|
||
sudo chown $USER:$USER $HOME/.kube/config
|
||
# 测试 kubectl 可用性(不需要 sudo)
|
||
kubectl get nodes
|
||
kubectl version
|
||
|
||
- name: Install Helm
|
||
run: |
|
||
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | sudo bash
|
||
|
||
- name: Load offline installer package
|
||
run: |
|
||
cd offline-test
|
||
tar -xzvf offline-setup-nginx-ingress-${{ matrix.arch }}.tar.gz
|
||
sudo tar xzvf nerdctl.tar.gz -C /usr/local/bin/
|
||
docker load -i images/nginx-ingress.tar
|
||
docker load -i images/kube-webhook-certgen.tar
|
||
cd ..
|
||
|
||
- name: Run offline installer in K3S cluster
|
||
run: |
|
||
cd offline-test
|
||
bash scripts/ingress-installer.sh # ❗不要用 sudo,除非你传入 KUBECONFIG
|
||
sleep 10
|
||
helm list -A
|
||
kubectl -n ingress get pods
|
||
|
||
publish-release:
|
||
needs: test-offline-installer
|
||
runs-on: ubuntu-latest
|
||
env:
|
||
tag_name: offline-nginx-ingress-${{ github.run_number }}
|
||
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
|
||
- name: Create Release
|
||
id: create_release
|
||
uses: actions/create-release@v1
|
||
with:
|
||
tag_name: ${{ env.tag_name }}
|
||
release_name: Daily Build ${{ env.tag_name }}
|
||
draft: false
|
||
prerelease: false
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
|
||
- name: Download amd64 artifact
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
name: offline-setup-nginx-ingress-amd64
|
||
path: release-artifacts
|
||
|
||
- name: Download arm64 artifact
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
name: offline-setup-nginx-ingress-arm64
|
||
path: release-artifacts
|
||
|
||
- name: Upload offline installers to GitHub Release
|
||
uses: softprops/action-gh-release@v1
|
||
with:
|
||
tag_name: ${{ env.tag_name }}
|
||
files: |
|
||
release-artifacts/offline-setup-nginx-ingress-amd64.tar.gz
|
||
release-artifacts/offline-setup-nginx-ingress-arm64.tar.gz
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|