Skip to content

Commit 30fc3bd

Browse files
authored
Adds allowInsecureRegistries parameter to allow HTTP. (GoogleContainerTools#450)
1 parent 3a8ee13 commit 30fc3bd

8 files changed

Lines changed: 31 additions & 4 deletions

File tree

‎jib-gradle-plugin/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
66
### Added
77

88
- `container.ports` parameter to define container's exposed ports (similar to Dockerfile `EXPOSE`) ([#383](https://github.com/GoogleContainerTools/jib/issues/383))
9+
- Can set `allowInsecureRegistries` parameter to `true` to use registries that only support HTTP ([#388](https://github.com/GoogleContainerTools/jib/issues/388))
910

1011
### Changed
1112

‎jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildDockerTask.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public void buildDocker() throws InvalidImageReferenceException {
108108
.setMainClass(mainClass)
109109
.setJavaArguments(jibExtension.getArgs())
110110
.setJvmFlags(jibExtension.getJvmFlags())
111-
.setExposedPorts(jibExtension.getExposedPorts());
111+
.setExposedPorts(jibExtension.getExposedPorts())
112+
.setAllowHttp(jibExtension.getAllowInsecureRegistries());
112113
CacheConfiguration applicationLayersCacheConfiguration =
113114
CacheConfiguration.forPath(gradleProjectProperties.getCacheDirectory());
114115
buildConfigurationBuilder.setApplicationLayersCacheConfiguration(

‎jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildImageTask.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public void buildImage() throws InvalidImageReferenceException {
111111
.setJavaArguments(jibExtension.getArgs())
112112
.setJvmFlags(jibExtension.getJvmFlags())
113113
.setExposedPorts(jibExtension.getExposedPorts())
114-
.setTargetFormat(jibExtension.getFormat());
114+
.setTargetFormat(jibExtension.getFormat())
115+
.setAllowHttp(jibExtension.getAllowInsecureRegistries());
115116
CacheConfiguration applicationLayersCacheConfiguration =
116117
CacheConfiguration.forPath(gradleProjectProperties.getCacheDirectory());
117118
buildConfigurationBuilder.setApplicationLayersCacheConfiguration(

‎jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ public class JibExtension {
6464
// Defines default configuration values.
6565
private static final String DEFAULT_FROM_IMAGE = "gcr.io/distroless/java";
6666
private static final boolean DEFAULT_USE_ONLY_PROJECT_CACHE = false;
67+
private static final boolean DEFAULT_ALLOW_INSECURE_REGISTIRIES = false;
6768

6869
private final ImageConfiguration from;
6970
private final ImageConfiguration to;
7071
private final ContainerParameters container;
7172
private final Property<Boolean> useOnlyProjectCache;
73+
private final Property<Boolean> allowInsecureRegistries;
7274

7375
// TODO: Deprecated parameters; remove these 4
7476
private final ListProperty<String> jvmFlags;
@@ -89,12 +91,14 @@ public JibExtension(Project project) {
8991
format = objectFactory.property(ImageFormat.class);
9092

9193
useOnlyProjectCache = objectFactory.property(Boolean.class);
94+
allowInsecureRegistries = objectFactory.property(Boolean.class);
9295

9396
// Sets defaults.
9497
from.setImage(DEFAULT_FROM_IMAGE);
9598
jvmFlags.set(Collections.emptyList());
9699
args.set(Collections.emptyList());
97100
useOnlyProjectCache.set(DEFAULT_USE_ONLY_PROJECT_CACHE);
101+
allowInsecureRegistries.set(DEFAULT_ALLOW_INSECURE_REGISTIRIES);
98102
}
99103

100104
/**
@@ -168,6 +172,10 @@ public void setUseOnlyProjectCache(boolean useOnlyProjectCache) {
168172
this.useOnlyProjectCache.set(useOnlyProjectCache);
169173
}
170174

175+
public void setAllowInsecureRegistries(boolean allowInsecureRegistries) {
176+
this.allowInsecureRegistries.set(allowInsecureRegistries);
177+
}
178+
171179
@Internal
172180
String getBaseImage() {
173181
return Preconditions.checkNotNull(from.getImage());
@@ -237,4 +245,10 @@ List<String> getExposedPorts() {
237245
boolean getUseOnlyProjectCache() {
238246
return useOnlyProjectCache.get();
239247
}
248+
249+
@Input
250+
@Optional
251+
boolean getAllowInsecureRegistries() {
252+
return allowInsecureRegistries.get();
253+
}
240254
}

‎jib-maven-plugin/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
66
### Added
77

88
- `<container><ports>` parameter to define container's exposed ports (similar to Dockerfile `EXPOSE`) ([#383](https://github.com/GoogleContainerTools/jib/issues/383))
9+
- Can set `allowInsecureRegistries` parameter to `true` to use registries that only support HTTP ([#388](https://github.com/GoogleContainerTools/jib/issues/388))
910

1011
### Changed
1112

‎jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/BuildDockerMojo.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public void execute() throws MojoExecutionException {
8888
.setJavaArguments(getArgs())
8989
.setJvmFlags(getJvmFlags())
9090
.setEnvironment(getEnvironment())
91-
.setExposedPorts(getExposedPorts());
91+
.setExposedPorts(getExposedPorts())
92+
.setAllowHttp(getAllowInsecureRegistries());
9293
CacheConfiguration applicationLayersCacheConfiguration =
9394
CacheConfiguration.forPath(mavenProjectProperties.getCacheDirectory());
9495
buildConfigurationBuilder.setApplicationLayersCacheConfiguration(

‎jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/BuildImageMojo.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
105105
.setJvmFlags(getJvmFlags())
106106
.setEnvironment(getEnvironment())
107107
.setExposedPorts(getExposedPorts())
108-
.setTargetFormat(ImageFormat.valueOf(getFormat()).getManifestTemplateClass());
108+
.setTargetFormat(ImageFormat.valueOf(getFormat()).getManifestTemplateClass())
109+
.setAllowHttp(getAllowInsecureRegistries());
109110
CacheConfiguration applicationLayersCacheConfiguration =
110111
CacheConfiguration.forPath(mavenProjectProperties.getCacheDirectory());
111112
buildConfigurationBuilder.setApplicationLayersCacheConfiguration(

‎jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/JibPluginConfiguration.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ void handleDeprecatedParameters(BuildLogger logger) {
155155
@Parameter(defaultValue = "false", required = true)
156156
private boolean useOnlyProjectCache;
157157

158+
@Parameter(defaultValue = "false", required = true)
159+
private boolean allowInsecureRegistries;
160+
158161
MavenProject getProject() {
159162
return Preconditions.checkNotNull(project);
160163
}
@@ -208,6 +211,10 @@ boolean getUseOnlyProjectCache() {
208211
return useOnlyProjectCache;
209212
}
210213

214+
boolean getAllowInsecureRegistries() {
215+
return allowInsecureRegistries;
216+
}
217+
211218
@VisibleForTesting
212219
void setJvmFlags(List<String> jvmFlags) {
213220
this.jvmFlags = jvmFlags;

0 commit comments

Comments
 (0)