feat: docker-image deploy and force-deploy button and api endpoint
parent
d4b49d9955
commit
71f71811eb
@ -0,0 +1,33 @@
|
|||||||
|
import { useState } from 'preact/hooks'
|
||||||
|
|
||||||
|
// target is a url to send a POST request to
|
||||||
|
export const TriggerButton = ({ target, children }) => {
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
const handleClick = async () => {
|
||||||
|
setLoading(true)
|
||||||
|
|
||||||
|
const response = await fetch(target, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
console.log('Success')
|
||||||
|
} else {
|
||||||
|
console.log('Failure')
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return loading ? (
|
||||||
|
<button disabled class="loading">
|
||||||
|
<span class="material-symbols-outlined">refresh</span> Loading...
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<button onClick={handleClick}>{children}</button>
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
import { loadConfig } from '@/config'
|
||||||
|
import { createDeployJob } from '@/deploys'
|
||||||
|
import { enqueueJob } from '@/jobs'
|
||||||
|
import { sleep } from '@/lib/utils'
|
||||||
|
import type { APIRoute } from 'astro'
|
||||||
|
|
||||||
|
export const POST: APIRoute = async ({ params: { name } }) => {
|
||||||
|
const { deploys } = await loadConfig()
|
||||||
|
const deploy = deploys.find(d => d.name === name)
|
||||||
|
|
||||||
|
if (!deploy) {
|
||||||
|
return new Response('Deploy not found', { status: 404 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const [jobBase, deployFn] = createDeployJob(deploy, { event: 'manual' })
|
||||||
|
|
||||||
|
let onComplete
|
||||||
|
const completed = new Promise<void>(resolve => {
|
||||||
|
onComplete = resolve
|
||||||
|
})
|
||||||
|
|
||||||
|
await enqueueJob(jobBase, deployFn, onComplete)
|
||||||
|
|
||||||
|
await completed
|
||||||
|
|
||||||
|
return new Response('ok')
|
||||||
|
}
|
Loading…
Reference in New Issue