-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from samzong/workflow/deploy-website
workflow: add sync to ucloud s3
- Loading branch information
Showing
4 changed files
with
200 additions
and
0 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,74 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: deploy-for-main | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push or pull request events but only for the main branch | ||
push: | ||
branches: [ main ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
env: | ||
UCLOUD_PUBLICKEY : ${{ secrets.UCLOUD_PUBLICKEY }} | ||
UCLOUD_PRIVATEKEY : ${{ secrets.UCLOUD_PRIVATEKEY }} | ||
UCLOUD_REGION : ${{ secrets.UCLOUD_REGION }} | ||
UCLOUD_BUCKET : ${{ secrets.UCLOUD_BUCKET }} | ||
CI: 1 | ||
|
||
concurrency: | ||
group: ${{ github.workflow_ref }} | ||
cancel-in-progress: true | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
deploy: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 # Required for mkdocs to be able to display pages last update info | ||
|
||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.x | ||
|
||
# Add ssh private key | ||
- name: Setup SSH | ||
uses: MrSquaare/ssh-setup-action@v1 | ||
with: | ||
host: github.com | ||
private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
|
||
# Runs a single command using the runners shell | ||
- run: pip install -r requirements.txt | ||
|
||
# Install mkdocs-material-insiders | ||
- run: git clone [email protected]:DaoCloud/mkdocs-material-insiders.git mkdocs-material | ||
- run: pip install -e mkdocs-material | ||
|
||
# add custom plugin with pdf support | ||
# - run: pip install git+https://github.com/SAMZONG/mkdocs-with-pdf-support-material-v8 | ||
|
||
# build docs | ||
- run: pwd | ||
- run: mkdocs build -f docs/zh/mkdocs.yml -d ../../public/ | ||
|
||
# upload to ucloud bucket | ||
- run: cd public && pwd && python ../scripts/upload-ucloud.py \ | ||
public_key=$UCLOUD_PUBLICKEY \ | ||
private_key=$UCLOUD_PRIVATEKEY \ | ||
region=$UCLOUD_REGION \ | ||
bucket=$UCLOUD_BUCKET | ||
|
||
# refresh docs site cdn cache | ||
- run: python scripts/refresh_cdn_cache.py \ | ||
publickey=$UCLOUD_PUBLICKEY \ | ||
privatekey=$UCLOUD_PRIVATEKEY |
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,63 @@ | ||
# /usr/bin/env python3 | ||
# -*- coding: UTF-8 -*- | ||
|
||
|
||
""" | ||
Author: samzong.lu | ||
E-mail: [email protected] | ||
""" | ||
import logging | ||
import sys | ||
import requests | ||
import hashlib | ||
import collections | ||
|
||
|
||
def sort_dict(data: dict = None): | ||
return collections.OrderedDict(sorted(data.items())) | ||
|
||
|
||
def dict_to_str(data: dict = None): | ||
data = sort_dict(data) | ||
return ''.join(['{}{}'.format(k, v) for k, v in data.items()]) | ||
|
||
|
||
def signature(payload, privatekey): | ||
sign_str = dict_to_str(payload) + privatekey | ||
return hashlib.sha1(sign_str.encode('utf-8')).hexdigest() | ||
|
||
|
||
def refresh_cdn_cache(privatekey, publickey, domain): | ||
url = "https://api.ucloud.cn/?Action=RefreshNewUcdnDomainCache" | ||
|
||
headers = { | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
payload = { | ||
"PublicKey": publickey, | ||
"Action": "RefreshNewUcdnDomainCache", | ||
"ProjectId": "org-ismsmp", | ||
"Type": "dir", | ||
"UrlList.0": domain | ||
} | ||
|
||
payload['Signature'] = signature(payload, privatekey) | ||
|
||
resp = requests.post(url, headers=headers, json=payload) | ||
|
||
logging.info("refresh cdn cache respone code: ".format(resp.status_code)) | ||
|
||
|
||
if __name__ == '__main__': | ||
argv = sys.argv | ||
|
||
publickey = argv[1].split('=')[1] | ||
privatekey = argv[2].split('=')[1] | ||
|
||
domains = ["https://docs.d.run/", "http://docs.d.run/"] | ||
|
||
for domain in domains: | ||
refresh_cdn_cache(privatekey, publickey, domain) |
Binary file not shown.
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,63 @@ | ||
# /usr/bin/env python3 | ||
# -*- coding: UTF-8 -*- | ||
|
||
|
||
""" | ||
Author: samzong.lu | ||
E-mail: [email protected] | ||
""" | ||
|
||
import logging | ||
import os | ||
import sys | ||
import subprocess | ||
|
||
|
||
def do_upload_cli(file, public_key, private_key, region, bucket): | ||
cmd = '../scripts/tools/us3cli-linux64' | ||
|
||
bucket = 'us3://' + bucket | ||
|
||
if not os.path.exists(cmd): | ||
logging.error('can not find us3cli command') | ||
return 'error' | ||
|
||
subprocess.run(['chmod', '+x', cmd]) | ||
|
||
if os.path.isdir(file): | ||
out = subprocess.run( | ||
[cmd, 'cp', '-r', file, bucket, '--accesskey', public_key, '--secretkey', | ||
private_key, | ||
'--endpoint', | ||
region]) | ||
elif os.path.isfile(file): | ||
out = subprocess.run( | ||
[cmd, 'cp', file, bucket, '--accesskey', public_key, '--secretkey', private_key, | ||
'--endpoint', | ||
region]) | ||
|
||
if out.returncode != 0: | ||
raise Exception("ucloud upload error", out.returncode) | ||
|
||
|
||
if __name__ == '__main__': | ||
argv = sys.argv | ||
|
||
if len(argv) != 5: | ||
raise Exception('args not right', argv) | ||
else: | ||
public_key = argv[1].split('=')[1] | ||
private_key = argv[2].split('=')[1] | ||
region = argv[3].split('=')[1] | ||
bucket = argv[4].split('=')[1] | ||
|
||
logging.debug(public_key + private_key + region + bucket) | ||
|
||
try: | ||
for file in os.listdir(): | ||
logging.info(file) | ||
do_upload_cli(file, public_key, private_key, region, bucket) | ||
except Exception as e: | ||
logging.error(e) |