Skip to content

Commit fa472c1

Browse files
committed
Support private registries
1 parent 863bb02 commit fa472c1

File tree

12 files changed

+388
-261
lines changed

12 files changed

+388
-261
lines changed

Diff for: components/image-builder-api/go/imgbuilder.pb.go

+152-134
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: components/image-builder-api/imgbuilder.proto

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ message ResolveWorkspaceImageResponse {
6464
message BuildRequest {
6565
BuildSource source = 1;
6666
BuildRegistryAuth auth = 2;
67-
bool forceRebuild = 3;
67+
bool force_rebuild = 3;
6868
}
6969

7070
message BuildRegistryAuth {
7171
oneof mode {
7272
BuildRegistryAuthTotal total = 1;
7373
BuildRegistryAuthSelective selective = 2;
7474
}
75+
map<string, string> additional = 3;
7576
}
7677

7778
message BuildRegistryAuthTotal {

Diff for: components/image-builder-api/typescript/src/imgbuilder_pb.d.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ export class BuildRequest extends jspb.Message {
215215
clearAuth(): void;
216216
getAuth(): BuildRegistryAuth | undefined;
217217
setAuth(value?: BuildRegistryAuth): BuildRequest;
218-
getForcerebuild(): boolean;
219-
setForcerebuild(value: boolean): BuildRequest;
218+
getForceRebuild(): boolean;
219+
setForceRebuild(value: boolean): BuildRequest;
220220

221221
serializeBinary(): Uint8Array;
222222
toObject(includeInstance?: boolean): BuildRequest.AsObject;
@@ -232,7 +232,7 @@ export namespace BuildRequest {
232232
export type AsObject = {
233233
source?: BuildSource.AsObject,
234234
auth?: BuildRegistryAuth.AsObject,
235-
forcerebuild: boolean,
235+
forceRebuild: boolean,
236236
}
237237
}
238238

@@ -248,6 +248,9 @@ export class BuildRegistryAuth extends jspb.Message {
248248
getSelective(): BuildRegistryAuthSelective | undefined;
249249
setSelective(value?: BuildRegistryAuthSelective): BuildRegistryAuth;
250250

251+
getAdditionalMap(): jspb.Map<string, string>;
252+
clearAdditionalMap(): void;
253+
251254
getModeCase(): BuildRegistryAuth.ModeCase;
252255

253256
serializeBinary(): Uint8Array;
@@ -264,6 +267,8 @@ export namespace BuildRegistryAuth {
264267
export type AsObject = {
265268
total?: BuildRegistryAuthTotal.AsObject,
266269
selective?: BuildRegistryAuthSelective.AsObject,
270+
271+
additionalMap: Array<[string, string]>,
267272
}
268273

269274
export enum ModeCase {

Diff for: components/image-builder-api/typescript/src/imgbuilder_pb.js

+40-7
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ proto.builder.BuildRequest.toObject = function(includeInstance, msg) {
17641764
var f, obj = {
17651765
source: (f = msg.getSource()) && proto.builder.BuildSource.toObject(includeInstance, f),
17661766
auth: (f = msg.getAuth()) && proto.builder.BuildRegistryAuth.toObject(includeInstance, f),
1767-
forcerebuild: jspb.Message.getBooleanFieldWithDefault(msg, 3, false)
1767+
forceRebuild: jspb.Message.getBooleanFieldWithDefault(msg, 3, false)
17681768
};
17691769

17701770
if (includeInstance) {
@@ -1813,7 +1813,7 @@ proto.builder.BuildRequest.deserializeBinaryFromReader = function(msg, reader) {
18131813
break;
18141814
case 3:
18151815
var value = /** @type {boolean} */ (reader.readBool());
1816-
msg.setForcerebuild(value);
1816+
msg.setForceRebuild(value);
18171817
break;
18181818
default:
18191819
reader.skipField();
@@ -1860,7 +1860,7 @@ proto.builder.BuildRequest.serializeBinaryToWriter = function(message, writer) {
18601860
proto.builder.BuildRegistryAuth.serializeBinaryToWriter
18611861
);
18621862
}
1863-
f = message.getForcerebuild();
1863+
f = message.getForceRebuild();
18641864
if (f) {
18651865
writer.writeBool(
18661866
3,
@@ -1945,10 +1945,10 @@ proto.builder.BuildRequest.prototype.hasAuth = function() {
19451945

19461946

19471947
/**
1948-
* optional bool forceRebuild = 3;
1948+
* optional bool force_rebuild = 3;
19491949
* @return {boolean}
19501950
*/
1951-
proto.builder.BuildRequest.prototype.getForcerebuild = function() {
1951+
proto.builder.BuildRequest.prototype.getForceRebuild = function() {
19521952
return /** @type {boolean} */ (jspb.Message.getBooleanFieldWithDefault(this, 3, false));
19531953
};
19541954

@@ -1957,7 +1957,7 @@ proto.builder.BuildRequest.prototype.getForcerebuild = function() {
19571957
* @param {boolean} value
19581958
* @return {!proto.builder.BuildRequest} returns this
19591959
*/
1960-
proto.builder.BuildRequest.prototype.setForcerebuild = function(value) {
1960+
proto.builder.BuildRequest.prototype.setForceRebuild = function(value) {
19611961
return jspb.Message.setProto3BooleanField(this, 3, value);
19621962
};
19631963

@@ -2021,7 +2021,8 @@ proto.builder.BuildRegistryAuth.prototype.toObject = function(opt_includeInstanc
20212021
proto.builder.BuildRegistryAuth.toObject = function(includeInstance, msg) {
20222022
var f, obj = {
20232023
total: (f = msg.getTotal()) && proto.builder.BuildRegistryAuthTotal.toObject(includeInstance, f),
2024-
selective: (f = msg.getSelective()) && proto.builder.BuildRegistryAuthSelective.toObject(includeInstance, f)
2024+
selective: (f = msg.getSelective()) && proto.builder.BuildRegistryAuthSelective.toObject(includeInstance, f),
2025+
additionalMap: (f = msg.getAdditionalMap()) ? f.toObject(includeInstance, undefined) : []
20252026
};
20262027

20272028
if (includeInstance) {
@@ -2068,6 +2069,12 @@ proto.builder.BuildRegistryAuth.deserializeBinaryFromReader = function(msg, read
20682069
reader.readMessage(value,proto.builder.BuildRegistryAuthSelective.deserializeBinaryFromReader);
20692070
msg.setSelective(value);
20702071
break;
2072+
case 3:
2073+
var value = msg.getAdditionalMap();
2074+
reader.readMessage(value, function(message, reader) {
2075+
jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readString, jspb.BinaryReader.prototype.readString, null, "", "");
2076+
});
2077+
break;
20712078
default:
20722079
reader.skipField();
20732080
break;
@@ -2113,6 +2120,10 @@ proto.builder.BuildRegistryAuth.serializeBinaryToWriter = function(message, writ
21132120
proto.builder.BuildRegistryAuthSelective.serializeBinaryToWriter
21142121
);
21152122
}
2123+
f = message.getAdditionalMap(true);
2124+
if (f && f.getLength() > 0) {
2125+
f.serializeBinary(3, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeString);
2126+
}
21162127
};
21172128

21182129

@@ -2190,6 +2201,28 @@ proto.builder.BuildRegistryAuth.prototype.hasSelective = function() {
21902201
};
21912202

21922203

2204+
/**
2205+
* map<string, string> additional = 3;
2206+
* @param {boolean=} opt_noLazyCreate Do not create the map if
2207+
* empty, instead returning `undefined`
2208+
* @return {!jspb.Map<string,string>}
2209+
*/
2210+
proto.builder.BuildRegistryAuth.prototype.getAdditionalMap = function(opt_noLazyCreate) {
2211+
return /** @type {!jspb.Map<string,string>} */ (
2212+
jspb.Message.getMapField(this, 3, opt_noLazyCreate,
2213+
null));
2214+
};
2215+
2216+
2217+
/**
2218+
* Clears values from the map. The map will be non-null.
2219+
* @return {!proto.builder.BuildRegistryAuth} returns this
2220+
*/
2221+
proto.builder.BuildRegistryAuth.prototype.clearAdditionalMap = function() {
2222+
this.getAdditionalMap().clear();
2223+
return this;};
2224+
2225+
21932226

21942227

21952228

Diff for: components/image-builder-bob/cmd/proxy.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
var proxyOpts struct {
2121
BaseRef, TargetRef string
2222
Auth string
23+
AdditionalAuth string
2324
}
2425

2526
// proxyCmd represents the build command
@@ -30,10 +31,15 @@ var proxyCmd = &cobra.Command{
3031
log.Init("bob", "", true, os.Getenv("SUPERVISOR_DEBUG_ENABLE") == "true")
3132
log := log.WithField("command", "proxy")
3233

33-
authP, err := proxy.NewAuthorizerFromEnvVar(proxyOpts.Auth)
34+
authP, err := proxy.NewAuthorizerFromDockerEnvVar(proxyOpts.Auth)
3435
if err != nil {
3536
log.WithError(err).WithField("auth", proxyOpts.Auth).Fatal("cannot unmarshal auth")
3637
}
38+
authA, err := proxy.NewAuthorizerFromEnvVar(proxyOpts.AdditionalAuth)
39+
if err != nil {
40+
log.WithError(err).WithField("auth", proxyOpts.Auth).Fatal("cannot unmarshal auth")
41+
}
42+
authP = authP.AddIfNotExists(authA)
3743

3844
baseref, err := reference.ParseNormalizedNamed(proxyOpts.BaseRef)
3945
if err != nil {
@@ -87,4 +93,5 @@ func init() {
8793
proxyCmd.Flags().StringVar(&proxyOpts.BaseRef, "base-ref", os.Getenv("WORKSPACEKIT_BOBPROXY_BASEREF"), "ref of the base image")
8894
proxyCmd.Flags().StringVar(&proxyOpts.TargetRef, "target-ref", os.Getenv("WORKSPACEKIT_BOBPROXY_TARGETREF"), "ref of the target image")
8995
proxyCmd.Flags().StringVar(&proxyOpts.Auth, "auth", os.Getenv("WORKSPACEKIT_BOBPROXY_AUTH"), "authentication to use")
96+
proxyCmd.Flags().StringVar(&proxyOpts.AdditionalAuth, "additional-auth", os.Getenv("WORKSPACEKIT_BOBPROXY_ADDITIONALAUTH"), "additional authentication to use")
9097
}

Diff for: components/image-builder-bob/pkg/proxy/auth.go

+31-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ type authConfig struct {
2020
Auth string `json:"auth"`
2121
}
2222

23-
type authorizerImpl map[string]authConfig
23+
type MapAuthorizer map[string]authConfig
2424

25-
func (a authorizerImpl) Authorize(host string) (user, pass string, err error) {
25+
func (a MapAuthorizer) Authorize(host string) (user, pass string, err error) {
2626
defer func() {
2727
log.WithFields(logrus.Fields{
2828
"host": host,
@@ -54,17 +54,44 @@ func (a authorizerImpl) Authorize(host string) (user, pass string, err error) {
5454
return
5555
}
5656

57+
func (a MapAuthorizer) AddIfNotExists(other MapAuthorizer) MapAuthorizer {
58+
res := make(map[string]authConfig)
59+
for k, v := range a {
60+
res[k] = v
61+
}
62+
for k, v := range other {
63+
if _, ok := a[k]; ok {
64+
continue
65+
}
66+
res[k] = v
67+
}
68+
return MapAuthorizer(res)
69+
}
70+
5771
type Authorizer interface {
5872
Authorize(host string) (user, pass string, err error)
5973
}
6074

61-
func NewAuthorizerFromEnvVar(content string) (auth Authorizer, err error) {
75+
func NewAuthorizerFromDockerEnvVar(content string) (auth MapAuthorizer, err error) {
6276
var res struct {
6377
Auths map[string]authConfig `json:"auths"`
6478
}
6579
err = json.Unmarshal([]byte(content), &res)
6680
if err != nil {
6781
return
6882
}
69-
return authorizerImpl(res.Auths), nil
83+
return MapAuthorizer(res.Auths), nil
84+
}
85+
86+
func NewAuthorizerFromEnvVar(content string) (auth MapAuthorizer, err error) {
87+
if content == "" {
88+
return nil, nil
89+
}
90+
91+
var res map[string]authConfig
92+
err = json.Unmarshal([]byte(content), &res)
93+
if err != nil {
94+
return
95+
}
96+
return MapAuthorizer(res), nil
7097
}

Diff for: components/image-builder-mk3/debug.sh

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
docker ps &> /dev/null || (echo "You need a working Docker daemon. Maybe set DOCKER_HOST?"; exit 1)
66
gcloud auth list | grep typefox &>/dev/null || (echo "Login using 'gcloud auth login' for the docker push to work"; exit 1)
77

8-
leeway build .:docker -Dversion=dev
9-
devImage=eu.gcr.io/gitpod-dev/image-builder:dev
8+
leeway build -v .:docker -Dversion=cw-dev -DimageRepoBase=eu.gcr.io/gitpod-core-dev/build
9+
devImage=eu.gcr.io/gitpod-core-dev/build/image-builder-mk3:cw-dev
1010

11-
kubectl patch deployment image-builder --patch '{"spec": {"template": {"spec": {"containers": [{"name": "service","image": "'$devImage'"}]}}}}'
12-
kubectl get pods --no-headers -o=custom-columns=:metadata.name | grep image-builder | xargs kubectl delete pod
11+
kubectl patch deployment image-builder-mk3 --patch '{"spec": {"template": {"spec": {"containers": [{"name": "image-builder-mk3","imagePullPolicy":"Always","image": "'$devImage'"}]}}}}'
12+
kubectl rollout restart deployment/image-builder-mk3
13+
kubectl rollout status -w deployment/image-builder-mk3
14+
# give the old pod time to disappear
15+
sleep 20
16+
gpctl debug logs image-builder-mk3

0 commit comments

Comments
 (0)