Skip to content

Commit a426676

Browse files
committed
feat(registry): add garbage-collect cronjob
1 parent 79534d9 commit a426676

7 files changed

Lines changed: 62 additions & 12 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ RUN groupadd drycc --gid ${DRYCC_GID} \
4343
&& chown -R ${DRYCC_GID}:${DRYCC_UID} ${DRYCC_HOME_DIR}
4444

4545
COPY --chown=${DRYCC_GID}:${DRYCC_UID} rootfs/config-example.yml /opt/drycc/registry/etc/config.yml
46+
ENV DRYCC_REGISTRY_CONFIG /opt/drycc/registry/etc/config.yml
4647

4748
USER ${DRYCC_UID}
4849
VOLUME ["${DRYCC_HOME_DIR}"]

charts/registry/templates/_helper.tpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{{- define "registry.envs" -}}
1+
{{- define "registry.envs" }}
2+
env:
23
- name: REGISTRY_STORAGE_DELETE_ENABLED
34
value: "true"
45
- name: REGISTRY_LOG_LEVEL
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{{- if eq .Values.global.registryLocation "on-cluster" }}
2+
apiVersion: batch/v1
3+
kind: CronJob
4+
metadata:
5+
name: drycc-registry-cronjob-daily
6+
labels:
7+
heritage: drycc
8+
annotations:
9+
component.drycc.cc/version: {{ .Values.imageTag }}
10+
spec:
11+
schedule: "0 0 * * *"
12+
concurrencyPolicy: {{ .Values.concurrencyPolicy }}
13+
successfulJobsHistoryLimit: 1
14+
failedJobsHistoryLimit: 1
15+
jobTemplate:
16+
spec:
17+
template:
18+
spec:
19+
restartPolicy: OnFailure
20+
serviceAccount: drycc-controller
21+
initContainers:
22+
- name: drycc-registry-init
23+
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/python-dev:latest
24+
imagePullPolicy: {{.Values.imagePullPolicy}}
25+
args:
26+
- netcat
27+
- -v
28+
- -u
29+
- $(DRYCC_MINIO_ENDPOINT)
30+
{{- include "builder.envs" . | indent 12 }}
31+
containers:
32+
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/registry:{{.Values.imageTag}}
33+
imagePullPolicy: {{.Values.imagePullPolicy}}
34+
name: drycc-registry-garbage-collect
35+
args:
36+
- /bin/bash
37+
- -c
38+
- /opt/registry/bin/registry
39+
- garbage-collect
40+
- $(DRYCC_REGISTRY_CONFIG)
41+
- --dry-run
42+
- --delete-untagged
43+
{{- include "builder.envs" . | indent 12 }}
44+
{{- end }}

charts/registry/templates/registry-deployment.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ spec:
3333
- -v
3434
- -u
3535
- $(DRYCC_MINIO_ENDPOINT)
36-
{{- include "builder.envs" . | indent 8 }}
36+
{{- include "registry.envs" . | indent 8 }}
3737
containers:
3838
- name: drycc-registry
3939
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/registry:{{.Values.imageTag}}
4040
imagePullPolicy: {{.Values.imagePullPolicy}}
41-
{{- include "builder.limits" . | indent 8 }}
42-
{{- include "builder.envs" . | indent 8 }}
41+
{{- include "registry.limits" . | indent 8 }}
42+
{{- include "registry.envs" . | indent 8 }}
4343
livenessProbe:
4444
httpGet:
45-
path: /v2/
45+
path: /
4646
port: 5000
4747
initialDelaySeconds: 1
4848
timeoutSeconds: 1
4949
readinessProbe:
5050
httpGet:
51-
path: /v2/
51+
path: /
5252
port: 5000
5353
initialDelaySeconds: 1
5454
timeoutSeconds: 1

charts/registry/templates/registry-secret.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
apiVersion: v1
32
kind: Secret
43
metadata:
@@ -9,8 +8,8 @@ metadata:
98
drycc.cc/registry-location: "{{ .Values.global.registryLocation }}"
109
type: Opaque
1110
data:
12-
{{- if ne .Values.global.registryLocation "on-cluster" }}
13-
host: {{ print "drycc-registry" .Release.Namespace ".svc." .Values.global.clusterDomain | b64enc }}
11+
{{- if eq .Values.global.registryLocation "on-cluster" }}
12+
host: {{ printf "drycc-registry.%s.svc.%s:80" .Release.Namespace .Values.global.clusterDomain | b64enc }}
1413
secret: {{ randAlphaNum 32 | b64enc }}
1514
{{- else }}
1615
host: {{ .Values.host | b64enc }}

charts/registry/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ imageTag: "canary"
44
imageRegistry: "registry.drycc.cc"
55
# limitsCpu: "100m"
66
# limitsMemory: "50Mi"
7+
concurrencyPolicy: "Replace"
78

89
# Service
910
service:

main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import (
1111

1212
const (
1313
registryBinary = "/opt/drycc/registry/bin/registry"
14-
registryConfig = "/opt/drycc/registry/etc/config.yml"
1514
registryHtpasswd = "/opt/drycc/registry/etc/htpasswd"
15+
registryConfigEnvVar = "DRYCC_REGISTRY_CONFIG"
1616
registryRedirectEnvVar = "DRYCC_REGISTRY_REDIRECT"
1717
minioLookupEnvVar = "DRYCC_MINIO_LOOKUP"
1818
minioBucketEnvVar = "DRYCC_MINIO_BUCKET"
1919
minioEndpointEnvVar = "DRYCC_MINIO_ENDPOINT"
2020
minioAccesskeyEnvVar = "DRYCC_MINIO_ACCESSKEY"
2121
minioSecretkeyEnvVar = "DRYCC_MINIO_SECRETKEY"
22-
command = "serve"
22+
defaultCommand = "serve"
2323
)
2424

2525
func main() {
@@ -61,8 +61,12 @@ func main() {
6161
if err := cmd.Run(); err != nil {
6262
log.Fatal("Error creating the registry bucket: ", err)
6363
}
64+
if len(os.Args) > 1 {
65+
cmd = exec.Command(registryBinary, os.Args[1:]...)
66+
} else {
67+
cmd = exec.Command(registryBinary, defaultCommand, os.Getenv(registryConfigEnvVar))
68+
}
6469

65-
cmd = exec.Command(registryBinary, command, registryConfig)
6670
cmd.Stdout = os.Stdout
6771
cmd.Stderr = os.Stderr
6872
if err := cmd.Run(); err != nil {

0 commit comments

Comments
 (0)