加载中...
- ) : packageStore.packagesList.length === 0 ? (
-
- {packageStore.packagesList.map((item: PackageItem) => {
- const dockerValue = `docker.cnb.cool/${slug}/${item.package}:latest`;
+ {filteredPackagesList.map((item: PackageItem) => {
+ const group = getGroup(slug);
+ const dockerValue = `docker.cnb.cool/${group}/${item.package}:latest`;
const dockerPullValue = `docker pull ${dockerValue}`;
return (
@@ -185,10 +247,20 @@ export const App = () => {
复制 docker registry
+ {
+ const url = `https://cnb.cool/${slug}/-/packages/${item.package_type}/${item.package}`;
+ window.open(url, '_blank');
+ }}
+ className="cursor-pointer"
+ >
+
+ 跳转详情包
+
{
const type = 'docker';
- const url = `https://cnb.cool/${slug}/-/packages?type=${type}&ordering=last_push_at`;
+ const url = `https://cnb.cool/${slug}/-/packages?type=${type}&ordering=last_push_at&search=${item.package}`;
window.open(url, '_blank');
}}
className="cursor-pointer"
diff --git a/src/pages/cnb-packages/store/index.ts b/src/pages/cnb-packages/store/index.ts
index 5c30379..0ae2b2b 100644
--- a/src/pages/cnb-packages/store/index.ts
+++ b/src/pages/cnb-packages/store/index.ts
@@ -1,6 +1,7 @@
import { create } from 'zustand';
import { queryApi as markApi } from '@/modules/mark-api';
-import { queryApi as cnbApi } from '@/modules/package-api';
+import { queryApi as packageApi } from '@/modules/package-api';
+import { queryApi as cnbApi } from '@/modules/cnb-api';
import { toast } from 'sonner';
import { PackageItem } from './package-type';
@@ -23,6 +24,7 @@ type PackageState = {
setLoading: (loading: boolean) => void;
// CNB packages list
packagesList: PackageItem[];
+ repo: string;
packagesListLoading: boolean;
getPackagesList: (params: { slug: string, type?: string, ordering?: string, name?: string, page?: number, pageSize?: number }) => Promise;
// Dialog states
@@ -38,6 +40,7 @@ type PackageState = {
updateItem: (id: string, data: { title?: string, tags?: string[], link?: string, summary?: string, description?: string }) => Promise;
deleteItem: (id: string) => Promise;
getItem: (id: string) => Promise;
+ dockerBuild: (config: { repo: string, config: string }) => Promise;
}
export type { PackageState, PackageItem };
@@ -50,11 +53,12 @@ export const usePackageStore = create((set, get) => ({
setLoading: (loading) => set({ loading }),
packagesList: [],
packagesListLoading: false,
+ repo: '',
getPackagesList: async (params: { slug: string, type?: string, ordering?: string, name?: string, page?: number, pageSize?: number }) => {
- const { slug, type = 'all', ordering, name, page = 1, pageSize = 20 } = params;
- set({ packagesListLoading: true });
+ const { slug, type = 'all', ordering, name, page = 1, pageSize = 99 } = params;
+ set({ packagesListLoading: true, repo: slug });
try {
- const res = await cnbApi.cnb['list-packages']({
+ const res = await packageApi.cnb['list-packages']({
slug,
type,
ordering,
@@ -185,5 +189,19 @@ export const usePackageStore = create((set, get) => ({
console.error('获取详情失败', e);
return null;
}
+ },
+ dockerBuild: async (config) => {
+ const res = await cnbApi.cnb['cloud-build']({
+ repo: config.repo,
+ branch: 'main',
+ env: {} as any,
+ event: 'api_trigger_event',
+ config: config.config,
+ })
+ if (res.code === 200) {
+ toast.success('构建已触发')
+ } else {
+ toast.error(res.message || '构建触发失败')
+ }
}
}));
diff --git a/src/pages/repos/store/build.ts b/src/pages/repos/store/build.ts
index e755685..bdab99b 100644
--- a/src/pages/repos/store/build.ts
+++ b/src/pages/repos/store/build.ts
@@ -97,4 +97,42 @@ ${branch}:
# - name: 结束阶段
# script: zsh -i -c 'bun run end'
`
+}
+
+export const createDockerBuildConfig = (params: {
+ repo: string,
+ // 参考 redis:latest 这种格式的镜像名称,必须包含冒号和标签,如果没有标签则默认为 latest
+ image: string
+}) => {
+ const toRepo = params.repo!;
+ let image = params.image!;
+ const tagIndex = image.lastIndexOf(':');
+ if (tagIndex === -1) {
+ image = `${image}:latest`;
+ }
+ const tagVersion = image.split(':').pop()!;
+ const imageLastPart = image.split('/').pop()!;
+ const imageNameWithoutTag = imageLastPart.split(':')[0];
+ const pullCmd = `docker pull ${image}`;
+ const tagCmd = `docker tag ${image} docker.cnb.cool/${toRepo}/${imageLastPart}`;
+ const pushCmd = `docker push docker.cnb.cool/${toRepo}/${imageLastPart}`;
+ let pushLatestCmd = 'echo "不需要推送 latest 标签"';
+ if (tagVersion !== 'latest') {
+ pushLatestCmd = `docker tag ${image} docker.cnb.cool/${toRepo}/${imageNameWithoutTag}:latest && docker push docker.cnb.cool/${toRepo}/${imageNameWithoutTag}:latest`;
+ }
+ return `
+$:
+ api_trigger_event:
+ - docker:
+ image: cnbcool/default-dev-env:latest
+ services:
+ - docker
+ stages:
+ - name: '执行同步脚本'
+ script: |
+ ${pullCmd}
+ ${tagCmd}
+ ${pushCmd}
+ ${pushLatestCmd}
+`
}
\ No newline at end of file