-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(openshift): container Build action #4726
Changes from 2 commits
3aae47e
1e6c7a8
d1ecd4a
891cd6d
3099e45
65241b3
47c8584
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -348,7 +348,13 @@ export async function ensureUtilDeployment({ | |
|
||
export async function getManifestInspectArgs(remoteId: string, deploymentRegistry: ContainerRegistryConfig) { | ||
const dockerArgs = ["manifest", "inspect", remoteId] | ||
if (isLocalHostname(deploymentRegistry.hostname)) { | ||
const { hostname } = deploymentRegistry | ||
// Allow insecure connections on local registry | ||
if ( | ||
hostname === "localhost" || | ||
hostname.startsWith("127.") || | ||
hostname === "default-route-openshift-image-registry.apps-crc.testing" | ||
) { | ||
dockerArgs.push("--insecure") | ||
} | ||
|
||
|
@@ -393,10 +399,6 @@ export async function ensureBuilderSecret({ | |
return { authSecret, updated } | ||
} | ||
|
||
function isLocalHostname(hostname: string) { | ||
return hostname === "localhost" || hostname.startsWith("127.") | ||
} | ||
|
||
Comment on lines
-402
to
-405
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function name sounds way more generic than its actual use was, and it was used only in one place. Inlined to |
||
export function getUtilContainer(authSecretName: string, provider: KubernetesProvider): V1Container { | ||
return { | ||
name: utilContainerName, | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,57 @@ | ||||||||
import { DeepPrimitiveMap } from "@garden-io/platform-api-types" | ||||||||
import { BuildActionExtension } from "../../plugin/action-types" | ||||||||
import { ContainerBuildAction } from "../container/config" | ||||||||
import { ContainerBuildMode, KubernetesProvider } from "../kubernetes/config" | ||||||||
import { k8sGetContainerBuildActionOutputs } from "../kubernetes/container/handlers" | ||||||||
import { k8sPublishContainerBuild } from "../kubernetes/container/publish" | ||||||||
import { BuildHandler, BuildStatusHandler } from "../kubernetes/container/build/common" | ||||||||
import { getLocalBuildStatus, localBuild } from "../kubernetes/container/build/local" | ||||||||
|
||||||||
export const openshiftContainerBuildExtension = (): BuildActionExtension<ContainerBuildAction> => ({ | ||||||||
name: "container", | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a question. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is directly based on garden/core/src/plugins/kubernetes/container/extensions.ts Lines 40 to 42 in 47c8584
|
||||||||
handlers: { | ||||||||
async getOutputs({ ctx, action }) { | ||||||||
const provider = ctx.provider as KubernetesProvider | ||||||||
return { | ||||||||
outputs: k8sGetContainerBuildActionOutputs({ action, provider }) as unknown as DeepPrimitiveMap, | ||||||||
} | ||||||||
}, | ||||||||
|
||||||||
build: async (params) => { | ||||||||
const { ctx } = params | ||||||||
|
||||||||
const provider = <KubernetesProvider>ctx.provider | ||||||||
const buildMode = provider.config.buildMode || "local-docker" | ||||||||
const handler = buildHandlers[buildMode] | ||||||||
|
||||||||
return handler(params) | ||||||||
}, | ||||||||
|
||||||||
getStatus: async (params) => { | ||||||||
const { ctx } = params | ||||||||
const provider = <KubernetesProvider>ctx.provider | ||||||||
|
||||||||
const buildMode = provider.config.buildMode || "local-docker" | ||||||||
const handler = buildStatusHandlers[buildMode] | ||||||||
return handler(params) | ||||||||
}, | ||||||||
|
||||||||
publish: k8sPublishContainerBuild, | ||||||||
}, | ||||||||
}) | ||||||||
|
||||||||
const unimplemented = () => { | ||||||||
throw new Error("Unimplemented handler called in OpenShift Build") | ||||||||
} | ||||||||
|
||||||||
const buildStatusHandlers: { [mode in ContainerBuildMode]: BuildStatusHandler } = { | ||||||||
"local-docker": getLocalBuildStatus, | ||||||||
"cluster-buildkit": unimplemented, | ||||||||
"kaniko": unimplemented, | ||||||||
} | ||||||||
|
||||||||
const buildHandlers: { [mode in ContainerBuildMode]: BuildHandler } = { | ||||||||
"local-docker": localBuild, | ||||||||
"cluster-buildkit": unimplemented, | ||||||||
"kaniko": unimplemented, | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM registry.access.redhat.com/ubi8/nginx-122 | ||
ADD index.html . | ||
CMD nginx -g "daemon off;" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
kind: Build | ||
type: container | ||
name: openshift-nginx-hello | ||
# FIXME: currently this is required, otherwise you get an ENOENT when calling | ||
# containerHelpers.dockerCli({cwd: action.getBuildPath() ... }) | ||
# because the .garden/build directory is not created | ||
buildAtSource: true | ||
Comment on lines
+4
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When trying to do |
||
|
||
--- | ||
kind: Deploy | ||
type: container | ||
name: nginx-hello | ||
name: openshift-nginx-hello | ||
build: openshift-nginx-hello | ||
spec: | ||
image: registry.access.redhat.com/ubi9/nginx-122:1-12 | ||
command: ["nginx", "-g", "daemon off;"] | ||
ports: | ||
- name: http | ||
containerPort: 8080 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Hello, OpenShift!</title> | ||
<style> | ||
body, | ||
html { | ||
height: 100%; | ||
display: grid; | ||
background: #eee; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
h1 { | ||
margin: auto; | ||
font-family: sans-serif; | ||
font-size: 32pt; | ||
color: #222; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Hello, OpenShift!</h1> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun fact: here
insecure
means e.g. allowing self-signed certs etc