73 lines
2.4 KiB
YAML
73 lines
2.4 KiB
YAML
name: Gitea CI/CD for Helm Deployment
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build-and-push:
|
|
# 请将 'ubuntu-latest' 替换为您的 Gitea runner 标签, 例如: 'self-hosted, dind, rootless'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
# 请将 'gitea.example.com' 替换为您的 Gitea 实例 URL
|
|
registry: gitea.173114.xyz
|
|
username: ${{ gitea.actor }}
|
|
# Gitea 会为工作流提供一个临时令牌用于访问包
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Build and push Docker image
|
|
run: |
|
|
# Gitea 仓库中的镜像名称
|
|
IMAGE_NAME="gitea.173114.xyz/${{ gitea.owner }}/my-docs"
|
|
echo "Pushing to: $IMAGE_NAME"
|
|
docker build . --file Dockerfile \
|
|
--tag "$IMAGE_NAME:latest" \
|
|
--tag "$IMAGE_NAME:${{ gitea.sha }}"
|
|
docker push "$IMAGE_NAME:latest"
|
|
docker push "$IMAGE_NAME:${{ gitea.sha }}"
|
|
|
|
deploy:
|
|
# 请将 'ubuntu-latest' 替换为您的 Gitea runner 标签
|
|
runs-on: ubuntu-latest
|
|
needs: build-and-push
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up Kubeconfig
|
|
run: |
|
|
mkdir -p $HOME/.kube
|
|
echo "${{ secrets.KUBE_CONFIG }}" > $HOME/.kube/config
|
|
chmod 600 $HOME/.kube/config
|
|
# KUBE_CONFIG应该是您的 kubeconfig 文件的 base64 编码内容
|
|
# 请在您的 Gitea 仓库设置中添加此 secret
|
|
if: ${{ secrets.KUBE_CONFIG != '' }}
|
|
|
|
- name: Set up Helm
|
|
uses: azure/setup-helm@v3
|
|
with:
|
|
# 如果需要,可以指定 Helm 版本, 例如: 'v3.8.0'
|
|
version: 'latest'
|
|
|
|
- name: Deploy with Helm
|
|
run: |
|
|
# 假设您的 Helm chart 位于 'helm/my-docs' 目录中
|
|
# 请将 'my-docs-release' 替换为您期望的 Helm release 名称
|
|
IMAGE_NAME="gitea.example.com/${{ gitea.owner }}/my-docs"
|
|
helm upgrade --install my-docs-release ./helm/my-docs \
|
|
--namespace my-docs-ns \
|
|
--create-namespace \
|
|
--set image.repository="$IMAGE_NAME" \
|
|
--set image.tag="${{ gitea.sha }}"
|