Skip to content

Commit caaa682

Browse files
committed
Adds more labels to the Dockerfile
It also updates the README and the bug_report template to reflect the changes. Additionally, in the README some relevant shields from shields.io are added. The labels follow [label-schema.org][lsorg] and the [OpenContainer image spec, section annotations][ocis], specifications. [lsorg]: http://label-schema.org/rc1/ [ocis]: https://github.com/opencontainers/image-spec/blob/master/annotations.md
1 parent eddc308 commit caaa682

File tree

4 files changed

+142
-46
lines changed

4 files changed

+142
-46
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,22 @@ The output of `docker version`: `XXXXX`
4545
The output of `git rev-parse HEAD`: `XXXXX`
4646
The command you used to start the project: `XXXXX`
4747

48+
<!-- adjust the `latest` tag to the version you're using -->
49+
The output of `docker inspect netboxcommunity/netbox:latest --format "{{json .ContainerConfig.Labels}}"`:
50+
51+
```json
52+
{
53+
"JSON JSON JSON":
54+
"--> Please paste formatted json. (Use e.g. `jq` or https://jsonformatter.curiousconcept.com/)"
55+
}
56+
```
57+
4858
The output of `docker-compose logs netbox`:
4959
<!--
5060
If your log is very long, create a Gist instead (and post the link to it): https://gist.github.com
5161
-->
5262

53-
```
63+
```text
5464
LOG LOG LOG
5565
```
5666

@@ -60,6 +70,6 @@ Only if you have gotten a 5xx http error, else delete this section.
6070
If your log is very long, create a Gist instead (and post the link to it): https://gist.github.com
6171
-->
6272

63-
```
73+
```text
6474
LOG LOG LOG
6575
```

Dockerfile

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,34 @@ ENTRYPOINT [ "/opt/netbox/docker-entrypoint.sh" ]
7272

7373
CMD ["gunicorn", "-c /etc/netbox/config/gunicorn_config.py", "netbox.wsgi"]
7474

75-
LABEL NETBOX_DOCKER_PROJECT_VERSION="custom build" \
76-
NETBOX_BRANCH="custom build" \
77-
ORIGINAL_DOCKER_TAG="custom build" \
78-
NETBOX_GIT_COMMIT="not built from git" \
79-
NETBOX_GIT_URL="not built from git"
75+
LABEL ORIGINAL_TAG="" \
76+
NETBOX_GIT_BRANCH="" \
77+
NETBOX_GIT_REF="" \
78+
NETBOX_GIT_URL="" \
79+
# See http://label-schema.org/rc1/#build-time-labels
80+
# Also https://microbadger.com/labels
81+
org.label-schema.schema-version="1.0" \
82+
org.label-schema.build-date="" \
83+
org.label-schema.name="Netbox Docker" \
84+
org.label-schema.description="A container based distribution of Netbox, the free and open IPAM and DCIM solution." \
85+
org.label-schema.vendor="The netbox-docker contributors." \
86+
org.label-schema.url="https://github.com/netbox-community/netbox-docker" \
87+
org.label-schema.usage="https://github.com/netbox-community/netbox-docker/wiki" \
88+
org.label-schema.vcs-url="https://github.com/netbox-community/netbox-docker.git" \
89+
org.label-schema.vcs-ref="" \
90+
org.label-schema.version="snapshot" \
91+
# See https://github.com/opencontainers/image-spec/blob/master/annotations.md#pre-defined-annotation-keys
92+
org.opencontainers.image.created="" \
93+
org.opencontainers.image.title="Netbox Docker" \
94+
org.opencontainers.image.description="A container based distribution of Netbox, the free and open IPAM and DCIM solution." \
95+
org.opencontainers.image.licenses="Apache-2.0" \
96+
org.opencontainers.image.authors="The netbox-docker contributors." \
97+
org.opencontainers.image.vendor="The netbox-docker contributors." \
98+
org.opencontainers.image.url="https://github.com/netbox-community/netbox-docker" \
99+
org.opencontainers.image.documentation="https://github.com/netbox-community/netbox-docker/wiki" \
100+
org.opencontainers.image.source="https://github.com/netbox-community/netbox-docker.git" \
101+
org.opencontainers.image.revision="" \
102+
org.opencontainers.image.version="snapshot"
80103

81104
#####
82105
## LDAP specific configuration

README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
# netbox-docker
22

3+
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/netbox-community/netbox-docker)][github-release]
4+
[![GitHub stars](https://img.shields.io/github/stars/netbox-community/netbox-docker)][github-stargazers]
5+
![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed-raw/netbox-community/netbox-docker)
6+
![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/netboxcommunity/netbox)
7+
![Docker Pulls](https://img.shields.io/docker/pulls/netboxcommunity/netbox)
8+
[![MicroBadger Layers](https://img.shields.io/microbadger/layers/netboxcommunity/netbox)][netbox-docker-microbadger]
9+
[![MicroBadger Size](https://img.shields.io/microbadger/image-size/netboxcommunity/netbox)][netbox-docker-microbadger]
10+
[![GitHub license](https://img.shields.io/github/license/netbox-community/netbox-docker)][netbox-docker-license]
11+
312
[The Github repository](netbox-docker-github) houses the components needed to build Netbox as a Docker container.
413
Images are built using this code and are released to [Docker Hub][netbox-dockerhub] once a day.
514

615
Do you have any questions? Before opening an issue on Github, please join the [Network To Code][ntc-slack] Slack and ask for help in our [`#netbox-docker`][netbox-docker-slack] channel.
716

17+
[github-stargazers]: https://github.com/netbox-community/netbox-docker/stargazers
18+
[github-release]: https://github.com/netbox-community/netbox-docker/releases
19+
[netbox-docker-microbadger]: https://microbadger.com/images/netboxcommunity/netbox
820
[netbox-dockerhub]: https://hub.docker.com/r/netboxcommunity/netbox/tags/
921
[netbox-docker-github]: https://github.com/netbox-community/netbox-docker/
1022
[ntc-slack]: http://slack.networktocode.com/
1123
[netbox-docker-slack]: https://slack.com/app_redirect?channel=netbox-docker&team=T09LQ7E9E
24+
[netbox-docker-license]: https://github.com/netbox-community/netbox-docker/blob/master/LICENSE
25+
26+
## Docker Tags
27+
28+
* `vX.Y.Z`: Release builds, built from [releases of Netbox][netbox-releases].
29+
* `latest`: Release builds, built from [`master` branch of Netbox][netbox-master].
30+
* `snapshot`: Pre-release builds, built from the [`develop` branch of Netbox][netbox-develop].
31+
* `develop-X.Y`: Pre-release builds, built from the corresponding [branch of Netbox][netbox-branches].
32+
33+
Then there is currently one extra tags for each of the above labels:
34+
35+
* `-ldap`: Contains additional dependencies and configurations for connecting Netbox to an LDAP directroy.
36+
[Learn more about that in our wiki][netbox-docker-ldap].
37+
38+
[netbox-releases]: https://github.com/netbox-community/netbox/releases
39+
[netbox-master]: https://github.com/netbox-community/netbox/tree/master
40+
[netbox-develop]: https://github.com/netbox-community/netbox/tree/develop
41+
[netbox-branches]: https://github.com/netbox-community/netbox/branches
42+
[netbox-docker-ldap]: https://github.com/netbox-community/netbox-docker/wiki/LDAP
1243

1344
## Quickstart
1445

@@ -54,12 +85,12 @@ This project relies only on *Docker* and *docker-compose* meeting this requireme
5485

5586
To ensure this, compare the output of `docker --version` and `docker-compose --version` with the requirements above.
5687

57-
## Reference Documentation
88+
## Documentation
5889

59-
Please refer [to the wiki][wiki] for further information on how to use this Netbox Docker image properly.
90+
Please refer [to our wiki on Github][netbox-docker-wiki] for further information on how to use this Netbox Docker image properly.
6091
It covers advanced topics such as using secret files, deployment to Kubernetes as well as NAPALM and LDAP configuration.
6192

62-
[wiki]: https://github.com/netbox-community/netbox-docker/wiki/
93+
[netbox-docker-wiki]: https://github.com/netbox-community/netbox-docker/wiki/
6394

6495
## Netbox Version
6596

@@ -69,7 +100,7 @@ To use this feature, set the environment-variable `VERSION` before launching `do
69100
[any tag of the `netboxcommunity/netbox` Docker image on Docker Hub][netbox-dockerhub].
70101

71102
```bash
72-
export VERSION=v2.6.6
103+
export VERSION=v2.6.7
73104
docker-compose pull netbox
74105
docker-compose up -d
75106
```
@@ -78,7 +109,7 @@ You can also build a specific version of the Netbox Docker image yourself.
78109
`VERSION` can be any valid [git ref][git-ref] in that case.
79110

80111
```bash
81-
export VERSION=v2.6.6
112+
export VERSION=v2.6.7
82113
./build.sh $VERSION
83114
docker-compose up -d
84115
```
@@ -90,8 +121,9 @@ docker-compose up -d
90121

91122
From time to time it might become necessary to re-engineer the structure of this setup.
92123
Things like the `docker-compose.yml` file or your Kubernetes or OpenShift configurations have to be adjusted as a consequence.
93-
Since April 2018 each image built from this repo contains a `NETBOX_DOCKER_PROJECT_VERSION` label.
94-
You can check the label of your local image by running `docker inspect netboxcommunity/netbox:v2.3.1 --format "{{json .ContainerConfig.Labels}}"`.
124+
Since November 2019 each image built from this repo contains a `org.opencontainers.image.version` label.
125+
(The images contained labels since April 2018, although in November 2019 the labels' names changed.)
126+
You can check the label of your local image by running `docker inspect netboxcommunity/netbox:v2.6.7 --format "{{json .ContainerConfig.Labels}}"`.
95127

96128
Please read [the release notes][releases] carefully when updating to a new image version.
97129

build.sh

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,26 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
3030
echo " When \${BRANCH}=master: latest"
3131
echo " When \${BRANCH}=develop: snapshot"
3232
echo " Else: same as \${BRANCH}"
33-
echo " DOCKER_ORG The Docker registry (i.e. hub.docker.com/r/\${DOCKER_ORG}/\${DOCKER_REPO})"
34-
echo " Also used for tagging the image."
33+
echo " DOCKER_REGISTRY The Docker repository's registry (i.e. '\${DOCKER_REGISTRY}/\${DOCKER_ORG}/\${DOCKER_REPO}'')"
34+
echo " Used for tagging the image."
35+
echo " Default: docker.io"
36+
echo " DOCKER_ORG The Docker repository's organisation (i.e. '\${DOCKER_REGISTRY}/\${DOCKER_ORG}/\${DOCKER_REPO}'')"
37+
echo " Used for tagging the image."
3538
echo " Default: netboxcommunity"
36-
echo " DOCKER_REPO The Docker registry (i.e. hub.docker.com/r/\${DOCKER_ORG}/\${DOCKER_REPO})"
37-
echo " Also used for tagging the image."
39+
echo " DOCKER_REPO The Docker repository's name (i.e. '\${DOCKER_REGISTRY}/\${DOCKER_ORG}/\${DOCKER_REPO}'')"
40+
echo " Used for tagging the image."
3841
echo " Default: netbox"
39-
echo " DOCKER_FROM The base image to use."
40-
echo " Default: Whatever is defined as default in the Dockerfile."
4142
echo " DOCKER_TAG The name of the tag which is applied to the image."
4243
echo " Useful for pushing into another registry than hub.docker.com."
43-
echo " Default: \${DOCKER_ORG}/\${DOCKER_REPO}:\${TAG}"
44+
echo " Default: \${DOCKER_REGISTRY}/\${DOCKER_ORG}/\${DOCKER_REPO}:\${TAG}"
4445
echo " DOCKER_SHORT_TAG The name of the short tag which is applied to the"
4546
echo " image. This is used to tag all patch releases to their"
4647
echo " containing version e.g. v2.5.1 -> v2.5"
47-
echo " Default: \${DOCKER_ORG}/\${DOCKER_REPO}:<MAJOR>.<MINOR>"
48+
echo " Default: \${DOCKER_REGISTRY}/\${DOCKER_ORG}/\${DOCKER_REPO}:<MAJOR>.<MINOR>"
4849
echo " DOCKERFILE The name of Dockerfile to use."
4950
echo " Default: Dockerfile"
51+
echo " DOCKER_FROM The base image to use."
52+
echo " Default: Whatever is defined as default in the Dockerfile."
5053
echo " DOCKER_TARGET A specific target to build."
5154
echo " It's currently not possible to pass multiple targets."
5255
echo " Default: main ldap"
@@ -98,12 +101,6 @@ else
98101
DRY="echo"
99102
fi
100103

101-
###
102-
# read the project version from the `VERSION` file and trim it
103-
# see https://stackoverflow.com/a/3232433/172132
104-
###
105-
NETBOX_DOCKER_PROJECT_VERSION="${NETBOX_DOCKER_PROJECT_VERSION-$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' VERSION)}"
106-
107104
###
108105
# variables for fetching the source
109106
###
@@ -152,9 +149,29 @@ if [ ! -f "${DOCKERFILE}" ]; then
152149
fi
153150
fi
154151

152+
###
153+
# variables for labelling the docker image
154+
###
155+
BUILD_DATE="$(date --utc --iso-8601=minutes)"
156+
157+
if [ -d ".git" ]; then
158+
GIT_REF="$(git rev-parse HEAD)"
159+
fi
160+
161+
# read the project version from the `VERSION` file and trim it, see https://stackoverflow.com/a/3232433/172132
162+
PROJECT_VERSION="${PROJECT_VERSION-$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' VERSION)}"
163+
164+
# Get the Git information from the netbox directory
165+
if [ -d "${NETBOX_PATH}/.git" ]; then
166+
NETBOX_GIT_REF=$(cd ${NETBOX_PATH}; git rev-parse HEAD)
167+
NETBOX_GIT_BRANCH=$(cd ${NETBOX_PATH}; git rev-parse --abbrev-ref HEAD)
168+
NETBOX_GIT_URL=$(cd ${NETBOX_PATH}; git remote get-url origin)
169+
fi
170+
155171
###
156172
# variables for tagging the docker image
157173
###
174+
DOCKER_REGISTRY="${DOCKER_REGISTRY-docker.io}"
158175
DOCKER_ORG="${DOCKER_ORG-netboxcommunity}"
159176
DOCKER_REPO="${DOCKER_REPO-netbox}"
160177
case "${BRANCH}" in
@@ -182,7 +199,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
182199
###
183200
# composing the final TARGET_DOCKER_TAG
184201
###
185-
TARGET_DOCKER_TAG="${DOCKER_TAG-${DOCKER_ORG}/${DOCKER_REPO}:${TAG}}"
202+
TARGET_DOCKER_TAG="${DOCKER_TAG-${DOCKER_REGISTRY}/${DOCKER_ORG}/${DOCKER_REPO}:${TAG}}"
186203
if [ "${DOCKER_TARGET}" != "main" ]; then
187204
TARGET_DOCKER_TAG="${TARGET_DOCKER_TAG}-${DOCKER_TARGET}"
188205
fi
@@ -196,10 +213,10 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
196213
MAJOR=${BASH_REMATCH[1]}
197214
MINOR=${BASH_REMATCH[2]}
198215

199-
DOCKER_SHORT_TAG="${DOCKER_SHORT_TAG-${DOCKER_ORG}/${DOCKER_REPO}:v${MAJOR}.${MINOR}}"
216+
TARGET_DOCKER_SHORT_TAG="${DOCKER_SHORT_TAG-${DOCKER_REGISTRY}/${DOCKER_ORG}/${DOCKER_REPO}:v${MAJOR}.${MINOR}}"
200217

201218
if [ "${DOCKER_TARGET}" != "main" ]; then
202-
DOCKER_SHORT_TAG="${DOCKER_SHORT_TAG}-${DOCKER_TARGET}"
219+
TARGET_DOCKER_SHORT_TAG="${TARGET_DOCKER_SHORT_TAG}-${DOCKER_TARGET}"
203220
fi
204221
fi
205222

@@ -216,25 +233,39 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
216233
-f "${DOCKERFILE}"
217234
-t "${TARGET_DOCKER_TAG}"
218235
)
219-
if [ -n "${DOCKER_SHORT_TAG}" ]; then
220-
DOCKER_BUILD_ARGS+=( -t "${DOCKER_SHORT_TAG}" )
236+
if [ -n "${TARGET_DOCKER_SHORT_TAG}" ]; then
237+
DOCKER_BUILD_ARGS+=( -t "${TARGET_DOCKER_SHORT_TAG}" )
221238
fi
222239

223240
# --label
224-
DOCKER_BUILD_ARGS+=(
225-
--label "NETBOX_DOCKER_PROJECT_VERSION=${NETBOX_DOCKER_PROJECT_VERSION}"
226-
--label "NETBOX_BRANCH=${BRANCH}"
227-
--label "ORIGINAL_DOCKER_TAG=${TARGET_DOCKER_TAG}"
228-
)
229-
if [ -d "${NETBOX_PATH}/.git" ]; then
241+
if [ "${DOCKER_TARGET}" == "main" ]; then
230242
DOCKER_BUILD_ARGS+=(
231-
--label "NETBOX_GIT_COMMIT=$($DRY cd "${NETBOX_PATH}"; $DRY git rev-parse HEAD)"
232-
--label "NETBOX_GIT_URL=$($DRY cd "${NETBOX_PATH}"; $DRY git remote get-url origin)"
243+
--label "ORIGINAL_TAG=${TARGET_DOCKER_TAG}"
244+
245+
--label "org.label-schema.build-date=${BUILD_DATE}"
246+
--label "org.opencontainers.image.created=${BUILD_DATE}"
247+
248+
--label "org.label-schema.version=${PROJECT_VERSION}"
249+
--label "org.opencontainers.image.version=${PROJECT_VERSION}"
233250
)
251+
if [ -d ".git" ]; then
252+
DOCKER_BUILD_ARGS+=(
253+
--label "org.label-schema.vcs-ref=${GIT_REF}"
254+
--label "org.opencontainers.image.revision=${GIT_REF}"
255+
)
256+
fi
257+
if [ -d "${NETBOX_PATH}/.git" ]; then
258+
DOCKER_BUILD_ARGS+=(
259+
--label "NETBOX_GIT_BRANCH=${NETBOX_GIT_BRANCH}"
260+
--label "NETBOX_GIT_REF=${NETBOX_GIT_REF}"
261+
--label "NETBOX_GIT_URL=${NETBOX_GIT_URL}"
262+
)
263+
fi
234264
fi
235265

236266
# --build-arg
237-
DOCKER_BUILD_ARGS+=( --build-arg "NETBOX_PATH=${NETBOX_PATH}" )
267+
DOCKER_BUILD_ARGS+=( --build-arg "NETBOX_PATH=${NETBOX_PATH}" )
268+
238269
if [ -n "${DOCKER_FROM}" ]; then
239270
DOCKER_BUILD_ARGS+=( --build-arg "FROM=${DOCKER_FROM}" )
240271
fi
@@ -262,10 +293,10 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
262293
$DRY docker push "${TARGET_DOCKER_TAG}"
263294
echo "✅ Finished pushing the Docker image '${TARGET_DOCKER_TAG}'."
264295

265-
if [ -n "$DOCKER_SHORT_TAG" ]; then
266-
echo "⏫ Pushing '${DOCKER_SHORT_TAG}'"
267-
$DRY docker push "${DOCKER_SHORT_TAG}"
268-
echo "✅ Finished pushing the Docker image '${DOCKER_SHORT_TAG}'."
296+
if [ -n "${TARGET_DOCKER_SHORT_TAG}" ]; then
297+
echo "⏫ Pushing '${TARGET_DOCKER_SHORT_TAG}'"
298+
$DRY docker push "${TARGET_DOCKER_SHORT_TAG}"
299+
echo "✅ Finished pushing the Docker image '${TARGET_DOCKER_SHORT_TAG}'."
269300
fi
270301
fi
271302
done

0 commit comments

Comments
 (0)