From d13097ba392a57337919da246a9f1312ec86625d Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sat, 4 May 2024 23:40:46 +0800 Subject: [PATCH 01/23] Rewrite get_version --- .github/workflows/build.yml | 15 ++- .gitignore | 2 + get_version.py | 244 ------------------------------------ jsontemplate.json | 42 +++++++ scripts/api_fetcher.py | 81 ++++++++++++ scripts/get_version.py | 146 +++++++++++++++++++++ scripts/version_finder | 138 ++++++++++++++++++++ scripts/web_fetcher.py | 148 ++++++++++++++++++++++ url.json | 4 +- 9 files changed, 569 insertions(+), 251 deletions(-) delete mode 100644 get_version.py create mode 100644 jsontemplate.json create mode 100644 scripts/api_fetcher.py create mode 100644 scripts/get_version.py create mode 100644 scripts/version_finder create mode 100644 scripts/web_fetcher.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8d19d65..e681382 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,22 +8,29 @@ on: paths-ignore: - ".github/**" - "docs/**" - - "README.md" + - "**.md" - "get_version.py" env: IMAGE_NAME: baidunetdisk-docker + DOCKERHUB_SLUG: crazymax/linguist + GHCR_SLUG: ghcr.io/yucat-ovo/baidunetdisk-docker jobs: Build: name: Build - strategy: - matrix: - arch: [linux/amd64, linux/arm64] + outputs: + matrix: ${{ steps.platforms.outputs.matrix }} runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@master + + - name: Create matrix + id: platforms + run: | + echo "matrix=$(docker buildx bake image-all --print | jq -cr '.target."image-all".platforms')" >>${GITHUB_OUTPUT} + - name: Set variables id: set-vars run: | diff --git a/.gitignore b/.gitignore index 68bc17f..b745cbd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.vscode/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/get_version.py b/get_version.py deleted file mode 100644 index c3bcddd..0000000 --- a/get_version.py +++ /dev/null @@ -1,244 +0,0 @@ -import json -import re -import time - -import requests -from lxml import etree - -GLOBAL_HEADER = { - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36" -} - -# 截至2024-03-01最新的版本 -GLOBAL_VERSION = [ - "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk_4.11.5_amd64.deb", -] - -# 定义需要检测的版本号范围 -max_version = [4, 20, 0] -min_version = [4, 17, 0] - -# 定义请求延时时间(秒) -GLOBAL_REQUEST_DELAY = 0.5 - - -def get_js_url() -> str: - """请求百度网盘下载页,获取存在下载链接的js文件""" - max_attempts = 5 - attempt = 0 - - url = "" - while attempt < max_attempts: - try: - r = requests.get( - "https://pan.baidu.com/download", - headers=GLOBAL_HEADER, - ) - e = etree.HTML(r.text, parser=None) - - # 获取包含链接的js文件 - for i in e.xpath("//script/@src"): - if re.search("https:\\/\\/.*chunk-common.*\\.js", i): - url = i - # print(url) - return url - except Exception as e: - print(f"An error occurred: {e}") - attempt += 1 - time.sleep(1) # 等待1秒再重试 - - if attempt == max_attempts: - print("Failed after several attempts") - return url - - -def append_json(json_file_name: str, add): - """为Json添加元素""" - file = None - try: - with open(json_file_name, "r") as f: - file = json.load(f) - # print("file=", file) - - except FileNotFoundError: - file = json.loads("") - - file.append(add) - - # print("ufile=", u_file) - - with open(json_file_name, "w") as f: - f.write(json.dumps(file, sort_keys=True, indent=4)) - return - - -def parse_url_from_json() -> list: - l = "" - try: - with open("url.json", "r") as f: - l = json.load(f) - except FileNotFoundError: - l = [] - return l - - -def parse_url_from_js(): - """从js文件中提取下载的链接并且去重,写入文件 url.json""" - url = get_js_url() - u_url = [] - - max_attempts = 5 - attempt = 0 - - while attempt < max_attempts: - try: - - d_url = "" - r = requests.get( - url, - headers=GLOBAL_HEADER, - ) - # 过滤链接 - d_url = re.findall( - '(?:link|url(?:_[0-9])?):"https://[a-zA-Z/\\.]*?/netdisk/[a-zA-Z10-9/\\._-]*?(?=")', - r.text, - ) - - # 清理 - for i in range(len(d_url)): - d_url[i] = re.sub('(link|url(?:_[0-9])?):"', "", d_url[i]) - - # 去重 - for i in d_url: - if i not in u_url: - u_url.append(i) - - break - except Exception as e: - print(f"An error occurred: {e}") - attempt += 1 - time.sleep(1) # 等待1秒再重试 - - if attempt == max_attempts: - print("Failed after several attempts,set url to default") - u_url = GLOBAL_VERSION - - with open("url.json", "w") as f: - f.write(json.dumps(u_url, sort_keys=True, indent=4)) - return - - -def make_info_json(urls: list): - """保存为Json文件""" - # print("urls:", urls) - l_url = urls[-3:] - # print(l_url) - j = [] - for i in l_url: - j.append( - { - "version": re.findall("(?<=/)((?:[0-9]{1,2}(?:\\.)?){1,3})(?=/)", i)[0], - "arch": re.findall("(amd64|arm64|x86_64)", i)[0], - "pak": re.findall("(rpm|deb)", i)[0], - "url": i, - }, - ) - # print(j) - with open("info.json", "w") as f: - f.write(json.dumps(j, sort_keys=True, indent=4)) - return - - -def make_url_temple(arch: str): - """按照之前所获取的 url.json,创建模板""" - l = "" - url_temple = "" - try: - with open("url.json", "r") as f: - l = json.load(f) - for i in l: - if re.search("amd64", i) != None and re.search("deb", i) != None: - url_temple = re.sub("amd64", arch, i) - url_temple = re.sub( - "(?<=[_/])((?:[0-9]{1,2}(?:\\.)?){1,3})(?=[_/])", "{0}", url_temple - ) - break - # print(url_temple) - except FileNotFoundError: - url_temple = "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/{0}/baidunetdisk_{0}_arm64.deb" - # print(url_temple) - return url_temple - - -def check_version(version: list, arch: str): - """检测指定版本号是否可用""" - url = make_url_temple(arch).format(".".join(str(v) for v in version)) - # url = "https://httpbin.org/status/200" - # print("Getting {0}".format(url)) - - max_attempts = 5 - attempt = 0 - - while attempt < max_attempts: - try: - response = requests.head( - url, - headers=GLOBAL_HEADER, - ) - if response.status_code == 200: - return True - else: - return False - except Exception as e: - print(f"An error occurred: {e}") - attempt += 1 - time.sleep(1) # 等待1秒再重试 - - if attempt == max_attempts: - print("Failed after several attempts") - - return - - -def find_latest_version(min_version, max_version): - """寻找最新版本号""" - version_list = [ - [x, y, z] - for x in range(max_version[0], min_version[0] - 1, -1) - for y in range(max_version[1], min_version[1] - 1, -1) - for z in range(20, -1, -1) - if not (x == max_version[0] and y == max_version[1] and z > max_version[2]) - if not (x == min_version[0] and y == min_version[1] and z < min_version[2]) - ] - for arch in ["amd64", "arm64"]: - for version in version_list: - # 检测指定版本号是否可用 - if check_version(version, arch): - print( - "arch {0} version {1} is available".format( - arch, ".".join(str(v) for v in version) - ) - ) - append_json( - "url.json", - make_url_temple(arch).format(".".join(str(v) for v in version)), - ) - time.sleep(GLOBAL_REQUEST_DELAY) - break - else: - print( - "arch {0} version {1} is not available".format( - arch, ".".join(str(v) for v in version) - ) - ) - time.sleep(GLOBAL_REQUEST_DELAY) - - # 找不到可用版本号,返回None - return None - - -if __name__ == "__main__": - parse_url_from_js() - find_latest_version(min_version, max_version) - urls = parse_url_from_json() - make_info_json(urls) diff --git a/jsontemplate.json b/jsontemplate.json new file mode 100644 index 0000000..7b428a8 --- /dev/null +++ b/jsontemplate.json @@ -0,0 +1,42 @@ +{ + "platform": { + "linux": { + "latest": { + "version": "4.17.7", + "amd64": "amd64url", + "arm64": "arm64url" + }, + "4.17.7": { + "amd64": "amd64url", + "arm64": "arm64url" + }, + "4.11.5": { + "amd64": "amd64url", + "arm64": "arm64url" + } + }, + "windows": { + "latest": { + "version": "7.19.0.18", + "amd64": "amd64url" + }, + "7.19.0.18": { + "amd64": "amd64url" + }, + "6.9.10.1": { + "amd64": "amd64url" + } + }, + "mac": { + "latest": { + "version": "4.11.0", + "amd64": "amd64url", + "arm64": "arm64url" + }, + "4.11.0": { + "amd64": "amd64url", + "arm64": "arm64url" + } + } + } +} \ No newline at end of file diff --git a/scripts/api_fetcher.py b/scripts/api_fetcher.py new file mode 100644 index 0000000..403ba5d --- /dev/null +++ b/scripts/api_fetcher.py @@ -0,0 +1,81 @@ +import asyncio +import json +import random +import re + +import httpx + + +class APIFetcher: + def __init__(self) -> None: + uas = [ + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", + ] + self.ua = random.choice(uas) + + async def async_fetcher(self, platform: str, max_attempt: int = 5) -> str | None: + url = "https://yun.baidu.com/disk/cmsdata?platform={0}&page=1&num=100".format( + platform + ) + for _ in range(max_attempt): + try: + async with httpx.AsyncClient() as client: + response = await client.get( + url, + headers={ + "User-Agent": self.ua, + "Referer": "https://yun.baidu.com/disk/version?errmsg=Auth+Login+Sucess&errno=0&ssnerror=0&", + }, + timeout=10, + ) + return response.text + except httpx.HTTPError as e: + print(f"An error occurred: {e}") + print(f"Fetch {0} failed after several attempts", url) + return None + + def linux_version(self): + doc = self.linux_json + version = json.loads(doc)["list"][0]["version"] + version = re.search(r"(?P([0-9]{1,2}(\.)?){3,4})", version).group( + "version" + ) + + return version + + def windows_version(self): + doc = self.windows_json + version = json.loads(doc)["list"][0]["version"] + version = re.search(r"(?P([0-9]{1,2}(\.)?){3,4})", version).group( + "version" + ) + return version + + def mac_version(self): + doc = self.mac_json + version = json.loads(doc)["list"][0]["version"] + version = re.search(r"(?P([0-9]{1,2}(\.)?){3,4})", version).group( + "version" + ) + return version + + async def run(self): + L = await asyncio.gather( + self.async_fetcher("linux"), + self.async_fetcher("windows"), + self.async_fetcher("mac"), + ) + # print(L) + self.linux_json, self.windows_json, self.mac_json = L + print(self.linux_json) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() + af = APIFetcher() + af.run() diff --git a/scripts/get_version.py b/scripts/get_version.py new file mode 100644 index 0000000..9dcb55b --- /dev/null +++ b/scripts/get_version.py @@ -0,0 +1,146 @@ +import json +import re +import time + +import requests + + +class LinkObj: + def __init__(self, link: str) -> None: + self.link = link + self.version, self.pkg = re.search( + r"(?P([0-9]{1,2}(\.)?){3,4}(?=[\._/])).*(?P(?<=\.)[a-z]{3,4}$)", + link, + ).group("version", "pkg") + arch = re.search( + r"(?Pamd64|arm64)", + link, + ) + if arch: + self.arch = arch.group("arch") + else: + self.arch = "amd64" + + +class Version: + def __init__(self, version, arch_links): + self.version = version + self.arch_links = arch_links + + def to_dict(self): + return self.arch_links.copy() + + +class Platform: + def __init__(self) -> None: + pass + + +def append_json(json_file_name: str, add): + """为Json添加元素""" + file = None + try: + with open(json_file_name, "r") as f: + file = json.load(f) + # print("file=", file) + + except FileNotFoundError: + file = json.loads("") + + file.append(add) + + # print("ufile=", u_file) + + with open(json_file_name, "w") as f: + f.write(json.dumps(file, sort_keys=True, indent=4)) + return + + +def parse_url_from_json() -> list: + link = "" + try: + with open("url.json", "r") as f: + link = json.load(f) + except FileNotFoundError: + link = [] + return link + + +def make_info_json(urls: list): + """保存为Json文件""" + # print("urls:", urls) + l_url = urls[-3:] + # print(l_url) + j = [] + for i in l_url: + j.append( + { + "version": re.findall("(?<=/)((?:[0-9]{1,2}(?:\\.)?){1,3})(?=/)", i)[0], + "arch": re.findall("(amd64|arm64|x86_64)", i)[0], + "pak": re.findall("(rpm|deb)", i)[0], + "url": i, + }, + ) + # print(j) + with open("info.json", "w") as f: + f.write(json.dumps(j, sort_keys=True, indent=4)) + return + + +def make_url_temple(arch: str): + """按照之前所获取的 url.json,创建模板""" + link = "" + url_temple = "" + try: + with open("url.json", "r") as f: + link = json.load(f) + for i in link: + if re.search("amd64", i) is not None and re.search("deb", i) is not None: + url_temple = re.sub("amd64", arch, i) + url_temple = re.sub( + "(?<=[_/])((?:[0-9]{1,2}(?:\\.)?){1,3})(?=[_/])", "{0}", url_temple + ) + break + # print(url_temple) + except FileNotFoundError: + url_temple = "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/{0}/baidunetdisk_{0}_arm64.deb" + # print(url_temple) + return url_temple + + +def check_version(version: list, arch: str): + """检测指定版本号是否可用""" + url = make_url_temple(arch).format(".".join(str(v) for v in version)) + # url = "https://httpbin.org/status/200" + # print("Getting {0}".format(url)) + + max_attempts = 5 + attempt = 0 + + while attempt < max_attempts: + try: + response = requests.head( + url, + headers="", + ) + if response.status_code == 200: + return True + else: + return False + except Exception as e: + print(f"An error occurred: {e}") + attempt += 1 + time.sleep(1) # 等待1秒再重试 + + if attempt == max_attempts: + print("Failed after several attempts") + + return + + +def main(): + pass + + +if __name__ == "__main__": + main() diff --git a/scripts/version_finder b/scripts/version_finder new file mode 100644 index 0000000..7d1d560 --- /dev/null +++ b/scripts/version_finder @@ -0,0 +1,138 @@ +import re + +from api_fetcher import APIFetcher + + +class VersionFinder: + def __init__(self) -> None: + pass + + class TemplateGenerator: + """模板创建类 + + Args: 从网页获取的url数组 + Returns: 模板数组, 版本区域由{0}替代 + """ + + def __init__(self, urls: list) -> list[str]: + self.linux_link = [] + self.windows_link = "" + self.mac_link = [] + + for i in urls: + if re.search("(deb|rpm)", i) is not None: + self.linux_link.append(i) + elif re.search("exe", i) is not None: + if self.windows_link != "": + continue + self.windows_link = i + elif re.search("dmg", i) is not None: + self.mac_link.append(i) + + def linux(self): + arch = ["arm64", "amd64"] + url_template = [] + + for url in self.linux_link: + # print(url) + + version = re.search( + r"(?P(?<=[_/])((?:[0-9]{1,2}(?:\.)?){1,3})(?=[_/])).*(?P(?<=\.)[a-z]{3,4}$)", + url, + ).group("pkg", "version") + + self.linux_version = version[1] + + if version[0] == "rpm": + url_template.append(re.sub(version[1], "{0}", url)) + else: + template = re.sub("amd64", "{0}", url) + url_template += [ + re.sub(version[1], "{0}", template.format(i)) for i in arch + ] + + return url_template + + def windows(self): + self.windows_version = re.search( + r"(?P([0-9]{1,2}(\.)?){3,4}(?=\.|_|\/))", self.windows_link + ).group("version") + return re.sub(self.windows_version, "{0}", self.windows_link) + + def mac(self): + versions = {} + url_template = [] + for url in self.mac_link: + version = re.search( + r"(?P(?<=[_])((?:[0-9]{1,2}(?:\.)?){1,3})(?=[_\.]))", + url, + ).group("version") + if re.search("arm", url): + versions["arm"] = version + url_template.append(re.sub(version, "{0}", url)) + else: + versions["amd"] = version + url_template.append(re.sub(version, "{0}", url)) + self.mac_version = versions + return url_template + + def __version_compear(a: str, b: str): + a_split = a.split(".") + b_split = b.split(".") + flag = False + if len(a) == len(b): + length = len(a_split) + for i in range(length): + if a_split[i] > b_split[i]: + flag = True + if flag: + return a + else: + return b + else: + print("The two version numbers have different lengths.") + return a + + def version_setter(self, api_version): + self.linux_version = self.__version_compear( + self.linux_version, api_version.linux_version() + ) + self.windows_version = self.__version_compear( + self.windows_version, api_version.windows_version() + ) + self.mac_version = self.__version_compear( + self.mac_version, api_version.mac_version() + ) + + def run(self, urls: list): + tg = self.TemplateGenerator(urls) + linux_template = tg.linux() + windows_template = tg.windows() + mac_template = tg.mac() + self.linux_version = tg.linux_version + self.windows_version = tg.windows_version + self.mac_version = tg.mac_version + api = APIFetcher() + api.run() + self.version_setter(api) + + def append_json(self): + pass + + +if __name__ == "__main__": + # import doctest + + # doctest.testmod() + urls = [ + "https://issuepcdn.baidupcs.com/issue/netdisk/yunguanjia/BaiduNetdisk_7.19.0.18.exe", + "https://issuepcdn.baidupcs.com/issue/netdisk/yunguanjia/BaiduNetdisk_6.9.10.1.exe", + "https://issuepcdn.baidupcs.com/issue/netdisk/MACguanjia/BaiduNetdisk_mac_4.11.0.dmg", + "https://issuepcdn.baidupcs.com/issue/netdisk/MACguanjia/BaiduNetdisk_mac_4.11.0_arm64.dmg", + "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk-4.11.5.x86_64.rpm", + "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk_4.11.5_amd64.deb", + ] + vf = VersionFinder() + vf.run(urls) + print(vf.linux_version) + pass diff --git a/scripts/web_fetcher.py b/scripts/web_fetcher.py new file mode 100644 index 0000000..79e9b27 --- /dev/null +++ b/scripts/web_fetcher.py @@ -0,0 +1,148 @@ +import json +import random +import re + +import httpx +from lxml import etree + + +class WebFetcher: + def __init__(self) -> None: + uas = [ + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", + ] + self.ua = random.choice(uas) + + def fetcher(self, url: str, max_attempt: int = 5) -> str | None: + """网址抓取器 + + 从给定 url 抓取对应数据, 失败时重试, 默认重试5次 + + >>> bdnd = WebFetcher() + >>> type(bdnd.fetcher("https://pan.baidu.com/download")) is str + True + >>> type(bdnd.fetcher("https://1.1.1.1", max_attempt=1)) is str + True + >>> bdnd.fetcher("https://172.1.1.1", max_attempt=1) + An error occurred: timed out + + Args: + url: 网址 + max_attempt: 重试次数 + + Returns: + 成功时返回所获取网页的text数据 + 失败时返回None + """ + for _ in range(max_attempt): + try: + response = httpx.get( + url, + headers={ + "User-Agent": self.ua, + "Referer": "https://pan.baidu.com/disk/main", + }, + timeout=10, + ) + return response.text + except httpx.HTTPError as e: + print(f"An error occurred: {e}") + + async def async_fetcher(self, url: str, max_attempt: int = 5) -> str | None: + for attempt in range(max_attempt): + try: + async with httpx.AsyncClient() as client: + response = await client.get( + url, + headers={ + "User-Agent": self.ua, + "Referer": "https://pan.baidu.com/disk/main", + }, + timeout=10, + ) + return response + except httpx.HTTPError as e: + print(f"An error occurred: {e}") + print(f"Fetch {0} failed after several attempts", url) + return None + + def fetch_js_url(self) -> list: + """请求百度网盘下载页,获取存在下载链接的js文件 + + Returns: + 成功时设置self.js_url为所获取网页的text数据 + 失败时设置self.js_url为None + + >>> bdnd = WebFetcher() + >>> bdnd.fetch_js_url() + 'https://nd-static.bdstatic.com/m-static/wp-brand/js/chunk-common.8b953c6c.js' + """ + response = self.fetcher("https://pan.baidu.com/download") + if response is not None: + try: + doc = etree.HTML(response, parser=None) + for i in doc.xpath("//script/@src"): + if re.search(r"https:\/\/.*chunk-common.*\.js", i): + self.js_url = i + return i + except Exception as e: + print(f"An error occurred: {e}, set js_url to default") + self.js_url = "https://nd-static.bdstatic.com/m-static/wp-brand/js/chunk-common.8b953c6c.js" + return self.js_url + else: + print("Fetcher return None, set js_url to default") + self.js_url = "https://nd-static.bdstatic.com/m-static/wp-brand/js/chunk-common.8b953c6c.js" + return self.js_url + + def parse_url_from_js(self) -> list: + """从js文件中提取下载的链接并且去重 + + >>> bdnd = WebFetcher() + >>> bdnd.fetch_js_url() + 'https://nd-static.bdstatic.com/m-static/wp-brand/js/chunk-common.8b953c6c.js' + >>> len(bdnd.parse_url_from_js()) + 6 + """ + # 获取js数据 + js_url = self.js_url + response = self.fetcher(js_url) + + # 过滤链接 + original_url = re.findall( + r'(?:(?:link|url)(?:_[0-9])?:")(?Phttps://[a-zA-Z/\.]*?/netdisk/[a-zA-Z10-9/\._-]*?)(?=")', + response, + ) + + # 去重 + unique_url = [] + for i in original_url: + if i not in unique_url: + unique_url.append(i) + self.link_url = unique_url + return unique_url + + def json_saver(self): + try: + with open("url.json", "w") as f: + f.write(json.dumps(self.link_url, sort_keys=True, indent=4)) + except Exception as e: + print(f"An error occurred: {e}, Please check the permissions.") + + def run(self): + doc = WebFetcher() + doc.fetch_js_url() + doc.parse_url_from_js() + doc.json_saver() + return self.link_url + + def get_urls(self) -> list: + return self.link_url + + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/url.json b/url.json index 771552e..12f14c4 100644 --- a/url.json +++ b/url.json @@ -4,7 +4,5 @@ "https://issuepcdn.baidupcs.com/issue/netdisk/MACguanjia/BaiduNetdisk_mac_4.11.0.dmg", "https://issuepcdn.baidupcs.com/issue/netdisk/MACguanjia/BaiduNetdisk_mac_4.11.0_arm64.dmg", "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk-4.11.5.x86_64.rpm", - "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk_4.11.5_amd64.deb", - "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.17.7/baidunetdisk_4.17.7_amd64.deb", - "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.17.7/baidunetdisk_4.17.7_arm64.deb" + "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk_4.11.5_amd64.deb" ] \ No newline at end of file From 205e502e00a606f1a877be859490240d22587aec Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sat, 4 May 2024 23:46:53 +0800 Subject: [PATCH 02/23] remove python --- info.json | 20 ------ jsontemplate.json | 42 ------------ requirements.txt | 2 - scripts/api_fetcher.py | 81 ---------------------- scripts/get_version.py | 146 ---------------------------------------- scripts/version_finder | 138 -------------------------------------- scripts/web_fetcher.py | 148 ----------------------------------------- url.json | 8 --- 8 files changed, 585 deletions(-) delete mode 100644 info.json delete mode 100644 jsontemplate.json delete mode 100644 requirements.txt delete mode 100644 scripts/api_fetcher.py delete mode 100644 scripts/get_version.py delete mode 100644 scripts/version_finder delete mode 100644 scripts/web_fetcher.py delete mode 100644 url.json diff --git a/info.json b/info.json deleted file mode 100644 index 11b3a2f..0000000 --- a/info.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "arch": "amd64", - "pak": "deb", - "url": "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk_4.11.5_amd64.deb", - "version": "4.11.5" - }, - { - "arch": "amd64", - "pak": "deb", - "url": "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.17.7/baidunetdisk_4.17.7_amd64.deb", - "version": "4.17.7" - }, - { - "arch": "arm64", - "pak": "deb", - "url": "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.17.7/baidunetdisk_4.17.7_arm64.deb", - "version": "4.17.7" - } -] \ No newline at end of file diff --git a/jsontemplate.json b/jsontemplate.json deleted file mode 100644 index 7b428a8..0000000 --- a/jsontemplate.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "platform": { - "linux": { - "latest": { - "version": "4.17.7", - "amd64": "amd64url", - "arm64": "arm64url" - }, - "4.17.7": { - "amd64": "amd64url", - "arm64": "arm64url" - }, - "4.11.5": { - "amd64": "amd64url", - "arm64": "arm64url" - } - }, - "windows": { - "latest": { - "version": "7.19.0.18", - "amd64": "amd64url" - }, - "7.19.0.18": { - "amd64": "amd64url" - }, - "6.9.10.1": { - "amd64": "amd64url" - } - }, - "mac": { - "latest": { - "version": "4.11.0", - "amd64": "amd64url", - "arm64": "arm64url" - }, - "4.11.0": { - "amd64": "amd64url", - "arm64": "arm64url" - } - } - } -} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index b091a2f..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -lxml==5.2.1 -requests==2.31.0 \ No newline at end of file diff --git a/scripts/api_fetcher.py b/scripts/api_fetcher.py deleted file mode 100644 index 403ba5d..0000000 --- a/scripts/api_fetcher.py +++ /dev/null @@ -1,81 +0,0 @@ -import asyncio -import json -import random -import re - -import httpx - - -class APIFetcher: - def __init__(self) -> None: - uas = [ - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", - ] - self.ua = random.choice(uas) - - async def async_fetcher(self, platform: str, max_attempt: int = 5) -> str | None: - url = "https://yun.baidu.com/disk/cmsdata?platform={0}&page=1&num=100".format( - platform - ) - for _ in range(max_attempt): - try: - async with httpx.AsyncClient() as client: - response = await client.get( - url, - headers={ - "User-Agent": self.ua, - "Referer": "https://yun.baidu.com/disk/version?errmsg=Auth+Login+Sucess&errno=0&ssnerror=0&", - }, - timeout=10, - ) - return response.text - except httpx.HTTPError as e: - print(f"An error occurred: {e}") - print(f"Fetch {0} failed after several attempts", url) - return None - - def linux_version(self): - doc = self.linux_json - version = json.loads(doc)["list"][0]["version"] - version = re.search(r"(?P([0-9]{1,2}(\.)?){3,4})", version).group( - "version" - ) - - return version - - def windows_version(self): - doc = self.windows_json - version = json.loads(doc)["list"][0]["version"] - version = re.search(r"(?P([0-9]{1,2}(\.)?){3,4})", version).group( - "version" - ) - return version - - def mac_version(self): - doc = self.mac_json - version = json.loads(doc)["list"][0]["version"] - version = re.search(r"(?P([0-9]{1,2}(\.)?){3,4})", version).group( - "version" - ) - return version - - async def run(self): - L = await asyncio.gather( - self.async_fetcher("linux"), - self.async_fetcher("windows"), - self.async_fetcher("mac"), - ) - # print(L) - self.linux_json, self.windows_json, self.mac_json = L - print(self.linux_json) - - -if __name__ == "__main__": - import doctest - - doctest.testmod() - af = APIFetcher() - af.run() diff --git a/scripts/get_version.py b/scripts/get_version.py deleted file mode 100644 index 9dcb55b..0000000 --- a/scripts/get_version.py +++ /dev/null @@ -1,146 +0,0 @@ -import json -import re -import time - -import requests - - -class LinkObj: - def __init__(self, link: str) -> None: - self.link = link - self.version, self.pkg = re.search( - r"(?P([0-9]{1,2}(\.)?){3,4}(?=[\._/])).*(?P(?<=\.)[a-z]{3,4}$)", - link, - ).group("version", "pkg") - arch = re.search( - r"(?Pamd64|arm64)", - link, - ) - if arch: - self.arch = arch.group("arch") - else: - self.arch = "amd64" - - -class Version: - def __init__(self, version, arch_links): - self.version = version - self.arch_links = arch_links - - def to_dict(self): - return self.arch_links.copy() - - -class Platform: - def __init__(self) -> None: - pass - - -def append_json(json_file_name: str, add): - """为Json添加元素""" - file = None - try: - with open(json_file_name, "r") as f: - file = json.load(f) - # print("file=", file) - - except FileNotFoundError: - file = json.loads("") - - file.append(add) - - # print("ufile=", u_file) - - with open(json_file_name, "w") as f: - f.write(json.dumps(file, sort_keys=True, indent=4)) - return - - -def parse_url_from_json() -> list: - link = "" - try: - with open("url.json", "r") as f: - link = json.load(f) - except FileNotFoundError: - link = [] - return link - - -def make_info_json(urls: list): - """保存为Json文件""" - # print("urls:", urls) - l_url = urls[-3:] - # print(l_url) - j = [] - for i in l_url: - j.append( - { - "version": re.findall("(?<=/)((?:[0-9]{1,2}(?:\\.)?){1,3})(?=/)", i)[0], - "arch": re.findall("(amd64|arm64|x86_64)", i)[0], - "pak": re.findall("(rpm|deb)", i)[0], - "url": i, - }, - ) - # print(j) - with open("info.json", "w") as f: - f.write(json.dumps(j, sort_keys=True, indent=4)) - return - - -def make_url_temple(arch: str): - """按照之前所获取的 url.json,创建模板""" - link = "" - url_temple = "" - try: - with open("url.json", "r") as f: - link = json.load(f) - for i in link: - if re.search("amd64", i) is not None and re.search("deb", i) is not None: - url_temple = re.sub("amd64", arch, i) - url_temple = re.sub( - "(?<=[_/])((?:[0-9]{1,2}(?:\\.)?){1,3})(?=[_/])", "{0}", url_temple - ) - break - # print(url_temple) - except FileNotFoundError: - url_temple = "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/{0}/baidunetdisk_{0}_arm64.deb" - # print(url_temple) - return url_temple - - -def check_version(version: list, arch: str): - """检测指定版本号是否可用""" - url = make_url_temple(arch).format(".".join(str(v) for v in version)) - # url = "https://httpbin.org/status/200" - # print("Getting {0}".format(url)) - - max_attempts = 5 - attempt = 0 - - while attempt < max_attempts: - try: - response = requests.head( - url, - headers="", - ) - if response.status_code == 200: - return True - else: - return False - except Exception as e: - print(f"An error occurred: {e}") - attempt += 1 - time.sleep(1) # 等待1秒再重试 - - if attempt == max_attempts: - print("Failed after several attempts") - - return - - -def main(): - pass - - -if __name__ == "__main__": - main() diff --git a/scripts/version_finder b/scripts/version_finder deleted file mode 100644 index 7d1d560..0000000 --- a/scripts/version_finder +++ /dev/null @@ -1,138 +0,0 @@ -import re - -from api_fetcher import APIFetcher - - -class VersionFinder: - def __init__(self) -> None: - pass - - class TemplateGenerator: - """模板创建类 - - Args: 从网页获取的url数组 - Returns: 模板数组, 版本区域由{0}替代 - """ - - def __init__(self, urls: list) -> list[str]: - self.linux_link = [] - self.windows_link = "" - self.mac_link = [] - - for i in urls: - if re.search("(deb|rpm)", i) is not None: - self.linux_link.append(i) - elif re.search("exe", i) is not None: - if self.windows_link != "": - continue - self.windows_link = i - elif re.search("dmg", i) is not None: - self.mac_link.append(i) - - def linux(self): - arch = ["arm64", "amd64"] - url_template = [] - - for url in self.linux_link: - # print(url) - - version = re.search( - r"(?P(?<=[_/])((?:[0-9]{1,2}(?:\.)?){1,3})(?=[_/])).*(?P(?<=\.)[a-z]{3,4}$)", - url, - ).group("pkg", "version") - - self.linux_version = version[1] - - if version[0] == "rpm": - url_template.append(re.sub(version[1], "{0}", url)) - else: - template = re.sub("amd64", "{0}", url) - url_template += [ - re.sub(version[1], "{0}", template.format(i)) for i in arch - ] - - return url_template - - def windows(self): - self.windows_version = re.search( - r"(?P([0-9]{1,2}(\.)?){3,4}(?=\.|_|\/))", self.windows_link - ).group("version") - return re.sub(self.windows_version, "{0}", self.windows_link) - - def mac(self): - versions = {} - url_template = [] - for url in self.mac_link: - version = re.search( - r"(?P(?<=[_])((?:[0-9]{1,2}(?:\.)?){1,3})(?=[_\.]))", - url, - ).group("version") - if re.search("arm", url): - versions["arm"] = version - url_template.append(re.sub(version, "{0}", url)) - else: - versions["amd"] = version - url_template.append(re.sub(version, "{0}", url)) - self.mac_version = versions - return url_template - - def __version_compear(a: str, b: str): - a_split = a.split(".") - b_split = b.split(".") - flag = False - if len(a) == len(b): - length = len(a_split) - for i in range(length): - if a_split[i] > b_split[i]: - flag = True - if flag: - return a - else: - return b - else: - print("The two version numbers have different lengths.") - return a - - def version_setter(self, api_version): - self.linux_version = self.__version_compear( - self.linux_version, api_version.linux_version() - ) - self.windows_version = self.__version_compear( - self.windows_version, api_version.windows_version() - ) - self.mac_version = self.__version_compear( - self.mac_version, api_version.mac_version() - ) - - def run(self, urls: list): - tg = self.TemplateGenerator(urls) - linux_template = tg.linux() - windows_template = tg.windows() - mac_template = tg.mac() - self.linux_version = tg.linux_version - self.windows_version = tg.windows_version - self.mac_version = tg.mac_version - api = APIFetcher() - api.run() - self.version_setter(api) - - def append_json(self): - pass - - -if __name__ == "__main__": - # import doctest - - # doctest.testmod() - urls = [ - "https://issuepcdn.baidupcs.com/issue/netdisk/yunguanjia/BaiduNetdisk_7.19.0.18.exe", - "https://issuepcdn.baidupcs.com/issue/netdisk/yunguanjia/BaiduNetdisk_6.9.10.1.exe", - "https://issuepcdn.baidupcs.com/issue/netdisk/MACguanjia/BaiduNetdisk_mac_4.11.0.dmg", - "https://issuepcdn.baidupcs.com/issue/netdisk/MACguanjia/BaiduNetdisk_mac_4.11.0_arm64.dmg", - "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk-4.11.5.x86_64.rpm", - "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk_4.11.5_amd64.deb", - ] - vf = VersionFinder() - vf.run(urls) - print(vf.linux_version) - pass diff --git a/scripts/web_fetcher.py b/scripts/web_fetcher.py deleted file mode 100644 index 79e9b27..0000000 --- a/scripts/web_fetcher.py +++ /dev/null @@ -1,148 +0,0 @@ -import json -import random -import re - -import httpx -from lxml import etree - - -class WebFetcher: - def __init__(self) -> None: - uas = [ - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", - ] - self.ua = random.choice(uas) - - def fetcher(self, url: str, max_attempt: int = 5) -> str | None: - """网址抓取器 - - 从给定 url 抓取对应数据, 失败时重试, 默认重试5次 - - >>> bdnd = WebFetcher() - >>> type(bdnd.fetcher("https://pan.baidu.com/download")) is str - True - >>> type(bdnd.fetcher("https://1.1.1.1", max_attempt=1)) is str - True - >>> bdnd.fetcher("https://172.1.1.1", max_attempt=1) - An error occurred: timed out - - Args: - url: 网址 - max_attempt: 重试次数 - - Returns: - 成功时返回所获取网页的text数据 - 失败时返回None - """ - for _ in range(max_attempt): - try: - response = httpx.get( - url, - headers={ - "User-Agent": self.ua, - "Referer": "https://pan.baidu.com/disk/main", - }, - timeout=10, - ) - return response.text - except httpx.HTTPError as e: - print(f"An error occurred: {e}") - - async def async_fetcher(self, url: str, max_attempt: int = 5) -> str | None: - for attempt in range(max_attempt): - try: - async with httpx.AsyncClient() as client: - response = await client.get( - url, - headers={ - "User-Agent": self.ua, - "Referer": "https://pan.baidu.com/disk/main", - }, - timeout=10, - ) - return response - except httpx.HTTPError as e: - print(f"An error occurred: {e}") - print(f"Fetch {0} failed after several attempts", url) - return None - - def fetch_js_url(self) -> list: - """请求百度网盘下载页,获取存在下载链接的js文件 - - Returns: - 成功时设置self.js_url为所获取网页的text数据 - 失败时设置self.js_url为None - - >>> bdnd = WebFetcher() - >>> bdnd.fetch_js_url() - 'https://nd-static.bdstatic.com/m-static/wp-brand/js/chunk-common.8b953c6c.js' - """ - response = self.fetcher("https://pan.baidu.com/download") - if response is not None: - try: - doc = etree.HTML(response, parser=None) - for i in doc.xpath("//script/@src"): - if re.search(r"https:\/\/.*chunk-common.*\.js", i): - self.js_url = i - return i - except Exception as e: - print(f"An error occurred: {e}, set js_url to default") - self.js_url = "https://nd-static.bdstatic.com/m-static/wp-brand/js/chunk-common.8b953c6c.js" - return self.js_url - else: - print("Fetcher return None, set js_url to default") - self.js_url = "https://nd-static.bdstatic.com/m-static/wp-brand/js/chunk-common.8b953c6c.js" - return self.js_url - - def parse_url_from_js(self) -> list: - """从js文件中提取下载的链接并且去重 - - >>> bdnd = WebFetcher() - >>> bdnd.fetch_js_url() - 'https://nd-static.bdstatic.com/m-static/wp-brand/js/chunk-common.8b953c6c.js' - >>> len(bdnd.parse_url_from_js()) - 6 - """ - # 获取js数据 - js_url = self.js_url - response = self.fetcher(js_url) - - # 过滤链接 - original_url = re.findall( - r'(?:(?:link|url)(?:_[0-9])?:")(?Phttps://[a-zA-Z/\.]*?/netdisk/[a-zA-Z10-9/\._-]*?)(?=")', - response, - ) - - # 去重 - unique_url = [] - for i in original_url: - if i not in unique_url: - unique_url.append(i) - self.link_url = unique_url - return unique_url - - def json_saver(self): - try: - with open("url.json", "w") as f: - f.write(json.dumps(self.link_url, sort_keys=True, indent=4)) - except Exception as e: - print(f"An error occurred: {e}, Please check the permissions.") - - def run(self): - doc = WebFetcher() - doc.fetch_js_url() - doc.parse_url_from_js() - doc.json_saver() - return self.link_url - - def get_urls(self) -> list: - return self.link_url - - -if __name__ == "__main__": - import doctest - - doctest.testmod() diff --git a/url.json b/url.json deleted file mode 100644 index 12f14c4..0000000 --- a/url.json +++ /dev/null @@ -1,8 +0,0 @@ -[ - "https://issuepcdn.baidupcs.com/issue/netdisk/yunguanjia/BaiduNetdisk_7.19.0.18.exe", - "https://issuepcdn.baidupcs.com/issue/netdisk/yunguanjia/BaiduNetdisk_6.9.10.1.exe", - "https://issuepcdn.baidupcs.com/issue/netdisk/MACguanjia/BaiduNetdisk_mac_4.11.0.dmg", - "https://issuepcdn.baidupcs.com/issue/netdisk/MACguanjia/BaiduNetdisk_mac_4.11.0_arm64.dmg", - "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk-4.11.5.x86_64.rpm", - "https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.11.5/baidunetdisk_4.11.5_amd64.deb" -] \ No newline at end of file From 16164b19aa9c08da55b0bd26fb4b2228262d0eab Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sat, 4 May 2024 23:49:41 +0800 Subject: [PATCH 03/23] remove --- .github/codeql.yml | 89 ------------------------------------- .github/dependabot.yml | 5 --- .github/workflows/build.yml | 2 +- 3 files changed, 1 insertion(+), 95 deletions(-) delete mode 100644 .github/codeql.yml diff --git a/.github/codeql.yml b/.github/codeql.yml deleted file mode 100644 index c480707..0000000 --- a/.github/codeql.yml +++ /dev/null @@ -1,89 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ "main" ] - paths: - - "get-version.py" - pull_request: - branches: [ "main" ] - paths: - - "get-version.py" - schedule: - - cron: '24 3 * * 2' - -jobs: - analyze: - name: Analyze - # Runner size impacts CodeQL analysis time. To learn more, please see: - # - https://gh.io/recommended-hardware-resources-for-running-codeql - # - https://gh.io/supported-runners-and-hardware-resources - # - https://gh.io/using-larger-runners - # Consider using larger runners for possible analysis time improvements. - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} - timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} - permissions: - # required for all workflows - security-events: write - - # only required for workflows in private repositories - actions: read - contents: read - - strategy: - fail-fast: false - matrix: - language: [ 'python' ] - # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] - # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both - # Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both - # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality - - - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 - - # ℹ️ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{matrix.language}}" - diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e321bcf..3cdbb87 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -12,8 +12,3 @@ updates: directory: "/" schedule: interval: "daily" - - - package-ecosystem: "pip" - directory: "/" - schedule: - interval: "daily" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e681382..e4a6ea6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ on: env: IMAGE_NAME: baidunetdisk-docker - DOCKERHUB_SLUG: crazymax/linguist + DOCKERHUB_SLUG: yucatovo/baidunetdisk-docker GHCR_SLUG: ghcr.io/yucat-ovo/baidunetdisk-docker jobs: From 29469a01591c613944a384211b28b38d15bc3b6e Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 18:34:08 +0800 Subject: [PATCH 04/23] Test action --- .github/workflows/build.yml | 5 ++- .github/workflows/test.yml | 51 +++++++++++++++++++++++++ .github/workflows/version.yml | 44 --------------------- Dockerfile | 72 +++++++---------------------------- Dockerfile.arm64 | 53 ++++++++++++++++++++++++++ docker-bake.hcl | 25 ++++++++++++ docker.yml | 31 +++++++++++++++ 7 files changed, 177 insertions(+), 104 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/version.yml create mode 100644 Dockerfile.arm64 create mode 100644 docker-bake.hcl create mode 100644 docker.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e4a6ea6..dea5044 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,15 +5,16 @@ on: push: branches: - "main" + tags: + - "[0-9]+.[0-9]+.[0-9]+" paths-ignore: - ".github/**" - "docs/**" - "**.md" - - "get_version.py" env: IMAGE_NAME: baidunetdisk-docker - DOCKERHUB_SLUG: yucatovo/baidunetdisk-docker + DOCKERHUB_SLUG: docker.io/yucatovo/baidunetdisk-docker GHCR_SLUG: ghcr.io/yucat-ovo/baidunetdisk-docker jobs: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e0efa57 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,51 @@ +name: test + +on: + workflow_dispatch: + push: + branches: + - "main" + - "develop" + tags: + - "[0-9]+.[0-9]+.[0-9]+" + paths-ignore: + - ".github/**" + - "docs/**" + - "**.md" +env: + BUILD_TAG: baidunetdisk-docker:test + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platforms: ["linux/amd64", "linux/arm64"] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set the value + id: set-vars + run: | + echo "TARGET=$(echo ${{ matrix.platforms }} | sed 's#/#-#g')" >> "$GITHUB_OUTPUT" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + platforms: ${{ matrix.platforms }} + + - name: Build + uses: docker/bake-action@v4 + with: + targets: ${{ steps.set-vars.outputs.TARGET }} + env: + DEFAULT_TAG: ${{ env.BUILD_TAG }} + + - name: Test + run: | + docker run -t --rm ${{ env.BUILD_TAG }} diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml deleted file mode 100644 index ac69818..0000000 --- a/.github/workflows/version.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Get BaiduNetdisk Version - -on: - workflow_dispatch: - schedule: - - cron: "0 3 * * 0" - push: - branches: - - "main" - paths: - - "get_version.py" - -jobs: - get-version: - name: Get BaiduNetdisk Version - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set variables - id: set-vars - run: | - RELEASE_NAME="Released on $(date +%Y%m%d%H%M)" - - echo "RELEASE_NAME=${RELEASE_NAME}" >> $GITHUB_OUTPUT - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.11.7" - - - name: Run Script - run: | - pip install -r requirements.txt - python get_version.py - - - name: Git push assets to branch - run: | - git config --local user.name "github-actions[bot]" - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add *.json - git commit -m "${{ steps.set-vars.outputs.RELEASE_NAME }}" || true - git push diff --git a/Dockerfile b/Dockerfile index 999f6b9..748845a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ # syntax=docker/dockerfile:1 +FROM docker.io/library/alpine:edge as download -FROM ghcr.io/linuxserver/baseimage-kasmvnc:debianbookworm +RUN \ + sed -i 's/dl-cdn.alpinelinux.org/mirrors.lzu.edu.cn/g' /etc/apk/repositories && \ + apk update && \ + apk add wget curl jq &&\ + wget $(curl 'https://yun.baidu.com/disk/cmsdata?platform=linux&page=1&num=1' | jq -r '.["list"][0]["url_1"]') -O /tmp/baidunetdisk.deb -# set version label -ARG BUILD_DATE -ARG VERSION -ARG TARGETPLATFORM -LABEL build_version="version:- ${VERSION} Build-date:- ${BUILD_DATE}" -LABEL maintainer="YuCat-OVO" -LABEL org.opencontainers.image.source="https://github.com/linuxserver/docker-baseimage-kasmvnc" +FROM ghcr.io/linuxserver/baseimage-kasmvnc:debianbookworm-062d5346-ls56 + +LABEL org.opencontainers.image.source="https://github.com/YuCat-OVO/BaiduNetdisk-Docker" ENV \ CUSTOM_PORT="8080" \ @@ -16,67 +17,22 @@ ENV \ HOME="/config" \ TITLE="Baidunetdisk" -COPY url.json /tmp/ - +COPY --from=download /tmp/baidunetdisk.deb /tmp/baidunetdisk.deb # add local files COPY root/ / RUN \ - TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} && \ - echo "**** arch: ${TARGETPLATFORM} ****" && \ - echo "**** add icon ****" && \ - curl -o \ - /kclient/public/icon.png \ - https://raw.githubusercontent.com/YuCat-OVO/BaiduNetdisk-Docker/master/docs/baidunetdisk.png && \ + sed -i "s/deb.debian.org/mirror.bfsu.edu.cn/g" /etc/apt/sources.list &&\ + sed -i "s/security.debian.org/mirror.bfsu.edu.cn/g" /etc/apt/sources.list &&\ echo "**** fix trusted.gpg ****" && \ mv /etc/apt/trusted.gpg /etc/apt/trusted.gpg.d/docker.gpg && \ - echo "**** install runtime packages ****" && \ - if [ -n ${TZ} ]; then \ - echo "**** TZ not found, setting up ****" && \ - export TZ=Asia/Shanghai; \ - fi && \ - export DEBIAN_FRONTEND=noninteractive && \ - apt-get update && \ + apt-get update -y && \ apt-get -yy -qq install --no-install-recommends --no-install-suggests --fix-missing \ - wget \ fonts-wqy-microhei \ fonts-wqy-zenhei \ - dbus \ - fcitx-rime \ - libnss3 \ - libopengl0 \ - libxkbcommon-x11-0 \ - libxcb-cursor0 \ - libxcb-icccm4 \ - libxcb-image0 \ - libxcb-keysyms1 \ - libxcb-randr0 \ - libxcb-render-util0 \ - libxcb-xinerama0 \ - libxdamage1 \ - poppler-utils \ - python3 \ - python3-xdg \ desktop-file-utils && \ + \ echo "**** install BaiduNetdisk ****" && \ - if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \ - echo "**** ${TARGETPLATFORM}, reading from url.json ****"; \ - BAIDUNETDISK_VERSION=$(jq -r ".[-2]" /tmp/url.json); \ - BAIDUNETDISK_URL=$(jq -r ".[-2]" /tmp/url.json); \ - elif [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \ - echo "**** ${TARGETPLATFORM}, reading from url.json ****"; \ - BAIDUNETDISK_VERSION=$(jq -r ".[-1]" /tmp/url.json); \ - BAIDUNETDISK_URL=$(jq -r ".[-1]" /tmp/url.json); \ - echo "**** ${TARGETPLATFORM}, add args ****" && \ - sed -i "s/baidunetdisk --no-sandbox/baidunetdisk --no-sandbox --disable-gpu-sandbox/g" /defaults/*; \ - else \ - echo "**** err, use default url ****" && \ - BAIDUNETDISK_URL="https://issuepcdn.baidupcs.com/issue/netdisk/LinuxGuanjia/4.17.7/baidunetdisk_4.17.7_amd64.deb"; \ - fi && \ - echo "***** Getting ${BAIDUNETDISK_URL} ****" && \ - curl -o \ - /tmp/baidunetdisk.deb -L \ - "$BAIDUNETDISK_URL" && \ for i in \ $(dpkg -I /tmp/baidunetdisk.deb | grep "Depends" | cut -c11- | awk -F ', ' '{ for(i=1; i<=NF; i++) print $i }'); \ do \ diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 new file mode 100644 index 0000000..68a2894 --- /dev/null +++ b/Dockerfile.arm64 @@ -0,0 +1,53 @@ +# syntax=docker/dockerfile:1 +FROM docker.io/library/alpine:edge as download + +RUN \ + sed -i 's/dl-cdn.alpinelinux.org/mirrors.lzu.edu.cn/g' /etc/apk/repositories && \ + apk update && \ + apk add wget curl jq &&\ + wget $(curl 'https://yun.baidu.com/disk/cmsdata?platform=linux&page=1&num=1' | jq -r '.["list"][0]["url_1"]' | sed "s/amd64/arm64/g") -O /tmp/baidunetdisk.deb + +FROM ghcr.io/linuxserver/baseimage-kasmvnc:debianbookworm-062d5346-ls56 + +LABEL org.opencontainers.image.source="https://github.com/YuCat-OVO/BaiduNetdisk-Docker" + +ENV \ + CUSTOM_PORT="8080" \ + CUSTOM_HTTPS_PORT="8181" \ + HOME="/config" \ + TITLE="Baidunetdisk" + +COPY --from=download /tmp/baidunetdisk.deb /tmp/baidunetdisk.deb +# add local files +COPY root/ / + +RUN \ + sed -i "s/deb.debian.org/mirror.bfsu.edu.cn/g" /etc/apt/sources.list &&\ + sed -i "s/security.debian.org/mirror.bfsu.edu.cn/g" /etc/apt/sources.list &&\ + echo "**** fix trusted.gpg ****" && \ + mv /etc/apt/trusted.gpg /etc/apt/trusted.gpg.d/docker.gpg && \ + apt-get update -y && \ + apt-get -yy -qq install --no-install-recommends --no-install-suggests --fix-missing \ + fonts-wqy-microhei \ + fonts-wqy-zenhei \ + desktop-file-utils && \ + \ + echo "**** install BaiduNetdisk ****" && \ + sed -i "s/baidunetdisk --no-sandbox/baidunetdisk --no-sandbox --disable-gpu-sandbox/g" /defaults/*; \ + for i in \ + $(dpkg -I /tmp/baidunetdisk.deb | grep "Depends" | cut -c11- | awk -F ', ' '{ for(i=1; i<=NF; i++) print $i }'); \ + do \ + if [ -n "$(dpkg -l | grep ^ii | grep $i)" ]; \ + then \ + echo "${i} installed,skip"; \ + else \ + apt-get -yy -qq install --no-install-recommends --no-install-suggests --fix-missing ${i}; \ + fi \ + done && \ + dpkg -i /tmp/baidunetdisk.deb && \ + echo "**** cleanup ****" && \ + apt-get clean && \ + rm -rf \ + /tmp/* \ + /var/lib/apt/lists/* \ + /var/tmp/* diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..f6ca76d --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,25 @@ +variable "TAG" { + default = "baidunetdisk-docker:latest" +} + +group "linux-amd64" { + targets = ["image-amd64"] +} +group "linux-arm64" { + targets = ["image-arm64"] +} + +target "docker-metadata-action" { + tags = ["${TAG}"] +} + +target "image-amd64" { + platforms = ["linux/amd64"] + inherits = ["docker-metadata-action"] + dockerfile = "Dockerfile" +} +target "image-arm64" { + platforms = ["linux/arm64"] + inherits = ["docker-metadata-action"] + dockerfile = "Dockerfile.arm64" +} diff --git a/docker.yml b/docker.yml new file mode 100644 index 0000000..6c3f66c --- /dev/null +++ b/docker.yml @@ -0,0 +1,31 @@ +input: + job: + package-manager: docker + allowed-updates: + - update-type: all + source: + provider: github + repo: YuCat-OVO/BaiduNetdisk-Docker + directory: / + branch: develop + commit: 16164b19aa9c08da55b0bd26fb4b2228262d0eab +output: + - type: update_dependency_list + expect: + data: + dependencies: + - name: linuxserver/baseimage-kasmvnc + requirements: + - file: Dockerfile + groups: [] + requirement: null + source: + registry: ghcr.io + tag: debianbookworm + version: debianbookworm + dependency_files: + - /Dockerfile + - type: mark_as_processed + expect: + data: + base-commit-sha: 16164b19aa9c08da55b0bd26fb4b2228262d0eab From 8ae436c56357d2bfde6237d39f4dea5a3b793d66 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 18:42:53 +0800 Subject: [PATCH 05/23] TAG --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e0efa57..cf3410f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,7 +44,7 @@ jobs: with: targets: ${{ steps.set-vars.outputs.TARGET }} env: - DEFAULT_TAG: ${{ env.BUILD_TAG }} + TAG: ${{ env.BUILD_TAG }} - name: Test run: | From cb1f0d7dd12a0148f6e3ea5e032b93ac5f83e5fb Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 18:46:10 +0800 Subject: [PATCH 06/23] Test Workflow --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cf3410f..754bb93 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,8 +6,6 @@ on: branches: - "main" - "develop" - tags: - - "[0-9]+.[0-9]+.[0-9]+" paths-ignore: - ".github/**" - "docs/**" From 0c75f9bcdafdd8d1f6f2667978914eadbd2e6189 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 18:51:10 +0800 Subject: [PATCH 07/23] Test Workflow --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 754bb93..7940ab0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,9 +7,9 @@ on: - "main" - "develop" paths-ignore: - - ".github/**" - "docs/**" - "**.md" + env: BUILD_TAG: baidunetdisk-docker:test @@ -41,7 +41,7 @@ jobs: uses: docker/bake-action@v4 with: targets: ${{ steps.set-vars.outputs.TARGET }} - env: + env: TAG: ${{ env.BUILD_TAG }} - name: Test From 6130d7016ba311b43bae18321548cc399ed6e749 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 19:24:32 +0800 Subject: [PATCH 08/23] Add registry --- .github/workflows/test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7940ab0..e84bd84 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ on: - "**.md" env: - BUILD_TAG: baidunetdisk-docker:test + BUILD_TAG: localhost:5000/yucatovo/baidunetdisk-docker:test jobs: test: @@ -20,6 +20,11 @@ jobs: fail-fast: false matrix: platforms: ["linux/amd64", "linux/arm64"] + services: + registry: + image: registry:3.0.0-alpha.1 + ports: + - 5000:5000 steps: - name: Checkout uses: actions/checkout@v4 From 2be743aad2a6a6a4aa534c7f612471fac8512cf0 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 19:31:52 +0800 Subject: [PATCH 09/23] enable push --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e84bd84..8a33a48 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,6 +45,7 @@ jobs: - name: Build uses: docker/bake-action@v4 with: + push: true targets: ${{ steps.set-vars.outputs.TARGET }} env: TAG: ${{ env.BUILD_TAG }} From 7b457eddf2e4f3d5504c76f50d7ce0b0353902ed Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 19:32:02 +0800 Subject: [PATCH 10/23] wget -nv --- Dockerfile | 2 +- Dockerfile.arm64 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 748845a..72a3a49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ RUN \ sed -i 's/dl-cdn.alpinelinux.org/mirrors.lzu.edu.cn/g' /etc/apk/repositories && \ apk update && \ apk add wget curl jq &&\ - wget $(curl 'https://yun.baidu.com/disk/cmsdata?platform=linux&page=1&num=1' | jq -r '.["list"][0]["url_1"]') -O /tmp/baidunetdisk.deb + wget -nv $(curl 'https://yun.baidu.com/disk/cmsdata?platform=linux&page=1&num=1' | jq -r '.["list"][0]["url_1"]') -O /tmp/baidunetdisk.deb FROM ghcr.io/linuxserver/baseimage-kasmvnc:debianbookworm-062d5346-ls56 diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index 68a2894..b230969 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -5,7 +5,7 @@ RUN \ sed -i 's/dl-cdn.alpinelinux.org/mirrors.lzu.edu.cn/g' /etc/apk/repositories && \ apk update && \ apk add wget curl jq &&\ - wget $(curl 'https://yun.baidu.com/disk/cmsdata?platform=linux&page=1&num=1' | jq -r '.["list"][0]["url_1"]' | sed "s/amd64/arm64/g") -O /tmp/baidunetdisk.deb + wget -nv $(curl 'https://yun.baidu.com/disk/cmsdata?platform=linux&page=1&num=1' | jq -r '.["list"][0]["url_1"]' | sed "s/amd64/arm64/g") -O /tmp/baidunetdisk.deb FROM ghcr.io/linuxserver/baseimage-kasmvnc:debianbookworm-062d5346-ls56 From d4d10d604f2f122b642ed77375d14d72128c78c6 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 19:34:54 +0800 Subject: [PATCH 11/23] Buildx network --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8a33a48..664f39c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,6 +40,7 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: + driver-opts: network=host platforms: ${{ matrix.platforms }} - name: Build From e00c6f84d0f9f2387022036b171307374b923f5f Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 20:30:05 +0800 Subject: [PATCH 12/23] Test --- .github/workflows/test.yml | 4 ++-- Dockerfile | 1 + Dockerfile.arm64 | 1 + docker.yml | 31 ------------------------------- root/usr/bin/mytest | 9 +++++++++ 5 files changed, 13 insertions(+), 33 deletions(-) delete mode 100644 docker.yml create mode 100644 root/usr/bin/mytest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 664f39c..b585372 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,8 +49,8 @@ jobs: push: true targets: ${{ steps.set-vars.outputs.TARGET }} env: - TAG: ${{ env.BUILD_TAG }} + TAG: ${{ env.BUILD_TAG }}-${{ steps.set-vars.outputs.TARGET }} - name: Test run: | - docker run -t --rm ${{ env.BUILD_TAG }} + docker run -t --rm "${{ env.BUILD_TAG }}-${{ steps.set-vars.outputs.TARGET }}" /usr/bin/mytest diff --git a/Dockerfile b/Dockerfile index 72a3a49..adf34c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,6 +44,7 @@ RUN \ fi \ done && \ dpkg -i /tmp/baidunetdisk.deb && \ + chmod +x /usr/bin/mytest && \ echo "**** cleanup ****" && \ apt-get clean && \ rm -rf \ diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index b230969..92010de 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -45,6 +45,7 @@ RUN \ fi \ done && \ dpkg -i /tmp/baidunetdisk.deb && \ + chmod +x /usr/bin/mytest && \ echo "**** cleanup ****" && \ apt-get clean && \ rm -rf \ diff --git a/docker.yml b/docker.yml deleted file mode 100644 index 6c3f66c..0000000 --- a/docker.yml +++ /dev/null @@ -1,31 +0,0 @@ -input: - job: - package-manager: docker - allowed-updates: - - update-type: all - source: - provider: github - repo: YuCat-OVO/BaiduNetdisk-Docker - directory: / - branch: develop - commit: 16164b19aa9c08da55b0bd26fb4b2228262d0eab -output: - - type: update_dependency_list - expect: - data: - dependencies: - - name: linuxserver/baseimage-kasmvnc - requirements: - - file: Dockerfile - groups: [] - requirement: null - source: - registry: ghcr.io - tag: debianbookworm - version: debianbookworm - dependency_files: - - /Dockerfile - - type: mark_as_processed - expect: - data: - base-commit-sha: 16164b19aa9c08da55b0bd26fb4b2228262d0eab diff --git a/root/usr/bin/mytest b/root/usr/bin/mytest new file mode 100644 index 0000000..6545aeb --- /dev/null +++ b/root/usr/bin/mytest @@ -0,0 +1,9 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +sudo -u root -s /bin/bash -c "/opt/baidunetdisk/baidunetdisk --no-sandbox" > /tmp/baidunetdisk_output.txt 2>&1 & +sleep 15 + +echo -e '\033[0;31m' +cat /tmp/baidunetdisk_output.txt +echo -e '\033[0m' From d4333118f8c12c3809945fb81c2cddd2cec99389 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 20:39:26 +0800 Subject: [PATCH 13/23] platform --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b585372..97a15ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - platforms: ["linux/amd64", "linux/arm64"] + platform: ["linux/amd64", "linux/arm64"] services: registry: image: registry:3.0.0-alpha.1 @@ -32,7 +32,7 @@ jobs: - name: Set the value id: set-vars run: | - echo "TARGET=$(echo ${{ matrix.platforms }} | sed 's#/#-#g')" >> "$GITHUB_OUTPUT" + echo "TARGET=$(echo ${{ matrix.platform }} | sed 's#/#-#g')" >> "$GITHUB_OUTPUT" - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -41,7 +41,7 @@ jobs: uses: docker/setup-buildx-action@v3 with: driver-opts: network=host - platforms: ${{ matrix.platforms }} + platform: ${{ matrix.platform }} - name: Build uses: docker/bake-action@v4 @@ -53,4 +53,4 @@ jobs: - name: Test run: | - docker run -t --rm "${{ env.BUILD_TAG }}-${{ steps.set-vars.outputs.TARGET }}" /usr/bin/mytest + docker run -t --rm --platform "${{ matrix.platform }}" "${{ env.BUILD_TAG }}-${{ steps.set-vars.outputs.TARGET }}" /usr/bin/mytest From cd6fbf5d1bd14b62c280f1fc1a1b1f05108a1997 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 20:46:40 +0800 Subject: [PATCH 14/23] Test arm64 sed --- Dockerfile | 1 + Dockerfile.arm64 | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index adf34c8..8d92355 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,6 +44,7 @@ RUN \ fi \ done && \ dpkg -i /tmp/baidunetdisk.deb && \ + echo "**** add test ****" && \ chmod +x /usr/bin/mytest && \ echo "**** cleanup ****" && \ apt-get clean && \ diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index 92010de..926b1c2 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -45,7 +45,9 @@ RUN \ fi \ done && \ dpkg -i /tmp/baidunetdisk.deb && \ + echo "**** add test ****" && \ chmod +x /usr/bin/mytest && \ + sed -i "s/baidunetdisk --no-sandbox/baidunetdisk --no-sandbox --disable-gpu-sandbox/g" root/usr/bin/mytest; \ echo "**** cleanup ****" && \ apt-get clean && \ rm -rf \ From 11736582edc8cd52ec454127557eaf1543c6eb51 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 21:22:10 +0800 Subject: [PATCH 15/23] QEMU Setup --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 97a15ab..bc95899 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,15 +33,17 @@ jobs: id: set-vars run: | echo "TARGET=$(echo ${{ matrix.platform }} | sed 's#/#-#g')" >> "$GITHUB_OUTPUT" + echo "ARCH=$(echo ${{ matrix.platform }} | sed 's#linux/##g')" >> "$GITHUB_OUTPUT" - name: Set up QEMU uses: docker/setup-qemu-action@v3 + with: ${{ steps.set-vars.outputs.ARCH }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: driver-opts: network=host - platform: ${{ matrix.platform }} + platforms: ${{ matrix.platform }} - name: Build uses: docker/bake-action@v4 From 32459aa2a4cb2115ad99a1ac05d54365fb85233c Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 21:23:21 +0800 Subject: [PATCH 16/23] platforms --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc95899..c6f4f79 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,8 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v3 - with: ${{ steps.set-vars.outputs.ARCH }} + with: + platforms: ${{ steps.set-vars.outputs.ARCH }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 From 6d4969841f4a48591a2b144c560878f486ca3a7d Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 21:35:54 +0800 Subject: [PATCH 17/23] add uname --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c6f4f79..f17b8bb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -56,4 +56,5 @@ jobs: - name: Test run: | - docker run -t --rm --platform "${{ matrix.platform }}" "${{ env.BUILD_TAG }}-${{ steps.set-vars.outputs.TARGET }}" /usr/bin/mytest + uname -m + docker run --rm "${{ env.BUILD_TAG }}-${{ steps.set-vars.outputs.TARGET }}" /usr/bin/mytest From 925abae38057ceae60ed986c8777ccebd0dc7b6e Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 21:47:40 +0800 Subject: [PATCH 18/23] alpine test --- .github/workflows/test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f17b8bb..c23d777 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,8 +37,6 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v3 - with: - platforms: ${{ steps.set-vars.outputs.ARCH }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -57,4 +55,4 @@ jobs: - name: Test run: | uname -m - docker run --rm "${{ env.BUILD_TAG }}-${{ steps.set-vars.outputs.TARGET }}" /usr/bin/mytest + docker run --rm --platform "${{ matrix.platform }}" alpine:edge echo hello From 2c5cbd117a1ab66d4aad6ca059faf9daa3d1fb4f Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 22:41:26 +0800 Subject: [PATCH 19/23] Build workflow --- .github/workflows/build.yml | 178 +++++++++--------------------------- .github/workflows/test.yml | 2 +- docker-bake.hcl | 4 +- 3 files changed, 45 insertions(+), 139 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dea5044..2f0fc74 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,178 +1,84 @@ name: Build & Release +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: workflow_dispatch: + inputs: + version: + description: "Version" + required: false + type: string push: branches: - "main" - tags: - - "[0-9]+.[0-9]+.[0-9]+" + - "develop" paths-ignore: - - ".github/**" - "docs/**" - "**.md" env: - IMAGE_NAME: baidunetdisk-docker DOCKERHUB_SLUG: docker.io/yucatovo/baidunetdisk-docker GHCR_SLUG: ghcr.io/yucat-ovo/baidunetdisk-docker jobs: - Build: - name: Build - outputs: - matrix: ${{ steps.platforms.outputs.matrix }} + prepare: + name: prepare runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: ["linux/amd64", "linux/arm64"] + steps: - name: Checkout uses: actions/checkout@master - - name: Create matrix - id: platforms - run: | - echo "matrix=$(docker buildx bake image-all --print | jq -cr '.target."image-all".platforms')" >>${GITHUB_OUTPUT} - - name: Set variables id: set-vars run: | - VERSION="1.0.4" - GITHUB_REF=${{ github.ref }} - BRACH=${GITHUB_REF#refs/heads/} - DATE=$(date '+%Y-%m-%dT%H:%M:%S%Z') - ARCH=${{ matrix.arch }} - PLATFORM_PAIR=${ARCH//\//-} - PLATFORM=${ARCH//linux\//} - - echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT - echo "GITHUB_REF=${GITHUB_REF}" >> $GITHUB_OUTPUT - echo "BRACH=${BRACH}" >> $GITHUB_OUTPUT - echo "DATE=${DATE}" >> $GITHUB_OUTPUT - echo "PLATFORM_PAIR=${PLATFORM_PAIR}" >> $GITHUB_OUTPUT - echo "PLATFORM=${PLATFORM}" >> $GITHUB_OUTPUT + echo "TARGET=$(echo ${{ matrix.platform }} | sed 's#/#-#g')" >> "$GITHUB_OUTPUT" + echo "ARCH=$(echo ${{ matrix.platform }} | sed 's#linux/##g')" >> "$GITHUB_OUTPUT" - name: Docker Meta - id: meta uses: docker/metadata-action@v5 + id: meta with: images: | - ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }} - ghcr.io/${{ github.repository }} + ${{ env.DOCKERHUB_SLUG }} + ${{ env.GHCR_SLUG }} tags: | - type=raw,value=${{ steps.set-vars.outputs.VERSION }} - type=raw,value=${{ steps.set-vars.outputs.BRACH }} - type=raw,value=${{ steps.set-vars.outputs.PLATFORM }} - type=raw,value=latest + type=ref,event=branch,prefix=br-,enable=${{ github.ref_name != github.event.repository.default_branch }} + type=edge,branch=develop,prefix=edge- + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + type=sha + labels: | + org.opencontainers.image.title=BaiduNetdisk-Docker + org.opencontainers.image.description=A BaiduNetdisk image base on Linuxserver.io's KasmVNC image. + org.opencontainers.image.vendor=YuCat-OVO + + - name: Rename meta bake definition file + run: | + mv "${{ steps.meta.outputs.bake-file }}" "/tmp/bake-meta.json" + + - name: Print meta bake definition file + run: | + cat "/tmp/bake-meta.json" - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} + platforms: ${{ matrix.platform }} - - name: Login to GHCR - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push by digest - id: build - uses: docker/build-push-action@v5 - with: - context: . - platforms: ${{ matrix.arch }} - build-args: | - BUILD_DATE=${{ steps.set-vars.outputs.DATE }} - VERSION=${{ steps.set-vars.outputs.VERSION }} - labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name=${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true - - - name: Export digest - run: | - mkdir -p /tmp/digests - digest="${{ steps.build.outputs.digest }}" - touch "/tmp/digests/${digest#sha256:}" - - - name: Upload digest + - name: Upload meta bake definition uses: actions/upload-artifact@v4 with: - name: digests-${{ steps.set-vars.outputs.PLATFORM_PAIR }} - path: /tmp/digests/* + name: bake-meta-${{ steps.set-vars.outputs.ARCH }} + path: /tmp/bake-meta.json if-no-files-found: error retention-days: 1 - - Merge: - runs-on: ubuntu-latest - needs: - - Build - steps: - - name: Checkout - uses: actions/checkout@master - - name: Set variables - id: set-vars - run: | - VERSION="1.0.3" - GITHUB_REF=${{ github.ref }} - BRACH=${GITHUB_REF#refs/heads/} - DATE=$(date '+%Y-%m-%dT%H:%M:%S%Z') - ACTOR=${{ github.actor }} - - echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT - echo "GITHUB_REF=${GITHUB_REF}" >> $GITHUB_OUTPUT - echo "BRACH=${BRACH}" >> $GITHUB_OUTPUT - echo "DATE=${DATE}" >> $GITHUB_OUTPUT - echo "ACTOR=${ACTOR,,}" >> $GITHUB_OUTPUT - - - name: Download digests - uses: actions/download-artifact@v4 - with: - path: /tmp/digests - pattern: digests-* - merge-multiple: true - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Docker Meta - id: meta - uses: docker/metadata-action@v5 - with: - images: | - ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }} - ghcr.io/${{ github.repository }} - tags: | - type=raw,value=${{ steps.set-vars.outputs.VERSION }} - type=raw,value=${{ steps.set-vars.outputs.BRACH }} - type=raw,value=latest - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - - - name: Login to GHCR - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Create manifest list and push - working-directory: /tmp/digests - run: | - docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ - $(printf '${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) - docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ - $(printf 'ghcr.io/${{ steps.set-vars.outputs.ACTOR }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) - - - name: Inspect image - run: | - docker buildx imagetools inspect ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c23d777..4f6c9fa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,7 +50,7 @@ jobs: push: true targets: ${{ steps.set-vars.outputs.TARGET }} env: - TAG: ${{ env.BUILD_TAG }}-${{ steps.set-vars.outputs.TARGET }} + DEFAULT_TAG: ${{ env.BUILD_TAG }}-${{ steps.set-vars.outputs.TARGET }} - name: Test run: | diff --git a/docker-bake.hcl b/docker-bake.hcl index f6ca76d..d9c1b90 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,4 +1,4 @@ -variable "TAG" { +variable "DEFAULT_TAG" { default = "baidunetdisk-docker:latest" } @@ -10,7 +10,7 @@ group "linux-arm64" { } target "docker-metadata-action" { - tags = ["${TAG}"] + tags = ["${DEFAULT_TAG}"] } target "image-amd64" { From a74791b18c3b73a391d72b71bcd3f0e13b78e803 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 22:42:51 +0800 Subject: [PATCH 20/23] Stop test --- .github/workflows/test.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f6c9fa..423503c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,13 +2,13 @@ name: test on: workflow_dispatch: - push: - branches: - - "main" - - "develop" - paths-ignore: - - "docs/**" - - "**.md" +# push: +# branches: +# - "main" +# - "develop" +# paths-ignore: +# - "docs/**" +# - "**.md" env: BUILD_TAG: localhost:5000/yucatovo/baidunetdisk-docker:test From c5be9119bc11fcb8030e2c054530db26de3bbc87 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Sun, 5 May 2024 23:42:03 +0800 Subject: [PATCH 21/23] Build --- .github/workflows/build.yml | 95 +++++++++++++++++++++++++++++-------- .github/workflows/test.yml | 9 ++-- 2 files changed, 81 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2f0fc74..9de72ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,21 +27,10 @@ jobs: prepare: name: prepare runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - platform: ["linux/amd64", "linux/arm64"] - steps: - name: Checkout uses: actions/checkout@master - - name: Set variables - id: set-vars - run: | - echo "TARGET=$(echo ${{ matrix.platform }} | sed 's#/#-#g')" >> "$GITHUB_OUTPUT" - echo "ARCH=$(echo ${{ matrix.platform }} | sed 's#linux/##g')" >> "$GITHUB_OUTPUT" - - name: Docker Meta uses: docker/metadata-action@v5 id: meta @@ -50,8 +39,8 @@ jobs: ${{ env.DOCKERHUB_SLUG }} ${{ env.GHCR_SLUG }} tags: | - type=ref,event=branch,prefix=br-,enable=${{ github.ref_name != github.event.repository.default_branch }} - type=edge,branch=develop,prefix=edge- + type=ref,event=branch,enable=${{ github.ref_name != github.event.repository.default_branch }} + type=edge,branch=develop type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} type=sha labels: | @@ -63,9 +52,43 @@ jobs: run: | mv "${{ steps.meta.outputs.bake-file }}" "/tmp/bake-meta.json" - - name: Print meta bake definition file + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Upload meta bake definition + uses: actions/upload-artifact@v4 + with: + name: bake-meta + path: /tmp/bake-meta.json + if-no-files-found: error + retention-days: 1 + + build: + runs-on: ubuntu-latest + needs: + - prepare + strategy: + fail-fast: false + matrix: + platform: ["linux/amd64", "linux/arm64"] + steps: + - name: Prepare run: | - cat "/tmp/bake-meta.json" + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV" + echo "ARCH=${platform//linux\//}" >> "$GITHUB_ENV" + + - name: Checkout + uses: actions/checkout@v4 + + - name: Download meta bake definition + uses: actions/download-artifact@v4 + with: + name: bake-meta + path: /tmp - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -73,12 +96,46 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: - platforms: ${{ matrix.platform }} + buildkitd-flags: "--debug" - - name: Upload meta bake definition + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build + id: bake + uses: docker/bake-action@v4 + with: + files: | + ./docker-bake.hcl + /tmp/bake-meta.json + targets: ${{ env.PLATFORM_PAIR }} + set: | + *.tags= + *.platform=${{ matrix.platform }} + *.cache-from=type=gha,scope=build-${{ env.PLATFORM_PAIR }} + *.cache-to=type=gha,scope=build-${{ env.PLATFORM_PAIR }} + *.output=type=image,"name=${{ env.DOCKERHUB_SLUG }},${{ env.GHCR_SLUG }}",push-by-digest=true,name-canonical=true,push=true + + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ fromJSON(steps.bake.outputs.metadata).image['containerimage.digest'] }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest uses: actions/upload-artifact@v4 with: - name: bake-meta-${{ steps.set-vars.outputs.ARCH }} - path: /tmp/bake-meta.json + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* if-no-files-found: error retention-days: 1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 423503c..a322d5d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,8 +32,9 @@ jobs: - name: Set the value id: set-vars run: | - echo "TARGET=$(echo ${{ matrix.platform }} | sed 's#/#-#g')" >> "$GITHUB_OUTPUT" - echo "ARCH=$(echo ${{ matrix.platform }} | sed 's#linux/##g')" >> "$GITHUB_OUTPUT" + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV" + echo "ARCH=${platform//linux\//}" >> "$GITHUB_ENV" - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -48,9 +49,9 @@ jobs: uses: docker/bake-action@v4 with: push: true - targets: ${{ steps.set-vars.outputs.TARGET }} + targets: ${{ env.TARGET }} env: - DEFAULT_TAG: ${{ env.BUILD_TAG }}-${{ steps.set-vars.outputs.TARGET }} + DEFAULT_TAG: ${{ env.BUILD_TAG }}-${{ env.PLATFORM_PAIR }} - name: Test run: | From 41e40388bd105eafdd21478c6e1e82ee381b42a1 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Mon, 6 May 2024 00:08:42 +0800 Subject: [PATCH 22/23] Build --- .github/workflows/build.yml | 64 +++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9de72ce..99c4e5c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,7 +102,7 @@ jobs: uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} + password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to GHCR uses: docker/login-action@v3 @@ -126,10 +126,20 @@ jobs: *.cache-to=type=gha,scope=build-${{ env.PLATFORM_PAIR }} *.output=type=image,"name=${{ env.DOCKERHUB_SLUG }},${{ env.GHCR_SLUG }}",push-by-digest=true,name-canonical=true,push=true - - name: Export digest + - name: Export digest (amd64) + if: ${{ matrix.platform }} == "linux/amd64" run: | mkdir -p /tmp/digests - digest="${{ fromJSON(steps.bake.outputs.metadata).image['containerimage.digest'] }}" + if + digest="${{ fromJSON(steps.bake.outputs.metadata).image-amd64['containerimage.digest'] }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Export digest (arm64) + if: ${{ matrix.platform }} == "linux/arm64" + run: | + mkdir -p /tmp/digests + if + digest="${{ fromJSON(steps.bake.outputs.metadata).image-arm64['containerimage.digest'] }}" touch "/tmp/digests/${digest#sha256:}" - name: Upload digest @@ -139,3 +149,51 @@ jobs: path: /tmp/digests/* if-no-files-found: error retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: + - build + steps: + - name: Download meta bake definition + uses: actions/download-artifact@v4 + with: + name: bake-meta + path: /tmp + + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.target."docker-metadata-action".tags | map(select(startswith("${{ env.DOCKERHUB_SLUG }}")) | "-t " + .) | join(" ")' /tmp/bake-meta.json) \ + $(printf '${{ env.DOCKERHUB_SLUG }}@sha256:%s ' *) + docker buildx imagetools create $(jq -cr '.target."docker-metadata-action".tags | map(select(startswith("${{ env.GHCR_SLUG }}")) | "-t " + .) | join(" ")' /tmp/bake-meta.json) \ + $(printf '${{ env.GHCR_SLUG }}@sha256:%s ' *) + + - name: Inspect image + run: | + tag=$(jq -r '.target."docker-metadata-action".args.DOCKER_META_VERSION' /tmp/bake-meta.json) + docker buildx imagetools inspect ${{ env.DOCKERHUB_SLUG }}:${tag} + docker buildx imagetools inspect ${{ env.GHCR_SLUG }}:${tag} From 42d2fec3ecb9a80553f0fac0f5fb0c64ba8abd37 Mon Sep 17 00:00:00 2001 From: YuCat <66810215+YuCat-OVO@users.noreply.github.com> Date: Mon, 6 May 2024 00:11:18 +0800 Subject: [PATCH 23/23] rm if --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 99c4e5c..8f5db56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -130,7 +130,6 @@ jobs: if: ${{ matrix.platform }} == "linux/amd64" run: | mkdir -p /tmp/digests - if digest="${{ fromJSON(steps.bake.outputs.metadata).image-amd64['containerimage.digest'] }}" touch "/tmp/digests/${digest#sha256:}" @@ -138,7 +137,6 @@ jobs: if: ${{ matrix.platform }} == "linux/arm64" run: | mkdir -p /tmp/digests - if digest="${{ fromJSON(steps.bake.outputs.metadata).image-arm64['containerimage.digest'] }}" touch "/tmp/digests/${digest#sha256:}"