diff --git "a/openfaas/OpenFaaS\345\256\232\346\227\266\344\273\273\345\212\241.md" "b/openfaas/OpenFaaS\345\256\232\346\227\266\344\273\273\345\212\241.md" new file mode 100644 index 0000000..c31f290 --- /dev/null +++ "b/openfaas/OpenFaaS\345\256\232\346\227\266\344\273\273\345\212\241.md" @@ -0,0 +1,34 @@ +## OpenFaaS定时任务 + +## 安装OpenFaas + +[helm安装openfaas.md](./helm安装openfaas.md) + +## 安装cron-connector + +下载chart + +```sh +helm repo add openfaas https://openfaas.github.io/faas-netes/ +helm repo update +helm pull openfaas/cron-connector +``` + +安装 + +```sh +helm upgrade --install \ +cron-connector cron-connector-0.6.7.tgz \ + --namespace openfaas \ + --set image=registry.solarfs.io/openfaas/cron-connector:0.6.1 +``` + + + +## 参考 + +https://artifacthub.io/packages/helm/openfaas/cron-connector + +https://docs.openfaas.com/reference/cron/ + +https://zhuanlan.zhihu.com/p/632391041 \ No newline at end of file diff --git "a/openfaas/OpenFaas\344\275\277\347\224\250Go\346\250\241\346\235\277\345\210\233\345\273\272Function.md" "b/openfaas/OpenFaas\344\275\277\347\224\250Go\346\250\241\346\235\277\345\210\233\345\273\272Function.md" new file mode 100644 index 0000000..4eed37e --- /dev/null +++ "b/openfaas/OpenFaas\344\275\277\347\224\250Go\346\250\241\346\235\277\345\210\233\345\273\272Function.md" @@ -0,0 +1,95 @@ +# OpenFaas使用Go模板创建Function + +## 根据模板创建项目 + +```sh +# 登录openfaas +faas-cli login https://gateway-openfaas.netwarps.com -p xxxx +# 查看已经存在的function列表 +faas-cli list +# 拉取语言模板 +faas-cli template pull +# 根据默认go模板创建function项目 +faas-cli new -p registry.solarfs.io/go-test go-test2 --lang go +``` + +生成如下一个目录一个yml文件 + +```sh +go-test2 +go-test2.yml +``` + +`go-test2.yml`如下 + +```yaml +version: 1.0 +provider: + name: openfaas + gateway: https://gateway-openfaas.netwarps.com +functions: + go-test2: + lang: go + handler: ./go-test2 + image: registry.solarfs.io/go-test/go-test2:latest + secrets: # 这个是手动添加的,配置镜像imagePullSecret + - registry-pld-cicd # imagePullSecret name +``` + +构建镜像 + +```sh +faas-cli build -f ./go-test.yml --build-arg GOPROXY=https://proxy.golang.com.cn,direct +``` + +登录私有镜像仓库 + +```sh +faas-cli registry-login --username user --password pass +``` + +推送镜像 + +```sh +faas-cli push -f ./go-test.yml +``` + +部署function + +```sh +faas-cli deploy -f ./go-test.yml +``` + +查看部署详细信息 + +```sh +faas-cli describe go-test +``` + +测试 + +```sh +echo "test go"|faas-cli invoke go-test +``` + +删除function + +```sh +faas-cli remove go-test +``` + +## 思考 + +### 减少代码量 + +openfaas 如果想要减少代码量,就是自定义提前定义代码模板, 提前把封装好的 模块 或 公共函数,比如说 web route logging metrics utils 等 写成模板,这样其它项目就可以从模板生成,直接写需要的业务代码了。也可以找别人开源的 代码模板,有现成的也可以用。 + +### 自动扩容 + +openfaas 开源版本扩容最多只能扩到5,再高的话,要买企业版,这个不实用, 不如使用k8s hpa 或 keda 实现自动扩容 + +## 参考 + +https://docs.openfaas.com/reference/yaml/ + +https://docs.openfaas.com/languages/go/ \ No newline at end of file diff --git "a/openfaas/helm\345\256\211\350\243\205openfaas.md" "b/openfaas/helm\345\256\211\350\243\205openfaas.md" new file mode 100644 index 0000000..38723ed --- /dev/null +++ "b/openfaas/helm\345\256\211\350\243\205openfaas.md" @@ -0,0 +1,90 @@ +# helm 安装openfaas + +## 安装arkade + +```sh +wget https://github.com/alexellis/arkade/releases/download/0.10.17/arkade +chmod +x arkade +mv arkade /usr/local/bin/arkade +``` + +## 安装faas-cli + +```sh +arkade get faas-cli +mv ~/.arkade/bin/faas-cli /usr/local/bin/ +# 自动补全设置到bashrc 中,如果使用了其它sh 需要修改 +grep "faas-cli completion --shell bash" ~/.bashrc || echo "source <(faas-cli completion --shell bash)" >> ~/.bashrc +faas-cli version +``` + +## 创建namespace + +```sh +wget https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml +kubectl apply -f namespaces.yml +``` + +## 拉取openfaas chart + +```sh +helm repo add openfaas https://openfaas.github.io/faas-netes/ +helm update +helm pull openfaas/openfaas +``` + +## 编写values.yaml + +```yaml +# ingress configuration +ingress: + enabled: true + hosts: + - host: gateway-openfaas.example.com + serviceName: gateway + servicePort: 8080 + path: / + tls: + - secretName: example-com-tls + hosts: + - gateway-openfaas.example.com + ingressClassName: nginx +``` + +## 安装openfaas + +```sh +helm upgrade openfaas \ + --install openfaas-14.2.1.tgz \ + --namespace openfaas +``` + +显示如下 + +```sh +Release "openfaas" does not exist. Installing it now. +NAME: openfaas +LAST DEPLOYED: Fri Dec 8 18:34:25 2023 +NAMESPACE: openfaas +STATUS: deployed +REVISION: 1 +TEST SUITE: None +NOTES: +To verify that openfaas has started, run: + + kubectl -n openfaas get deployments -l "release=openfaas, app=openfaas" + +To retrieve the admin password, run: + + echo $(kubectl -n openfaas get secret basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode) +``` + +## 参考 + +https://artifacthub.io/packages/helm/openfaas/openfaas + +https://github.com/openfaas/faas-netes/tree/master/chart/openfaas + +https://docs.openfaas.com/deployment/kubernetes/ + +https://www.openfaas.com/blog/bring-gitops-to-your-openfaas-functions-with-argocd/ \ No newline at end of file diff --git a/playwright/images/image-20231221190033724.png b/playwright/images/image-20231221190033724.png new file mode 100644 index 0000000..005787e Binary files /dev/null and b/playwright/images/image-20231221190033724.png differ diff --git "a/playwright/\344\275\277\347\224\250playwright\346\210\252\345\233\276Kibana\345\233\276\350\241\250.md" "b/playwright/\344\275\277\347\224\250playwright\346\210\252\345\233\276Kibana\345\233\276\350\241\250.md" new file mode 100644 index 0000000..07c7967 --- /dev/null +++ "b/playwright/\344\275\277\347\224\250playwright\346\210\252\345\233\276Kibana\345\233\276\350\241\250.md" @@ -0,0 +1,119 @@ +# 使用playwright截图Kibana图表 + +## 安装 playwright + +```sh +pip install playwright +``` + +## 安装 playwright 依赖项 + +```sh +playwright install --with-deps +``` + +## 使用playwright自动生成代码 + +使用`playwright` 生成访问`kibana dashboard` 代码,其中`--ignore-https-errors`为忽略证书认证 + +```sh +playwright codegen --ignore-https-errors "https://kibana.liujinye.example/" +``` + +上面命令执行完会自动调用 chromium ,并生成python 代码,如图: + +![image-20231221190033724](./images/image-20231221190033724.png) + +自动生成代码示例如下: + +```python +from playwright.sync_api import Playwright, sync_playwright, expect + + +def run(playwright: Playwright) -> None: + browser = playwright.chromium.launch(headless=False) + context = browser.new_context(ignore_https_errors=True) + page = context.new_page() + page.goto("https://kibana.liujinye.example/login?next=%2F") + page.get_by_label("用户名").click() + page.get_by_label("用户名").fill("elastic") + page.get_by_label("密码", exact=True).click() + page.get_by_label("密码", exact=True).fill("xxxxxxxxxxxxxxx") + page.get_by_text("欢迎使用 Elastic用户名密码登录").click() + + # --------------------- + context.close() + browser.close() + + +with sync_playwright() as playwright: + run(playwright) + +``` + +在生成好的代码基础上增加一些其它逻辑 + +```python +from playwright.sync_api import Playwright, sync_playwright + + +def run(playwright: Playwright) -> None: + browser = playwright.chromium.launch( + headless=False, # 本地调度不使用headless 自动打开浏览器界面,服务器设置为True + args=['--start-maximized'] + ) + # 增加设置窗口大小 + context = browser.new_context(ignore_https_errors=True,viewport={'width': 1792, 'height': 1120}) + page = context.new_page() + page.goto("https://kibana.liujinye.example/") + page.get_by_label("用户名").fill("elastic") + page.get_by_label("密码", exact=True).fill("xxxxxxxxxxxx") + page.get_by_role("button", name="登录").click() + # 增加等待页面加载超时时间 + page.wait_for_timeout(5000) + + # 在浏览器中输入要请求的dashboard + page.goto("https://kibana.liujinye.example/app/dashboards#/view/c95bd6e0-7a22-11ee-8b13-0f9a027c16f6?_g=(refreshInterval%3A(pause%3A!t%2Cvalue%3A60000)%2Ctime%3A(from%3Anow-7d%2Fd%2Cto%3Anow))") + # 增加等待页面加载超时时间 + page.wait_for_timeout(10000) + # 添加的截图代码 + page.screenshot(path=f'example.png', full_page=True) + + context.close() + browser.close() + + +with sync_playwright() as playwright: + run(playwright) + +``` + +## Dockerfile示例 + +```dockerfile +FROM python:3.11-slim-bookworm + +WORKDIR /home/app/ + +COPY requirements.txt . + +RUN mkdir -p /home/app/python + +ENV PATH=$PATH:/home/app/.local/bin:/home/app/python/bin/ +ENV PYTHONPATH=$PYTHONPATH:/home/app/python +ENV PYTHONUNBUFFERED=1 +ENV PLAYWRIGHT_HEADLESS=True + +RUN pip install -r requirements.txt --target=/home/app/python \ + && playwright install chromium --with-deps + +COPY main.py . +ENTRYPOINT ["python"] +CMD ["main.py"] +``` + +## 参考 + +https://playwright.dev/docs/api/class-page#page-goto + +https://developer.aliyun.com/article/835305 \ No newline at end of file