本文簡單介紹了Github Action的用法,並使用Gihub Action定時重啟IBM cloud foundry容器。
摘要
GitHub Actions是GitHub自家的持續集成及自動化工作流服務,它使用起來非常簡單,隻要在你的倉庫根目錄建立.github/workflows文件夾,將你的工作流配置(YML文件)放到這個目錄下,就能啟用GitHub Actions服務。
關鍵字
Github Action,IBM cloud foundry
yml配置文件
name: IBM Cloud Auto Restart
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 0 * * *' # 根據自己的需要設置何時重啟
jobs:
ibm-cloud-restart:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Init
run: |
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
sudo apt-get update
sudo apt-get install cf-cli
- name: Login IBM Cloud
env:
IBM_ACCOUNT: ${{ secrets.IBM_ACCOUNT }}
IBM_PASSWORD: ${{ secrets.IBM_PASSWORD }}
run: |
cf login -a https://api.us-south.cf.cloud.ibm.com -u $IBM_ACCOUNT << EOF
$IBM_PASSWORD
EOF
- name: Get IBM Cloud Apps
run: |
cf a
- name: Restart IBM Cloud
env:
IBM_APP_NAME: ${{ secrets.IBM_APP_NAME }}
run: |
cf restart $IBM_APP_NAME
使用方法
fork倉庫:https://github.com/wf09/IBMWorkflow
設置環境變量
IBM_ACCOUNT:賬戶郵箱
IBM_APP_NAME:app的名字
IBM_PASSWORD:密碼
設置完環境變量以後記得commit一下yml文件觸發Action。