mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-17 18:26:44 +00:00
Fixed invocation of registry. Basic run works hardcoded
Console logs are left in place and should be deleted
This commit is contained in:
@@ -60,6 +60,12 @@ export const requiredPermissions = [
|
|||||||
verbs: ['create', 'delete', 'get', 'list'],
|
verbs: ['create', 'delete', 'get', 'list'],
|
||||||
resource: 'secrets',
|
resource: 'secrets',
|
||||||
subresource: ''
|
subresource: ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group: '',
|
||||||
|
verbs: ['create', 'delete', 'get', 'list'],
|
||||||
|
resource: 'configmaps',
|
||||||
|
subresource: ''
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -334,7 +340,14 @@ export async function waitForPodPhases(
|
|||||||
let phase: PodPhase = PodPhase.UNKNOWN
|
let phase: PodPhase = PodPhase.UNKNOWN
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
phase = await getPodPhase(podName)
|
try {
|
||||||
|
phase = await getPodPhase(podName)
|
||||||
|
} catch (err) {
|
||||||
|
const e = err as k8s.HttpError
|
||||||
|
if (e?.body?.reason === 'NotFound') {
|
||||||
|
phase = PodPhase.UNKNOWN
|
||||||
|
}
|
||||||
|
}
|
||||||
if (awaitingPhases.has(phase)) {
|
if (awaitingPhases.has(phase)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -482,9 +495,30 @@ export async function buildContainer(): Promise<void> {
|
|||||||
k8sApi.createNamespacedConfigMap(namespace(), cm),
|
k8sApi.createNamespacedConfigMap(namespace(), cm),
|
||||||
k8sApi.createNamespacedSecret(namespace(), secret)
|
k8sApi.createNamespacedSecret(namespace(), secret)
|
||||||
])
|
])
|
||||||
await k8sAppsV1.createNamespacedStatefulSet(namespace(), ss)
|
try {
|
||||||
await k8sApi.createNamespacedService(namespace(), svc)
|
await k8sAppsV1.createNamespacedStatefulSet(namespace(), ss)
|
||||||
await k8sApi.createNamespacedPod(namespace(), pod)
|
await waitForPodPhases(
|
||||||
|
'docker-registry-0',
|
||||||
|
new Set([PodPhase.RUNNING]),
|
||||||
|
new Set([PodPhase.PENDING, PodPhase.UNKNOWN])
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
console.log(JSON.stringify(err))
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await k8sApi.createNamespacedService(namespace(), svc)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(JSON.stringify(err))
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await k8sApi.createNamespacedPod(namespace(), pod)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(JSON.stringify(err))
|
||||||
|
throw err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCurrentNodeName(): Promise<string> {
|
async function getCurrentNodeName(): Promise<string> {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import * as k8s from '@kubernetes/client-node'
|
import * as k8s from '@kubernetes/client-node'
|
||||||
|
|
||||||
const REGISTRY_CONFIG_MAP_YAML = `
|
const REGISTRY_CONFIG_MAP_YAML = `
|
||||||
|
storage:
|
||||||
|
filesystem:
|
||||||
|
rootdirectory: /var/lib/registry
|
||||||
|
maxthreads: 100
|
||||||
health:
|
health:
|
||||||
storagedriver:
|
storagedriver:
|
||||||
enabled: true
|
enabled: true
|
||||||
@@ -96,6 +100,13 @@ export function registryStatefulSet(): k8s.V1StatefulSet {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
c.volumeMounts = [
|
||||||
|
{
|
||||||
|
mountPath: '/etc/docker/registry',
|
||||||
|
name: 'docker-registry-config'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
c.livenessProbe = new k8s.V1Probe()
|
c.livenessProbe = new k8s.V1Probe()
|
||||||
c.livenessProbe.failureThreshold = 3
|
c.livenessProbe.failureThreshold = 3
|
||||||
c.livenessProbe.periodSeconds = 10
|
c.livenessProbe.periodSeconds = 10
|
||||||
@@ -118,12 +129,6 @@ export function registryStatefulSet(): k8s.V1StatefulSet {
|
|||||||
|
|
||||||
tmpl.spec.containers = [c]
|
tmpl.spec.containers = [c]
|
||||||
tmpl.spec.volumes = [
|
tmpl.spec.volumes = [
|
||||||
{
|
|
||||||
name: 'data',
|
|
||||||
persistentVolumeClaim: {
|
|
||||||
claimName: 'docker-registry'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'docker-registry-config',
|
name: 'docker-registry-config',
|
||||||
configMap: {
|
configMap: {
|
||||||
@@ -133,22 +138,6 @@ export function registryStatefulSet(): k8s.V1StatefulSet {
|
|||||||
]
|
]
|
||||||
|
|
||||||
spec.template = tmpl
|
spec.template = tmpl
|
||||||
spec.volumeClaimTemplates = [
|
|
||||||
{
|
|
||||||
metadata: {
|
|
||||||
name: 'data'
|
|
||||||
},
|
|
||||||
spec: {
|
|
||||||
accessModes: ['ReadWriteOnce'],
|
|
||||||
storageClassName: 'local-storage',
|
|
||||||
resources: {
|
|
||||||
requests: {
|
|
||||||
storage: '5Gi'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
ss.spec = spec
|
ss.spec = spec
|
||||||
|
|
||||||
return ss
|
return ss
|
||||||
@@ -196,19 +185,20 @@ export function kanikoPod(): k8s.V1Pod {
|
|||||||
c.image = 'gcr.io/kaniko-project/executor:latest'
|
c.image = 'gcr.io/kaniko-project/executor:latest'
|
||||||
c.name = 'kaniko'
|
c.name = 'kaniko'
|
||||||
c.imagePullPolicy = 'Always'
|
c.imagePullPolicy = 'Always'
|
||||||
|
c.env = [
|
||||||
|
{
|
||||||
|
name: 'GIT_TOKEN',
|
||||||
|
value: process.env.GITHUB_TOKEN
|
||||||
|
}
|
||||||
|
]
|
||||||
c.args = [
|
c.args = [
|
||||||
'--dockerfile=',
|
'--dockerfile=Dockerfile',
|
||||||
'--context=',
|
'--context=git://github.com/nikola-jokic/dockeraction.git',
|
||||||
'--destination=docker-registry.default.svc.cluster.local:5000/test/app:1.0'
|
'--destination=docker-registry.default.svc.cluster.local:5000/test/app:1.0'
|
||||||
]
|
]
|
||||||
c.volumeMounts = [
|
spec.containers = [c]
|
||||||
// TODO: ...
|
|
||||||
]
|
|
||||||
spec.dnsPolicy = 'ClusterFirst'
|
spec.dnsPolicy = 'ClusterFirst'
|
||||||
spec.restartPolicy = 'Never'
|
spec.restartPolicy = 'Never'
|
||||||
spec.volumes = [
|
|
||||||
// TODO: ...
|
|
||||||
]
|
|
||||||
pod.spec = spec
|
pod.spec = spec
|
||||||
|
|
||||||
return pod
|
return pod
|
||||||
|
|||||||
14
packages/k8s/tests/build-container-test.ts
Normal file
14
packages/k8s/tests/build-container-test.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { buildContainer } from '../src/k8s'
|
||||||
|
import { TestHelper } from './test-setup'
|
||||||
|
|
||||||
|
jest.useRealTimers()
|
||||||
|
|
||||||
|
describe('container build', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
process.env['ACTIONS_RUNNER_KUBERNETES_NAMESPACE'] = 'default'
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should finish without throwing an exception', async () => {
|
||||||
|
await expect(buildContainer()).resolves.not.toThrow()
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user