Browse Source

Merge "Fix: git commit id labels on images"

Zuul 6 months ago
parent
commit
20f27f6281
3 changed files with 49 additions and 17 deletions
  1. 7
    0
      Dockerfile
  2. 11
    3
      Makefile
  3. 31
    14
      tools/zuul/playbooks/docker-image-build.yaml

+ 7
- 0
Dockerfile View File

@@ -15,6 +15,13 @@
15 15
 ARG FROM=python:3.6
16 16
 FROM ${FROM}
17 17
 
18
+LABEL org.opencontainers.image.authors='airship-discuss@lists.airshipit.org, irc://#airshipit@freenode'
19
+LABEL org.opencontainers.image.url='https://airshipit.org'
20
+LABEL org.opencontainers.image.documentation='https://airship-promenade.readthedocs.org'
21
+LABEL org.opencontainers.image.source='https://git.openstack.org/openstack/airship-promenade'
22
+LABEL org.opencontainers.image.vendor='The Airship Authors'
23
+LABEL org.opencontainers.image.licenses='Apache-2.0'
24
+
18 25
 VOLUME /etc/promenade
19 26
 VOLUME /target
20 27
 

+ 11
- 3
Makefile View File

@@ -22,7 +22,7 @@ PROXY             ?= http://proxy.foo.com:8000
22 22
 NO_PROXY          ?= localhost,127.0.0.1,.svc.cluster.local
23 23
 USE_PROXY         ?= false
24 24
 PUSH_IMAGE        ?= false
25
-LABEL             ?= commit-id
25
+COMMIT            ?= commit-id
26 26
 PYTHON            = python3
27 27
 CHARTS            := $(patsubst charts/%/.,%,$(wildcard charts/*/.))
28 28
 IMAGE             := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG}
@@ -118,7 +118,11 @@ $(CHARTS): $(addprefix dry-run-,$(CHARTS)) chartbanner
118 118
 .PHONY: build_promenade
119 119
 build_promenade:
120 120
 ifeq ($(USE_PROXY), true)
121
-	docker build --network host -t $(IMAGE) --label $(LABEL) -f ./Dockerfile \
121
+	docker build --network host -t $(IMAGE) \
122
+		--label "org.opencontainers.image.revision=$(COMMIT)" \
123
+		--label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \
124
+		--label "org.opencontainers.image.title=$(IMAGE_NAME)" \
125
+		-f ./Dockerfile \
122 126
 		--build-arg FROM=$(PYTHON_BASE_IMAGE) \
123 127
 		--build-arg http_proxy=$(PROXY) \
124 128
 		--build-arg https_proxy=$(PROXY) \
@@ -127,7 +131,11 @@ ifeq ($(USE_PROXY), true)
127 131
 		--build-arg no_proxy=$(NO_PROXY) \
128 132
 		--build-arg NO_PROXY=$(NO_PROXY) .
129 133
 else
130
-	docker build --network host -t $(IMAGE) --label $(LABEL) -f ./Dockerfile \
134
+	docker build --network host -t $(IMAGE) \
135
+		--label "org.opencontainers.image.revision=$(COMMIT)" \
136
+		--label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \
137
+		--label "org.opencontainers.image.title=$(IMAGE_NAME)" \
138
+		-f ./Dockerfile \
131 139
 		--build-arg FROM=$(PYTHON_BASE_IMAGE) .
132 140
 endif
133 141
 ifeq ($(PUSH_IMAGE), true)

+ 31
- 14
tools/zuul/playbooks/docker-image-build.yaml View File

@@ -70,24 +70,40 @@
70 70
       debug:
71 71
         var: image_tags
72 72
 
73
-    - name: Docker login
74
-      docker_login:
75
-        password: "{{ airship_promenade_quay_creds.password }}"
76
-        username: "{{ airship_promenade_quay_creds.username }}"
77
-        registry_url: "https://quay.io/api/v1/"
73
+    - name: Make images
74
+      when: not publish
75
+      block:
76
+        - make:
77
+            chdir: "{{ zuul.project.src_dir }}"
78
+            target: images
79
+            params:
80
+              IMAGE_TAG: "{{ item }}"
81
+          with_items: "{{ image_tags.stdout_lines }}"
82
+
83
+        - shell: "docker images"
84
+          register: docker_images
85
+
86
+        - debug:
87
+            var: docker_images
78 88
 
79 89
       become: True
80
-      when: publish
81 90
 
82
-    - name: Build (and push) images
91
+    - name: Publish images
83 92
       block:
84
-        - docker_image:
85
-            name: "quay.io/airshipit/promenade"
86
-            dockerfile: "Dockerfile"
87
-            path: "{{ zuul.project.src_dir }}"
88
-            pull: false
89
-            push: "{{ publish }}"
90
-            tag: "{{ item }}"
93
+        - docker_login:
94
+            username: "{{ airship_promenade_quay_creds.username }}"
95
+            password: "{{ airship_promenade_quay_creds.password }}"
96
+            registry_url: "https://quay.io/api/v1/"
97
+
98
+        - make:
99
+            chdir: "{{ zuul.project.src_dir }}"
100
+            target: images
101
+            params:
102
+              DOCKER_REGISTRY: "quay.io"
103
+              IMAGE_PREFIX: "airshipit"
104
+              IMAGE_TAG: "{{ item }}"
105
+              COMMIT: "{{ zuul.newrev }}"
106
+              PUSH_IMAGE: "true"
91 107
           with_items: "{{ image_tags.stdout_lines }}"
92 108
 
93 109
         - shell: "docker images"
@@ -96,4 +112,5 @@
96 112
         - debug:
97 113
             var: docker_images
98 114
 
115
+      when: publish
99 116
       become: True

Loading…
Cancel
Save