-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sync): added bearer client for sync
fixed ping function taking too much time closes: #2213 #2212 Signed-off-by: Petu Eusebiu <[email protected]>
- Loading branch information
1 parent
36e04a4
commit a16ecab
Showing
21 changed files
with
1,086 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"distSpecVersion": "1.1.0-dev", | ||
"storage": { | ||
"rootDirectory": "/tmp/zot" | ||
}, | ||
"http": { | ||
"address": "127.0.0.1", | ||
"port": "8080" | ||
}, | ||
"log": { | ||
"level": "debug" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# --- | ||
# Stage 1: Install certs, build binary, create default config file | ||
# --- | ||
FROM ghcr.io/project-zot/golang:1.17 AS builder | ||
RUN mkdir -p /go/src/github.com/project-zot/zot | ||
WORKDIR /go/src/github.com/project-zot/zot | ||
COPY . . | ||
RUN make clean binary | ||
RUN echo '{\n\ | ||
"storage": {\n\ | ||
"rootDirectory": "/var/lib/registry"\n\ | ||
},\n\ | ||
"http": {\n\ | ||
"address": "0.0.0.0",\n\ | ||
"port": "5000"\n\ | ||
},\n\ | ||
"log": {\n\ | ||
"level": "debug"\n\ | ||
},\n\ | ||
"extensions": {\n\ | ||
"metrics": {\n\ | ||
"enable": true,\n\ | ||
"prometheus": {\n\ | ||
"path": "/metrics"\n\ | ||
}\n\ | ||
}\n\ | ||
}\n\ | ||
}\n' > config.json && cat config.json | ||
|
||
# --- | ||
# Stage 2: Final image with nothing but certs, binary, and default config file | ||
# --- | ||
FROM scratch AS final | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | ||
COPY --from=builder /go/src/github.com/project-zot/zot/bin/zot /zot | ||
COPY --from=builder /go/src/github.com/project-zot/zot/config.json /etc/zot/config.json | ||
ENTRYPOINT ["/zot"] | ||
EXPOSE 5000 | ||
VOLUME ["/var/lib/registry"] | ||
CMD ["serve", "/etc/zot/config.json"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# --- | ||
# Stage 1: Install certs, build binary, create default config file | ||
# --- | ||
FROM ghcr.io/project-zot/golang:1.17 AS builder | ||
RUN mkdir -p /go/src/github.com/project-zot/zot | ||
WORKDIR /go/src/github.com/project-zot/zot | ||
COPY . . | ||
RUN make clean binary-minimal | ||
RUN echo '{\n\ | ||
"storage": {\n\ | ||
"rootDirectory": "/var/lib/registry"\n\ | ||
},\n\ | ||
"http": {\n\ | ||
"address": "0.0.0.0",\n\ | ||
"port": "5050"\n\ | ||
},\n\ | ||
"log": {\n\ | ||
"level": "debug"\n\ | ||
}\n\ | ||
}\n' > config.json && cat config.json | ||
|
||
# --- | ||
# Stage 2: Final image with nothing but certs, binary, and default config file | ||
# --- | ||
FROM scratch AS final | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | ||
COPY --from=builder /go/src/github.com/project-zot/zot/bin/zot-minimal /zot | ||
COPY --from=builder /go/src/github.com/project-zot/zot/config.json /etc/zot/config.json | ||
ENTRYPOINT ["/zot"] | ||
EXPOSE 5050 | ||
VOLUME ["/var/lib/registry"] | ||
CMD ["serve", "/etc/zot/config.json"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# --- | ||
# Stage 1: Build binary, create default config file | ||
# --- | ||
FROM ghcr.io/project-zot/golang:1.17 AS builder | ||
RUN mkdir -p /go/src/github.com/project-zot/zot | ||
WORKDIR /go/src/github.com/project-zot/zot | ||
COPY . . | ||
RUN make clean exporter-minimal | ||
RUN echo '{\n\ | ||
"Server": {\n\ | ||
"protocol": "http",\n\ | ||
"host": "127.0.0.1",\n\ | ||
"port": "5050"\n\ | ||
},\n\ | ||
"Exporter": {\n\ | ||
"port": "5051",\n\ | ||
"log": {\n\ | ||
"level": "debug"\n\ | ||
}\n\ | ||
}\n\ | ||
}\n' > config.json && cat config.json | ||
|
||
# --- | ||
# Stage 2: Final image with nothing but binary and default config file | ||
# --- | ||
FROM scratch AS final | ||
COPY --from=builder /go/src/github.com/project-zot/zot/bin/zxp /zxp | ||
COPY --from=builder /go/src/github.com/project-zot/zot/config.json /etc/zxp/config.json | ||
ENTRYPOINT ["/zxp"] | ||
EXPOSE 5051 | ||
CMD ["config", "/etc/zxp/config.json"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CONTAINER_RUNTIME := docker | ||
|
||
.PHONY: binary-container | ||
binary-container: | ||
${CONTAINER_RUNTIME} build -f Dockerfile -t zot-build:latest ../../. | ||
|
||
.PHONY: run-container | ||
run-container: | ||
${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd)/../..:/go/src/github.com/project-zot/zot \ | ||
zot-build:latest | ||
|
||
.PHONY: binary-minimal-container | ||
binary-minimal-container: | ||
${CONTAINER_RUNTIME} build -f Dockerfile-minimal -t zot-minimal:latest ../../. | ||
|
||
.PHONY: run-minimal-container | ||
run-minimal-container: | ||
${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd)/../..:/go/src/github.com/project-zot/zot \ | ||
zot-minimal:latest | ||
|
||
.PHONY: binary-exporter-container | ||
binary-exporter-container: | ||
${CONTAINER_RUNTIME} build -f Dockerfile-zxp -t zxp:latest ../../. | ||
|
||
.PHONY: run-exporter-container | ||
run-exporter-container: | ||
${CONTAINER_RUNTIME} run --rm --security-opt label=disable zxp:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package client | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
// Key:Value store for bearer tokens, key is namespace, value is token. | ||
// We are storing only pull scoped tokens, the http client is for pulling only. | ||
type TokenCache struct { | ||
entries sync.Map | ||
} | ||
|
||
func NewTokenCache() *TokenCache { | ||
return &TokenCache{ | ||
entries: sync.Map{}, | ||
} | ||
} | ||
|
||
func (c *TokenCache) Set(namespace string, token *bearerToken) { | ||
if c == nil || token == nil { | ||
return | ||
} | ||
|
||
defer c.prune() | ||
|
||
c.entries.Store(namespace, token) | ||
} | ||
|
||
func (c *TokenCache) Get(namespace string) *bearerToken { | ||
if c == nil { | ||
return nil | ||
} | ||
|
||
val, ok := c.entries.Load(namespace) | ||
if !ok { | ||
return nil | ||
} | ||
|
||
bearerToken, ok := val.(*bearerToken) | ||
if !ok { | ||
return nil | ||
} | ||
|
||
return bearerToken | ||
} | ||
|
||
func (c *TokenCache) prune() { | ||
c.entries.Range(func(key, val any) bool { | ||
bearerToken, ok := val.(*bearerToken) | ||
if ok { | ||
if bearerToken.isExpired() { | ||
c.entries.Delete(key) | ||
} | ||
} | ||
|
||
return true | ||
}) | ||
} |
Oops, something went wrong.