Skip to content

Commit 8cfc16f

Browse files
committed
renamed container_inject to container_layer; updated commented example
1 parent ff646dc commit 8cfc16f

File tree

2 files changed

+48
-37
lines changed

2 files changed

+48
-37
lines changed

containers.build_defs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def container_flattener(name:str, srcs:list, toolchain:str = CONFIG.PLEASE_CONTA
9393
},
9494
)
9595

96-
def container_inject(name:str, srcs:list, destination:str, toolchain:str = CONFIG.PLEASE_CONTAINERS_TOOLCHAIN, visibility:list=[], labels:list=[]):
96+
def container_layer(name:str, srcs:list, destination:str, toolchain:str = CONFIG.PLEASE_CONTAINERS_TOOLCHAIN, visibility:list=[], labels:list=[]):
9797
dst = destination.lstrip('/')
9898
datefmt = '+%Y-%m-%dT%H:%M:%S%z'
9999

@@ -129,8 +129,6 @@ def container_inject(name:str, srcs:list, destination:str, toolchain:str = CONFI
129129
'sha256': [ toolchain+'|sha256'],
130130
'jarcat': [ CONFIG.JARCAT_TOOL ],
131131
},
132-
# deps = [ baseimage ],
133-
# post_build = lambda name, output: [add_out(name, line) for line in output if line]
134132
)
135133

136134
def container_config(name:str, srcs:list, timestamp:str='0', toolchain:str = CONFIG.PLEASE_CONTAINERS_TOOLCHAIN, description:str = '', image_labels:dict = {}, entrypoint:list = [], command:list = [], environment:dict = {}, ports:list = [], osversion:str = 'linux', architecture:str = 'amd64', visibility:list = ['PUBLIC'], labels:list=[]):
@@ -192,7 +190,6 @@ def container_config(name:str, srcs:list, timestamp:str='0', toolchain:str = CON
192190
# CLOUDSDK_CONFIG has to point to the $HOME/.config/gcloud directory, otherwise push will fail;
193191
# DOCKER_CONFIG has to point to a $HOME/.docker with configured docker credential/helper for gcr.io cases or some other auth completed already for private repos;
194192
# if the docker-credential-gcloud is being used, it has to be symlinked into the limited PATH used by please - either /usr/local/bin or /usr/bin
195-
# TODO: find a way to remote the unnecessary output
196193
def container_push(name:str, srcs:list, repository:str = CONFIG.DEFAULT_DOCKER_REPO, tag:str = '', image_name:str = '', toolchain:str = CONFIG.PLEASE_CONTAINERS_TOOLCHAIN, visibility:list = ['PUBLIC'], labels:list=[]):
197194
outfile = f"{name}_run.sh"
198195
fqnfile = f"{name}_fqn"

examples/BUILD

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,63 @@ filegroup(
1717
]
1818
)
1919

20+
# DESCRIPTION:
21+
# * name Mandatory - name of the rule
22+
# * image Mandatory - which image to pull
23+
# * tag Mandatory - which image version to pull
24+
# * repository Optional (default = "index.docker.io")
25+
# Pull an image from the registry and save it for future use;
26+
2027
container_pull(
2128
name = 'ubuntu',
2229
image = 'ubuntu',
2330
tag = '20.04',
2431
)
2532

33+
# DESCRIPTION:
34+
# This rule's srcs MUST be a multi-layer container_pull rule; it creates a container one with a single merged layer
35+
2636
container_flattener(
2737
name = 'ubuntu_flat',
2838
srcs = [ ":ubuntu" ],
2939
)
3040

31-
# container_inject just copies a bunch of files from another please target into a separate layer;
32-
# it may be repeated as many times as there are files
33-
# all files are being copied in the same destination directory
34-
# all files receive 755 if they are generated by a binary rule or 664 if not, with ownership nobody:nogroup
35-
#
36-
# supported arguments (and defaults or suggested values)
37-
# name: descriptive
38-
# baseimage: <target> a previous container_pull or container_flattener target
39-
# srcs: [] list of targets that contain or generate the files to be copied
40-
# destination: <path> where to put those files
41+
# DESCRIPTION:
42+
# * name Mandatory. The name of the rule
43+
# * srcs Mandatory. The list of targets that generate the file or files to be included.
44+
# * destination Mandatory. The destination directory.
45+
# All files inserted into the layer will be
46+
# * owned by nobody:nogroup
47+
# * mode 644 if they come from a normal please rule
48+
# * mode 755 if they come from a rule marked as "binary"
49+
# * placed in the same directory; if different destinations are required, one must define multiple rules
4150

42-
container_inject(
51+
container_layer(
4352
name = 'ubuntu_files',
4453
srcs = [ ":inject" ],
45-
# baseimage = ":ubuntu_flat",
4654
destination = "/opt/foo",
4755
)
4856

49-
container_inject(
57+
container_layer(
5058
name = 'ubuntu_files_two',
5159
srcs = [ ":inject_two" ],
52-
# baseimage = ":ubuntu_files",
5360
destination = "/opt/bar",
5461
)
5562

56-
# container_config runs after inject or flatten and creates the required metadata files for the container
57-
# supported arguments (and defaults/suggested values)
58-
# name: descriptive
59-
# baseimage: <target> previous container_flatten or container_inject target
60-
# description: '' what will be the description of the container (optional)
61-
# image_labels: {} what labels to associate with the container (optional)
62-
# environment: {} what environment to provide to the container (optional) - equivalent of the ENV in Dockerfiles
63-
# entrypoint: [] what's the entrypoint of the image (optional)
64-
# command: [] what's the command of the image (optional)
65-
# ports: [] what to EXPOSE
63+
# DESCRIPTION:
64+
# * name Mandatory. The name of the rule
65+
# * srcs Mandatory. The list of layers that compose the image
66+
# * description Optional. The container description as it would be generated by docker
67+
# * image_labels Optional. Embedded image labels
68+
# * environment Optional. Same as doing ENV in a Dockerfile
69+
# * entrypoint Optional. Same as ENTRYPOINT in a Dockerfile
70+
# * command Optional. Same as CMD in a Dockerfile
71+
# * ports Optional. Same as EXPOSE in a Dockerfile
72+
# * osversion Optional (default = linux).
73+
# * architecture Optional (default = amd64).
74+
6675
container_config(
67-
name = 'ubuntu_new',
68-
# baseimage = ":ubuntu_files_two",
76+
name = 'ubuntu_config',
6977
srcs = [
7078
":ubuntu_flat",
7179
":ubuntu_files",
@@ -90,20 +98,26 @@ container_config(
9098
"443",
9199
],
92100
)
93-
# CLOUDSDK_CONFIG has to point to the real $HOME/.config/gcloud directory, otherwise push will fail: please sets HOME to the current build dir
94-
# DOCKER_CONFIG has to point to a $HOME/.docker with configured docker credential/helper for gcr.io cases or some other auth completed already for private repos;
95-
# if the docker-credential-gcloud is being used, it has to be symlinked into the limited PATH used by please - either /usr/local/bin or /usr/bin
101+
102+
# DESCRIPTION:
103+
# * name Mandatory. The name of the rule; note that the rule will generate 2 separate rules, the one that does the push is called '${name}_push'; invoking just the name won't work
104+
# * srcs Mandatory. The ORDERED list of layers that compose the image. Always start with the baseimage (if any), followed by smaller layers; the LAST one MUST be a previously defined "container_config" target.
105+
# * image_name Optional. The name of the generated image; if absent, will use the ${name} field
106+
# * tag Optional. Extra tag for the image. The rule uses by default 12 chars from the digest of the image and the $CI_COMMIT_TAG variable (if defined);
107+
# REQUIREMENTS:
108+
# * CLOUDSDK_CONFIG has to point to the real $HOME/.config/gcloud directory (by default), otherwise push will fail, since please sets $HOME to the current build dir
109+
# * DOCKER_CONFIG has to point to a $HOME/.docker with configured docker credentials/helpers for private repos use-case;
110+
# * any credential helper for docker has to be linked into /usr/local/bin or /usr/bin (e.g. docker-credential-gcloud)
96111
container_push(
97112
name = 'ubuntu_custom',
98113
srcs = [
99114
":ubuntu_flat",
100115
":ubuntu_files",
101116
":ubuntu_files_two",
102-
":ubuntu_new",
117+
":ubuntu_config",
103118
],
104-
image_name = "foo", # optional, if you want image name to be different from the rule name
105-
tag = "foobarv2", # optional, will use the image digest (default) an $CI_COMMIT_TAG if defined; this one will the the 3rd
106-
# repository = "gcr.io/tcn-cloud-dev/m", # optional, will use CONFIG.DEFAULT_DOCKER_REPO as default;
119+
image_name = "foo",
120+
tag = "foobarv2",
107121
)
108122

109123
container_make(

0 commit comments

Comments
 (0)