Skip to content

Commit 0975fc0

Browse files
Raynoooosallou
authored andcommitted
Shared the fix between both script, added its import to both Dockerfiles
1 parent 4c3fb33 commit 0975fc0

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

Dockerfile_jenkins_spec_check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ RUN apt-get update
33
RUN apt-get install -y python3-pip
44
RUN pip3 install dockerfile_parse requests
55
COPY jenkins_container_spec_check.py /root/
6+
COPY dockerparse_arg_fix.py /root/
67

78
ENTRYPOINT ["/usr/bin/python3", "/root/jenkins_container_spec_check.py"]

Dockerfile_jenkins_version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ RUN apt-get update
33
RUN apt-get install -y python3-pip
44
RUN pip3 install dockerfile_parse requests
55
COPY jenkins_container_version.py /root/
6+
COPY dockerparse_arg_fix.py /root/
67

78
ENTRYPOINT ["/usr/bin/python3", "/root/jenkins_container_version.py"]

dockerparse_arg_fix.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from dockerfile_parse import DockerfileParser
2+
from dockerfile_parse.util import WordSplitter
3+
4+
def reload_arg_to_env (dfp, content):
5+
recipe_args = dict()
6+
for crtInstr in dfp.structure:
7+
if crtInstr['instruction']=="ARG":
8+
parts = crtInstr['value'].split('=')
9+
if len(parts) != 2:
10+
print("An ARG instruction is wrongly formatted")
11+
sys.exit(1)
12+
#If an ARG can be parsed, it is added to a temp env dictionary
13+
crt_value = WordSplitter(parts[1]).dequote()
14+
recipe_args[parts[0]]=crt_value
15+
16+
if len(recipe_args.keys())>0:
17+
#We must re-initialize the parser while including the ARG dictionary
18+
print ("Updating parser with newly found ARG instructions")
19+
dfp = DockerfileParser(parent_env = recipe_args)
20+
dfp.content = content
21+
22+
return dfp

jenkins_container_spec_check.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import logging
66
import re
77

8+
import dockerparse_arg_fix
9+
810
def send_comment(comment):
911
if 'GITHUB_STATUS_TOKEN' not in os.environ:
1012
logging.info(str({
@@ -93,6 +95,10 @@ def send_status(software, status, msg=None):
9395

9496
dfp = DockerfileParser()
9597
dfp.content = content
98+
99+
#Need to double check on ARGs here
100+
dfp = dockerparse_arg_fix.reload_arg_to_env(dfp, content)
101+
96102
labels = dfp.labels
97103
status = True
98104
msg = []

jenkins_container_version.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from dockerfile_parse import DockerfileParser
2-
from dockerfile_parse.util import WordSplitter
32
import sys
43
import os
54
import logging
65
import re
76

7+
import dockerparse_arg_fix
8+
89
docker_file = None
910
if len(sys.argv) > 1 and sys.argv[1]:
1011
docker_file = sys.argv[1]
@@ -20,24 +21,8 @@
2021
dfp = DockerfileParser()
2122
dfp.content = content
2223

23-
###DockerfileParser doesn't know how to link ARG declarations to their subsequent use
24-
##Parsing all ARGs
25-
recipe_args = dict()
26-
for crtInstr in dfp.structure:
27-
if crtInstr['instruction']=="ARG":
28-
parts = crtInstr['value'].split('=')
29-
if len(parts) != 2:
30-
print("An ARG instruction is wrongly formatted")
31-
sys.exit(1)
32-
#If an ARG can be parsed, it is added to a temp env dictionary
33-
crt_value = WordSplitter(parts[1]).dequote()
34-
recipe_args[parts[0]]=crt_value
35-
36-
if len(recipe_args.keys())>0:
37-
#We must re-initialize the parser while including the ARG dictionary
38-
print ("Updating parser with newly found ARG instructions")
39-
dfp = DockerfileParser(parent_env = recipe_args)
40-
dfp.content = content
24+
#Applying our fix to load ARGs until DockerfileParser handles them
25+
dfp = dockerparse_arg_fix.reload_arg_to_env(dfp, content)
4126

4227
#Moved here to avoid repeating this step
4328
labels = dfp.labels

0 commit comments

Comments
 (0)