6.3. 在受限环境中启用工件存储库
通过配置技术堆栈,您可以使用自签名证书处理来自托管软件仓库的工件:
6.3.1. Maven
您可以在受限环境中运行的 Maven 工作区中启用 Maven 工件存储库。
先决条件
- 您没有运行任何 Maven 工作区。
-
您知道您的用户命名空间,即 <
username> -devspaces
,其中 <username&
gt; 是 OpenShift Dev Spaces 用户名。
流程
在 &
lt;username> -devspaces
命名空间中,为 TLS 证书应用 Secret:kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /home/user/certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: tls.cer: >- <Base64_encoded_content_of_public_cert> 1
- 1
- 禁用行嵌套的 Base64 编码。
在 &
lt;username> -devspaces
命名空间中,应用 ConfigMap 来创建settings.xml
文件:kind: ConfigMap apiVersion: v1 metadata: name: settings-xml annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /home/user/.m2 labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: settings.xml: | <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository/> <interactiveMode/> <offline/> <pluginGroups/> <servers/> <mirrors> <mirror> <id>redhat-ga-mirror</id> <name>Red Hat GA</name> <url>https://<maven_artifact_repository_route>/repository/redhat-ga/</url> <mirrorOf>redhat-ga</mirrorOf> </mirror> <mirror> <id>maven-central-mirror</id> <name>Maven Central</name> <url>https://<maven_artifact_repository_route>/repository/maven-central/</url> <mirrorOf>maven-central</mirrorOf> </mirror> <mirror> <id>jboss-public-repository-mirror</id> <name>JBoss Public Maven Repository</name> <url>https://<maven_artifact_repository_route>/repository/jboss-public/</url> <mirrorOf>jboss-public-repository</mirrorOf> </mirror> </mirrors> <proxies/> <profiles/> <activeProfiles/> </settings>
-
可选:在使用基于 JBoss EAP 的 devfile 时,在 <
username>-devspaces
命名空间中应用第二个settings-xml
ConfigMap,并具有相同的内容、不同的名称和/home/jboss/.m2
挂载路径。 在 &
lt;username> -devspaces
命名空间中,为 TrustStore 初始化脚本应用 ConfigMap:Java 8
kind: ConfigMap apiVersion: v1 metadata: name: init-truststore annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /home/user/ labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: init-java8-truststore.sh: | #!/usr/bin/env bash keytool -importcert -noprompt -file /home/user/certs/tls.cer -trustcacerts -keystore ~/.java/current/jre/lib/security/cacerts -storepass changeit
Java 11
kind: ConfigMap apiVersion: v1 metadata: name: init-truststore annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /home/user/ labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: init-java11-truststore.sh: | #!/usr/bin/env bash keytool -importcert -noprompt -file /home/user/certs/tls.cer -cacerts -storepass changeit
- 启动 Maven 工作区。
-
在
tools
容器中打开一个新的终端。 -
运行
~/init-truststore.sh
。
6.3.2. gradle
您可以在受限环境中运行的 Gradle 工作区中启用 Gradle 工件存储库。
先决条件
- 您没有运行任何 Gradle 工作区。
流程
为 TLS 证书应用 Secret:
kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /home/user/certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: tls.cer: >- <Base64_encoded_content_of_public_cert> 1
- 1
- 禁用行嵌套的 Base64 编码。
为 TrustStore 初始化脚本应用 ConfigMap:
kind: ConfigMap apiVersion: v1 metadata: name: init-truststore annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /home/user/ labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: init-truststore.sh: | #!/usr/bin/env bash keytool -importcert -noprompt -file /home/user/certs/tls.cer -cacerts -storepass changeit
为 Gradle init 脚本应用 ConfigMap:
kind: ConfigMap apiVersion: v1 metadata: name: init-gradle annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /home/user/.gradle labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: init.gradle: | allprojects { repositories { mavenLocal () maven { url "https://<gradle_artifact_repository_route>/repository/maven-public/" credentials { username "admin" password "passwd" } } } }
- 启动 Gradle 工作区。
-
在
tools
容器中打开一个新的终端。 -
运行
~/init-truststore.sh
。
6.3.3. npm
您可以在受限环境中运行的 npm 工作区中启用 npm 工件存储库。
先决条件
- 您没有运行任何 npm 工作区。
应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。
如果您遇到此行为,请删除 ConfigMap
并直接编辑 devfile。
流程
为 TLS 证书应用 Secret:
kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /home/user/certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: tls.cer: >- <Base64_encoded_content_of_public_cert> 1
- 1
- 禁用行嵌套的 Base64 编码。
应用 ConfigMap 在
tools
容器中设置以下环境变量:kind: ConfigMap apiVersion: v1 metadata: name: disconnected-env annotations: controller.devfile.io/mount-as: env labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: NODE_EXTRA_CA_CERTS: /home/user/certs/tls.cer NPM_CONFIG_REGISTRY: >- https://<npm_artifact_repository_route>/repository/npm-all/
6.3.4. Python
您可以在受限环境中运行的 Python 工作区中启用 Python 工件存储库。
先决条件
- 您没有运行任何 Python 工作区。
应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。
如果您遇到此行为,请删除 ConfigMap
并直接编辑 devfile。
流程
为 TLS 证书应用 Secret:
kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /home/user/certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: tls.cer: >- <Base64_encoded_content_of_public_cert> 1
- 1
- 禁用行嵌套的 Base64 编码。
应用 ConfigMap 在
tools
容器中设置以下环境变量:kind: ConfigMap apiVersion: v1 metadata: name: disconnected-env annotations: controller.devfile.io/mount-as: env labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: PIP_INDEX_URL: >- https://<python_artifact_repository_route>/repository/pypi-all/ PIP_CERT: /home/user/certs/tls.cer
6.3.5. Go
您可以在受限环境中运行的 Go 工作区中启用 Go 工件存储库。
先决条件
- 您没有运行任何 Go 工作区。
应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。
如果您遇到此行为,请删除 ConfigMap
并直接编辑 devfile。
流程
为 TLS 证书应用 Secret:
kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /home/user/certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: tls.cer: >- <Base64_encoded_content_of_public_cert> 1
- 1
- 禁用行嵌套的 Base64 编码。
应用 ConfigMap 在
tools
容器中设置以下环境变量:kind: ConfigMap apiVersion: v1 metadata: name: disconnected-env annotations: controller.devfile.io/mount-as: env labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: GOPROXY: >- http://<athens_proxy_route> SSL_CERT_FILE: /home/user/certs/tls.cer
6.3.6. NuGet
您可以在受限环境中运行的 NuGet 工作区中启用 NuGet 工件存储库。
先决条件
- 您没有运行任何 NuGet 工作区。
应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。
如果您遇到此行为,请删除 ConfigMap
并直接编辑 devfile。
流程
为 TLS 证书应用 Secret:
kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /home/user/certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: tls.cer: >- <Base64_encoded_content_of_public_cert> 1
- 1
- 禁用行嵌套的 Base64 编码。
应用 ConfigMap 来设置
工具
容器中 TLS 证书文件的路径的环境变量:kind: ConfigMap apiVersion: v1 metadata: name: disconnected-env annotations: controller.devfile.io/mount-as: env labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: SSL_CERT_FILE: /home/user/certs/tls.cer
应用 ConfigMap 以创建
nuget.config
文件:kind: ConfigMap apiVersion: v1 metadata: name: init-nuget annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /projects labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: nuget.config: | <?xml version="1.0" encoding="UTF-8"?> <configuration> <packageSources> <add key="nexus2" value="https://<nuget_artifact_repository_route>/repository/nuget-group/"/> </packageSources> <packageSourceCredentials> <nexus2> <add key="Username" value="admin" /> <add key="Password" value="passwd" /> </nexus2> </packageSourceCredentials> </configuration>