This repository was archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 550
docker cache deploy #5290
Merged
SwordFaith
merged 80 commits into
microsoft:master
from
SwordFaith:swordfaith/docker-cache-deploy
Feb 22, 2021
Merged
docker cache deploy #5290
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
727dfa8
Add basic docker-cache folder
SwordFaith e95e05b
Update docker-cache configs and scripts
SwordFaith d25c6d1
Add uri in docker-cache config
SwordFaith 4ef4cb4
Add pylon env and location for docker cache
SwordFaith 241307e
Add basic docker_cache.py
SwordFaith 10ca21b
Add service.yaml
SwordFaith efc4230
Update docker-cache.yaml.template
SwordFaith facd854
Fix missing docker_cache bug in docker-cache.yaml.template
SwordFaith 4fe370c
Seperate docker-cache.yaml.template to multiple template files
SwordFaith 29bfb12
Remove docker-cache namespace
SwordFaith 798f141
Try to fix containerPort type error
SwordFaith 784a373
Fix stop.sh file not find error and docker-cache-service namespace error
SwordFaith 75a1a77
Modify default service nodeport to valid range
SwordFaith 2eadc5c
Merge branch 'master' into swordfaith/docker-cache-deploy
SwordFaith c17ca58
Add docker-cache option in role docker-runtime
SwordFaith d010e92
Add docker-cache related config in kubespray
SwordFaith 23f7293
Add test play book
SwordFaith 1518147
Move docker-cache-dist to parent dir
SwordFaith 6d5f47c
Add enable docker-cache info in role tasks
SwordFaith d9ad362
Disable docker-cache htpasswd auth
SwordFaith 6986826
Change daemon.json mirror to default nodeport conf
SwordFaith fbd696a
Change legacy daemon.json path to default
SwordFaith 4bef655
Add systemctl reload task
SwordFaith 8de7c3a
Avoid install nvidia-runtime by default
SwordFaith 9d2619c
Fix bug in config dist load config command
SwordFaith f351c45
Revert docker-runtime role as it is
SwordFaith ad794c5
Move docker-cache related op to docker-cache role
SwordFaith fc8b753
Update docker-cache daemon.json
SwordFaith a25a04a
Update a version works for job submit cache
SwordFaith eb81c5f
Add sample deploy config and script
SwordFaith bf83b5d
Add process logic if undefine other mirrors and insecure registries
SwordFaith 3731d46
Add docker-cache config to service-conf
SwordFaith 699a599
Fix bug in get docker config func name
SwordFaith 4307571
Fix typo in docker cache config keys
SwordFaith 4520d3e
Fix bug in docker-cache template list
SwordFaith e0b46a4
Modify docker-cache start.sh.template
SwordFaith 97d93f7
Fix start.sh.template condition
SwordFaith f580371
Test another template condition to docker-cache start.sh
SwordFaith 1428fd0
Cancel start.sh.template to start.sh.
SwordFaith 9bbbf81
update
SwordFaith 665f845
Test start.sh.template
SwordFaith f7b9f13
update
SwordFaith d2cbe5a
update
SwordFaith 936db62
Add docker-cache as prerequisite of most job
SwordFaith a1ec787
Merge branch 'master' into swordfaith/docker-cache-deploy
SwordFaith e5dd6b2
Add docker-cache config to kubespray config
SwordFaith 50d0119
Add insecure_registry and mirror diff logic
SwordFaith 21e1b6b
Fix docker insecure registry and mirror format error
SwordFaith 8c79630
Merge branch 'master' into swordfaith/docker-cache-deploy
SwordFaith 624b366
Fix pylint errors
SwordFaith 6157910
Fix deployment delete error
SwordFaith b253761
Add enable option in docker-cache to support start.sh.template
SwordFaith d55f4be
Fix service conf template for enabled in docker-cache
SwordFaith e2cdfdb
Merge branch 'master' into swordfaith/docker-cache-deploy
yiyione 8d8fd94
Add fs storage backend support
SwordFaith 7a9b41b
Fix typo in docker-cache and add trailing new line
SwordFaith 82a3e25
Fix missing quote in service conf template
SwordFaith 6bf0386
Change docker-cache config update logic
SwordFaith 1f21b60
Fix typo
SwordFaith e8cac8f
Use py script to change docker config
SwordFaith 2e1898c
Fix typo in docker-cache role
SwordFaith 88c22b0
Change arg format in ansible builtin command
SwordFaith 431dac8
Change add docker config task format
SwordFaith cdc7bc2
Change format of add docker cache config task
SwordFaith 4641920
Remove unused files in docker-cache role
SwordFaith f6a6d7d
Rename docker-cache-dist to docker-cache-config-distribute
SwordFaith 1b86ff6
Remove redundant function do generate specific docker-cache-config
SwordFaith 9d9f878
Add parameter to docker-cache role
SwordFaith aa1a651
Update
SwordFaith ec34eed
Change docker_cache_host pass by environ
SwordFaith 66eba51
Revert to distribute localhost node port only
SwordFaith 03fd7ce
Add support to dynamic docker-cache config dist host
SwordFaith 61f7ff9
Delete cluster type: yarn use docker-cache
SwordFaith d5e5f37
Add trailing new line
SwordFaith 0934044
Change auth htpasswd enabled when user specify htpasswd secret
SwordFaith 6b882dc
Add explaination to registry-htpasswd parameter
SwordFaith e062992
Add trainling new lin to service.yaml
SwordFaith 7dd0359
Squeeze service-conf by jinja2 whitespace control
SwordFaith e6c439a
Squeeze docker-cache-config template by jinja2 whitespace control
SwordFaith 97ca25a
Remove redundant sudo in add-docker-cache-config task
SwordFaith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,14 @@ | ||
| - hosts: all | ||
| become: true | ||
| become_user: root | ||
| gather_facts: true | ||
| roles: | ||
| - role: '../roles/docker-cache/install' | ||
| vars: | ||
| enable_docker_cache: true | ||
| docker_cache_host: "{{ hostvars[groups['kube-master'][0]]['ip'] }}" | ||
| tasks: | ||
| - name: Restart service docker config from /etc/docker/daemon.json after update | ||
| ansible.builtin.systemd: | ||
| name: docker | ||
| state: restarted |
This file contains hidden or 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 hidden or 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
2 changes: 2 additions & 0 deletions
2
contrib/kubespray/roles/docker-cache/install/defaults/main.yml
This file contains hidden or 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,2 @@ | ||
| enable_docker_cache: false | ||
| docker_cache_host: 'localhost' |
46 changes: 46 additions & 0 deletions
46
contrib/kubespray/roles/docker-cache/install/files/add_docker_cache_config.py
This file contains hidden or 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,46 @@ | ||
| from pathlib import Path | ||
| import argparse | ||
| import json | ||
|
|
||
|
|
||
| def parse_args(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("host", default="localhost", help="host addr of docker cache registry") | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def main(): | ||
| args = parse_args() | ||
|
|
||
| folder_path = Path("/etc/docker") | ||
| target_path = Path("/etc/docker/daemon.json") | ||
| backup_path = Path("/etc/docker/daemon.json.bk") | ||
|
|
||
| folder_path.mkdir(parents=True, exist_ok=True) | ||
| target_path.touch(mode=0o666) | ||
| backup_path.touch(mode=0o666) | ||
|
|
||
| with open(str(target_path)) as f: | ||
| current_config = json.load(f); | ||
|
|
||
| with open(str(backup_path), 'w') as f: | ||
| json.dump(current_config, f) | ||
|
|
||
| docker_cache_mirror = "http://{}:30500".format(args.host) | ||
| if "registry-mirrors" in current_config: | ||
| if docker_cache_mirror not in current_config["registry-mirrors"]: | ||
| current_config["registry-mirrors"].append(docker_cache_mirror) | ||
| else: | ||
| current_config["registry-mirrors"] = [docker_cache_mirror] | ||
|
|
||
| if "insecure-registries" in current_config: | ||
| if docker_cache_mirror not in current_config["insecure-registries"]: | ||
| current_config["insecure-registries"].append(docker_cache_mirror) | ||
| else: | ||
| current_config["insecure-registries"] = [docker_cache_mirror] | ||
|
|
||
| with open(str(target_path), 'w') as f: | ||
| json.dump(current_config, f) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
12 changes: 12 additions & 0 deletions
12
contrib/kubespray/roles/docker-cache/install/tasks/add-docker-cache-config.yml
This file contains hidden or 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,12 @@ | ||
| --- | ||
| - name: copy add_docker_cache_config.py script into /tmp | ||
| copy: | ||
| src: add_docker_cache_config.py | ||
| dest: /tmp/add_docker_cache_config.py | ||
|
|
||
| - name: run add_docker_cache_config.py script to add docker cache config | ||
| ansible.builtin.command: | ||
| argv: | ||
| - python3 | ||
| - /tmp/add_docker_cache_config.py | ||
| - "{{ docker_cache_host }}" |
This file contains hidden or 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,5 @@ | ||
| --- | ||
| - name: "Add docker cache config" | ||
| include_tasks: add-docker-cache-config.yml | ||
| when: | ||
| - enable_docker_cache |
2 changes: 1 addition & 1 deletion
2
contrib/kubespray/roles/docker-runtime/install/defaults/main.yml
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| install_run_time: true | ||
| install_run_time: false |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ cluster-type: | |
|
|
||
| prerequisite: | ||
| - cluster-configuration | ||
| - docker-cache | ||
|
|
||
| template-list: | ||
| - start.sh | ||
|
|
||
This file contains hidden or 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,18 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| enabled: false | ||
| storage_backend: "azure" | ||
| azure_account_name: "" | ||
SwordFaith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| azure_account_key: "" | ||
| azure_container_name: dockerregistry | ||
| fs_mount_path: "/var/lib/registry" | ||
| registry_listener: ":5000" | ||
| container_port: 5000 | ||
| service_port: 5000 | ||
| service_nodeport: 30500 | ||
| remote_url: https://registry-1.docker.io | ||
| registry-htpasswd: '' | ||
| # registry-htpasswd default value can be dGVzdDokMnkkMDUkRUZiaWphaHovMHl4UC5xMFk1VW52TzljU2hHMThCRzM3QzBHNFhoRmFtTXdTUXdQLjBqQi4KCg==, | ||
| # which is "username: test password: test" encoded by htpasswd and base64 | ||
| # htpasswd is an apache tool for generate basic auth credentials | ||
This file contains hidden or 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,26 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| import copy | ||
|
|
||
| class DockerCache(object): | ||
| def __init__(self, cluster_conf, service_conf, default_service_conf): | ||
| self.cluster_conf = cluster_conf | ||
| self.service_conf = dict(default_service_conf, **service_conf) | ||
|
|
||
| def validation_pre(self): | ||
| machine_list = self.cluster_conf['machine-list'] | ||
| if len([host for host in machine_list if host.get('pai-master') == 'true']) < 1: | ||
| return False, '"pai-master=true" machine is required to deploy the docker-cache service' | ||
| return True, None | ||
|
|
||
| def run(self): | ||
| result = copy.deepcopy(self.service_conf) | ||
| machine_list = self.cluster_conf['machine-list'] | ||
| server_port = self.service_conf['service_nodeport'] | ||
| master_ip = [host['hostip'] for host in machine_list if host.get('pai-master') == 'true'][0] | ||
| result['uri'] = 'http://{0}:{1}'.format(master_ip, server_port) | ||
| return result | ||
|
|
||
| def validation_post(self, conf): | ||
| return True, None |
This file contains hidden or 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,10 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| pushd $(dirname "$0") > /dev/null | ||
|
|
||
| /bin/bash stop.sh || exit $? | ||
|
|
||
| popd > /dev/null |
This file contains hidden or 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,47 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License | ||
|
|
||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: registry-config | ||
| namespace: default | ||
| data: | ||
| config.yml: | | ||
| version: 0.1 | ||
| log: | ||
| fields: | ||
| service: registry | ||
| storage: | ||
| cache: | ||
| blobdescriptor: inmemory | ||
| delete: | ||
| enabled: true | ||
| {%- if cluster_cfg["docker-cache"]["storage_backend"] == "azure" %} | ||
| azure: | ||
SwordFaith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| accountname: {{ cluster_cfg["docker-cache"]["azure_account_name"] }} | ||
| accountkey: {{ cluster_cfg["docker-cache"]["azure_account_key"] }} | ||
| container: {{ cluster_cfg["docker-cache"]["azure_container_name"] }} | ||
| # realm: core.windows.net | ||
| {%- elif cluster_cfg["docker-cache"]["storage_backend"] == "filesystem" %} | ||
| filesystem: | ||
| rootdirectory: {{ cluster_cfg["docker-cache"]["fs_mount_path"] }} | ||
| {%- else %} | ||
| {%- endif %} | ||
| http: | ||
| addr: {{ cluster_cfg["docker-cache"]["registry_listener"] }} | ||
| headers: | ||
| X-Content-Type-Options: [nosniff] | ||
| {%- if cluster_cfg["docker-cache"]["registry-htpasswd"] != '' %} | ||
| auth: | ||
| htpasswd: | ||
| realm: basic-realm | ||
| path: /auth/htpasswd # /etc/registry | ||
| {%- endif %} | ||
| proxy: | ||
| remoteurl: {{ cluster_cfg["docker-cache"]["remote_url"] }} | ||
| health: | ||
| storagedriver: | ||
| enabled: true | ||
| interval: 10s | ||
| threshold: 3 | ||
This file contains hidden or 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,11 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License | ||
|
|
||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: registry-htpasswd | ||
| namespace: default | ||
| data: | ||
| htpasswd: | # test test as default, to generate htpasswd please refer to README | ||
| {{ cluster_cfg["docker-cache"]["registry-htpasswd"] }} |
19 changes: 19 additions & 0 deletions
19
src/docker-cache/deploy/docker-cache-service.yaml.template
This file contains hidden or 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,19 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: docker-registry-cache-service | ||
| namespace: default | ||
| labels: | ||
| app: docker-registry-cache | ||
| spec: | ||
| type: NodePort | ||
| selector: | ||
| app: docker-registry-cache | ||
| ports: | ||
| - port: {{ cluster_cfg["docker-cache"]["service_port"] }} | ||
| name: http | ||
| targetPort: {{ cluster_cfg["docker-cache"]["container_port"] }} | ||
| nodePort: {{ cluster_cfg["docker-cache"]["service_nodeport"] }} |
This file contains hidden or 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 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: docker-registry-cache | ||
| namespace: default | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| app: docker-registry-cache | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: docker-registry-cache | ||
| spec: | ||
| containers: | ||
| - name: docker-registry-cache | ||
| image: registry:2 | ||
| imagePullPolicy: IfNotPresent | ||
| volumeMounts: | ||
| - name: registry-htpasswd | ||
| mountPath: /auth/ | ||
| readOnly: True | ||
| - name: registry-config | ||
| mountPath: /etc/docker/registry/ | ||
| readOnly: True | ||
| ports: | ||
| - name: http | ||
| containerPort: {{ cluster_cfg["docker-cache"]["container_port"] }} | ||
| volumes: | ||
| - name: registry-htpasswd | ||
| secret: | ||
| secretName: registry-htpasswd | ||
| defaultMode: 0400 | ||
| - name: registry-config | ||
| configMap: | ||
| name: registry-config |
This file contains hidden or 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,11 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| pushd $(dirname "$0") > /dev/null | ||
|
|
||
| bash stop.sh | ||
| bash start.sh | ||
|
|
||
| popd > /dev/null |
This file contains hidden or 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,23 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| cluster-type: | ||
| - k8s | ||
|
|
||
| prerequisite: | ||
| - cluster-configuration | ||
|
|
||
| template-list: | ||
| - docker-cache-config.yaml | ||
| - docker-cache-secret.yaml | ||
| - docker-cache.yaml | ||
| - docker-cache-service.yaml | ||
| - start.sh | ||
|
|
||
| start-script: start.sh | ||
| stop-script: stop.sh | ||
| delete-script: delete.sh | ||
| refresh-script: refresh.sh | ||
|
|
||
| deploy-rules: | ||
| - in: pai-master |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.