-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
3,992 additions
and
1,623 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
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,49 @@ | ||
const router = require('@koa/router')(); | ||
const SessionMiddleware = require('../middlewares/session'); | ||
const PaginationMiddleware = require('../middlewares/pagination'); | ||
const docker = require('../libs/docker'); | ||
|
||
/** | ||
* Convert images from Docker Hub to releases | ||
* | ||
* @param {Array<Object>} images - ref: https://hub.docker.com/v2/repositories/fedlearner/fedlearner-web-console/tags/ | ||
* @return {Array<Object>} - checkout `tests/fixtures/activity.js` for schema detail | ||
*/ | ||
function mapImageToRelease(images) { | ||
return images.map(x => ({ | ||
id: x.images[0].digest, | ||
type: 'release', | ||
creator: 'bytedance', | ||
created_at: x.tag_last_pushed, | ||
ctx: { | ||
docker: x, | ||
// fake github data | ||
github: { | ||
html_url: `https://github.com/bytedance/fedlearner/releases/tag/${x.name}`, | ||
tag_name: x.name, | ||
published_at: x.tag_last_pushed, | ||
author: { | ||
login: 'bytedance', | ||
avatar_url: 'https://avatars3.githubusercontent.com/u/4158466?v=4', | ||
html_url: 'https://github.com/bytedance', | ||
}, | ||
}, | ||
}, | ||
})); | ||
} | ||
|
||
router.get('/api/v1/activities', SessionMiddleware, PaginationMiddleware, async (ctx) => { | ||
let page = 1; | ||
let pageSize = 10; | ||
|
||
if (ctx.pagination.limit > 0 && ctx.pagination.offset >= 0) { | ||
page = ctx.pagination.offset / ctx.pagination.limit + 1; | ||
pageSize = ctx.pagination.limit; | ||
} | ||
|
||
// 'v' is used to filter standard versions | ||
const { count, results } = await docker.listImageTags('fedlearner/fedlearner-web-console', 'v', page, pageSize); | ||
ctx.body = { count, data: mapImageToRelease(results) }; | ||
}); | ||
|
||
module.exports = router; |
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,24 @@ | ||
/** | ||
* Common proxy of Kubernetes Deployment API | ||
*/ | ||
|
||
const router = require('@koa/router')(); | ||
const SessionMiddleware = require('../middlewares/session'); | ||
const k8s = require('../libs/k8s'); | ||
|
||
router.get('/api/v1/deployments', SessionMiddleware, async (ctx) => { | ||
const res = await k8s.listDeployments(); | ||
ctx.body = { data: res.deployments.items }; | ||
}); | ||
|
||
router.get('/api/v1/deployments/:name', SessionMiddleware, async (ctx) => { | ||
const { deployment: data } = await k8s.getDeployment(ctx.params.name); | ||
ctx.body = { data }; | ||
}); | ||
|
||
router.put('/api/v1/deployments/:name', SessionMiddleware, async (ctx) => { | ||
const { deployment: data } = await k8s.updateDeployment(ctx.request.body); | ||
ctx.body = { data }; | ||
}); | ||
|
||
module.exports = router; |
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
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
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,56 @@ | ||
import React from 'react'; | ||
import css from 'styled-jsx/css'; | ||
import { Avatar, Link, Text, useTheme } from '@zeit-ui/react'; | ||
import { humanizeDuration } from '../utils/time'; | ||
|
||
function useStyles(theme) { | ||
return css` | ||
.event { | ||
display: flex; | ||
align-items: center; | ||
padding: 10px 0px; | ||
border-bottom: 1px solid ${theme.palette.accents_2}; | ||
font-size: 14px; | ||
} | ||
`; | ||
} | ||
|
||
function renderRelease(activity) { | ||
const { creator, created_at, ctx } = activity; | ||
const { author, html_url, tag_name } = ctx.github; | ||
|
||
return ( | ||
<> | ||
<Link href={author.html_url} target="_blank" rel="noopenner noreferer"> | ||
<Avatar | ||
src={author.avatar_url} | ||
alt={`${creator} Avatar`} | ||
/> | ||
</Link> | ||
<div style={{ flex: 1, display: 'flex', alignItems: 'center', margin: '0 0 0 10px' }}> | ||
<Text b> | ||
<Link href={author.html_url} target="_blank" rel="noopenner noreferer">{creator}</Link> | ||
</Text> | ||
<Text style={{ margin: '0 4px' }}>released version</Text> | ||
<Text b> | ||
<Link href={html_url} target="_blank" rel="noopenner noreferer">{tag_name}</Link> | ||
</Text> | ||
</div> | ||
<Text type="secondary">{humanizeDuration(created_at)}</Text> | ||
</> | ||
); | ||
} | ||
|
||
export default function ActivityListItem({ activity }) { | ||
const theme = useTheme(); | ||
const styles = useStyles(theme); | ||
const { type } = activity; | ||
|
||
return ( | ||
<div className="event"> | ||
{type === 'release' && renderRelease(activity)} | ||
{/* render other type of activity here */} | ||
<style jsx>{styles}</style> | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.