genuinetools / img

Standalone, daemon-less, unprivileged Dockerfile and OCI compatible container image builder.
https://blog.jessfraz.com/post/building-container-images-securely-on-kubernetes/
MIT License
3.9k stars 231 forks source link

add --label flag support to img build #178

Closed westonsteimel closed 6 years ago

westonsteimel commented 6 years ago

Adds support for img build --label per #168.

westonsteimel commented 6 years ago

I tested by building this Dockerfile with the following

$ img build --label "version=1.68.0" --label "date=2018-10-19" -t westonsteimel/img-label-test .

I then loaded it into docker, ran docker inspect, and observed that the date and version labels had been added in the output

$ img save westonsteimel/img-label-test | docker load
$ docker inspect westonsteimel/img-label-test
[
    {
        "Id": "sha256:ceb18563e6bceefaa835ec1a27e682f941439075540a7fff8fe81dea370f6d20",
        "RepoTags": [
            "westonsteimel/img-label-test:latest"
        ],
        "RepoDigests": [],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2018-10-09T23:49:00.403370381+01:00",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "DockerVersion": "",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "BOOST_VERSION=1.68.0"
            ],
            "Cmd": [
                "sh"
            ],
            "ArgsEscaped": true,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "Description": "Boost C++ libraries on Alpine Linux",
                "date": "2018-10-19",
                "version": "1.68.0"
            }
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 142137617,
        "VirtualSize": 142137617,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/4bb676b4df9a0d1ed8dd7855931e19917a501944e5af5a12e7672db2177adc66/diff",
                "MergedDir": "/var/lib/docker/overlay2/f2a907da5395d4365cd0a1825d95493ec1887ff3e2d53b25305955925a241686/merged",
                "UpperDir": "/var/lib/docker/overlay2/f2a907da5395d4365cd0a1825d95493ec1887ff3e2d53b25305955925a241686/diff",
                "WorkDir": "/var/lib/docker/overlay2/f2a907da5395d4365cd0a1825d95493ec1887ff3e2d53b25305955925a241686/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:df64d3292fd6194b7865d7326af5255db6d81e9df29f48adde61a918fbd8c332",
                "sha256:eadd0972a6d0c0259010fdb40e4266f4a8362cac8fe1fe71a606a9e88580dd68"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]
jessfraz commented 6 years ago

ah cool can you add a test to the test file for build as well! thanks!

westonsteimel commented 6 years ago

Sure, I can give it a go. I'm a bit unsure of how to view the metadata in order to check that the labels have been applied following the build without docker inspect though.

jessfraz commented 6 years ago

No worries about that :)

On Tue, Oct 23, 2018 at 00:02 Weston Steimel notifications@github.com wrote:

Sure, I can give it a go. I'm a bit unsure of how to view the metadata in order to check that the labels have been applied following the build without docker inspect though.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/genuinetools/img/pull/178#issuecomment-432120025, or mute the thread https://github.com/notifications/unsubscribe-auth/ABYNbBayD5LPDEY-Fc17Bd-IQvjMMAhoks5unr8AgaJpZM4XvaYV .

--

Jessie Frazelle 4096R / D4C4 DD60 0D66 F65A 8EFC 511E 18F3 685C 0022 BFF3 pgp.mit.edu http://pgp.mit.edu/pks/lookup?op=get&search=0x18F3685C0022BFF3

codecov[bot] commented 6 years ago

Codecov Report

Merging #178 into master will not change coverage. The diff coverage is 0%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #178   +/-   ##
=====================================
  Coverage       0%     0%           
=====================================
  Files          13     13           
  Lines         729    735    +6     
=====================================
- Misses        729    735    +6
Impacted Files Coverage Δ
build.go 0% <0%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 151b450...5c6e8a2. Read the comment docs.

westonsteimel commented 6 years ago

Thanks, I've added a test. Does it seem reasonable enough?

jessfraz commented 6 years ago

thanks so much!

jessfraz commented 6 years ago

oh if you have time want to update the readme too, just realized :) thanks again!

westonsteimel commented 6 years ago

No problem. Yeah, I can update the readme in about an hour or so.

jessfraz commented 6 years ago

thanks so much!

On Tue, Oct 23, 2018 at 11:02 AM Weston Steimel notifications@github.com wrote:

No problem. Yeah, I can update the readme in about an hour or so.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/genuinetools/img/pull/178#issuecomment-432354677, or mute the thread https://github.com/notifications/unsubscribe-auth/ABYNbBi5r2nFveJB9OWUBguxtOMxLfM1ks5un1m2gaJpZM4XvaYV .

--

Jessie Frazelle 4096R / D4C4 DD60 0D66 F65A 8EFC 511E 18F3 685C 0022 BFF3 pgp.mit.edu http://pgp.mit.edu/pks/lookup?op=get&search=0x18F3685C0022BFF3