Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions dockerdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
import docker
import os
import sys
import time
import yaml
import json

# Setup local docker client connection
dockerclient = docker.from_env()

def get_local_image_manifest_digest(image_reference: str):
try:
output = os.popen(f"docker manifest inspect -v {image_reference}").read()
manifest_info = json.loads(output)

digest = manifest_info['Descriptor']['digest']
return digest
except Exception as e:
print(f"FAIL to get local image manifest digest: {e}")
return None

# Import yaml file
if len(sys.argv) > 0:
if len(sys.argv) > 1:
job_file = sys.argv[1]
else:
job_file = 'jobs.yaml'
Expand Down Expand Up @@ -39,8 +50,10 @@

# Process images in given imagelist
for image in dddata['imagelists'][imagelist]:
image_name = image['name']
lts = image.get('lts', False)
result = 'ok'
image_name, image_tag = image.split(':')
image_name, image_tag = image_name.split(':')
if source_addr == 'default':
source_full = image_name + ':' + image_tag
else:
Expand All @@ -52,7 +65,7 @@

# Check if image is already in target registry
osout = os.system(f"docker manifest inspect {target_full} > /dev/null 2>&1")
if osout == 0:
if osout == 0 and not lts:
print("cached... ok")
else:
# Pull image from source registry
Expand All @@ -63,7 +76,7 @@
print(f"FAIL: {e}")
if 'dockerimage' in locals():
del dockerimage
pass
continue

# Tag new registry
if 'dockerimage' in locals():
Expand All @@ -75,7 +88,13 @@
dockerclient.images.remove(source_full)
if 'dockerimage' in locals():
del dockerimage
pass
continue
# Get and write the local image digest to a file
digest = get_local_image_manifest_digest(target_full)
if digest:
with open(f"digest.txt", 'a') as file:
file.write(f"{target_full}@{digest}\n")
print(f" (Digest written {target_full} {digest} digest.txt)")

# Push image to target registry
if 'dockerimage' in locals():
Expand All @@ -87,7 +106,7 @@
dockerclient.images.remove(target_full)
except Exception as e:
print(f"FAIL: {e}")
pass
continue

# Check if image is available in target repo
print("verify:", end='', flush=True)
Expand All @@ -105,3 +124,4 @@
except:
pass
print(result)

50 changes: 29 additions & 21 deletions jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- gitlab
- kubernetes
- postgres
- ubuntu
- vault
dev-to-prd:
source: dev
Expand All @@ -37,28 +38,35 @@ jobs:
# Define your imagelists down here
imagelists:
gitlab:
- gitlab/gitlab-ee:15.7.0-ee.0
- gitlab/gitlab-runner-helper:ubuntu-x86_64-v14.10.2
- name: gitlab/gitlab-ee:15.7.0-ee.0
- name: gitlab/gitlab-runner-helper:ubuntu-x86_64-v14.10.2
kubernetes:
- calico/apiserver:v3.24.5
- calico/cni:v3.24.5
- calico/kube-controllers:v3.24.5
- calico/node:v3.24.5
- calico/pod2daemon-flexvol:v3.24.5
- calico/typha:v3.24.5
- grafana/grafana:9.2.3
- k8s.gcr.io/pause:3.6
- library/traefik:2.9.4
- name: calico/apiserver:v3.24.5
- name: calico/cni:v3.24.5
- name: calico/kube-controllers:v3.24.5
- name: calico/node:v3.24.5
- name: calico/pod2daemon-flexvol:v3.24.5
- name: calico/typha:v3.24.5
- name: grafana/grafana:9.2.3
- name: k8s.gcr.io/pause:3.6
- name: library/traefik:2.9.4
kubernetes_k8s:
- coredns:v1.9.3
- etcd:3.5.4-0
- kube-apiserver:v1.25.0
- kube-controller-manager:v1.25.0
- kube-proxy:v1.25.0
- kube-scheduler:v1.25.0
- pause:3.8
- coredns/coredns:v1.9.3
- name: coredns:v1.9.3
- name: etcd:3.5.4-0
- name: kube-apiserver:v1.25.0
- name: kube-controller-manager:v1.25.0
- name: kube-proxy:v1.25.0
- name: kube-scheduler:v1.25.0
- name: pause:3.8
- name: coredns/coredns:v1.9.3
postgres:
- library/postgres:15.1-alpine
- name: library/postgres:15.1-alpine
ubuntu:
- name: ubuntu:20.04
lts: true
- name: ubuntu:22.04
lts: true
- name: ubuntu:24.04
lts: true
vault:
- library/vault:1.11.4
- name: library/vault:1.11.4