Skip to content

Commit cd59747

Browse files
committed
initial version
0 parents  commit cd59747

File tree

5 files changed

+360
-0
lines changed

5 files changed

+360
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# docker-rpi-dozzle
2+
3+
Dozzle is a real-time log viewer for Docker. It's free. It's small.
4+
And it's right in your browser.
5+
6+
Have a look: https://dozzle.dev/
7+
8+
9+
### Develop and test builds
10+
11+
Just type:
12+
13+
```
14+
docker build . -t dozzle
15+
```
16+
17+
### Create final release and publish to Docker Hub
18+
19+
```
20+
create-release.sh
21+
```
22+
23+
24+
### Run
25+
26+
Given the docker image with name `dozzle`:
27+
28+
```
29+
docker run --name logging -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock -d jriguera/dozzle
30+
```
31+
32+
If you get an error like `FATAL Could not connect to Docker Engine: Error response from daemon: client version 1.41 is too new. Maximum supported API version is 1.40`,
33+
run `docker version` to check the Docker engine version and you can try:
34+
35+
```
36+
# Force a docker version using the binary
37+
export DOCKER_API_VERSION=1.40
38+
# and in Docker, run it passing the version
39+
docker run --name logging -p 8080:8080 -e DOCKER_API_VERSION=1.40 -v /var/run/docker.sock:/var/run/docker.sock -d jriguera/dozzle
40+
41+
```
42+
43+
44+
# Author
45+
46+
Jose Riguera `<jriguera@gmail.com>`

create-publish-release.sh

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#!/usr/bin/env bash
2+
# set -o pipefail # exit if pipe command fails
3+
[ -z "$DEBUG" ] || set -x
4+
set -e
5+
6+
##
7+
8+
NAME="dozzle"
9+
DOCKER_TAG="jriguera/$NAME"
10+
RELEASE="dozzle"
11+
DESCRIPTION="Docker image to run Dozzle in a Raspberry Pi. Simple logging for Docker."
12+
GITHUB_REPO="jriguera/docker-rpi-dozzle"
13+
14+
###
15+
16+
DOCKER="docker"
17+
JQ="jq"
18+
CURL="curl -s"
19+
RE_VERSION_NUMBER='^[0-9]+([0-9\.]*[0-9]+)*$'
20+
21+
###
22+
23+
ARCH=""
24+
case "$(uname -m)" in
25+
armv7l)
26+
ARCH='arm32v6'
27+
;;
28+
x86_64|amd64)
29+
ARCH='amd64'
30+
;;
31+
*)
32+
echo "ERROR: unsupported architecture: $(uname -m)"
33+
exit 1
34+
;;
35+
esac
36+
37+
VERSION=""
38+
case $# in
39+
0)
40+
echo "*** Creating a new release. Automatically calculating version number"
41+
;;
42+
1)
43+
if [ $1 == "-h" ] || [ $1 == "--help" ]
44+
then
45+
echo "Usage: $0 [version-number]"
46+
echo " Creates a release, commits the changes to this repository using tags and uploads "
47+
echo " the release to Github Releases and the final Docker image to Docker Hub. "
48+
echo " It also adds comments based on previous git commits."
49+
exit 0
50+
else
51+
VERSION=$1
52+
if ! [[ $VERSION =~ $RE_VERSION_NUMBER ]]
53+
then
54+
echo "ERROR: Incorrect version number!"
55+
exit 1
56+
fi
57+
echo "*** Creating a new release. Using release version number $VERSION."
58+
fi
59+
;;
60+
*)
61+
echo "ERROR: incorrect argument. See '$0 --help'"
62+
exit 1
63+
;;
64+
esac
65+
66+
# Create a personal github token to use this script
67+
if [ -z "$GITHUB_TOKEN" ]
68+
then
69+
echo "Github TOKEN not defined!"
70+
echo "See https://help.github.com/articles/creating-an-access-token-for-command-line-use/"
71+
exit 1
72+
fi
73+
74+
# You need bosh installed and with you credentials
75+
if ! [ -x "$(command -v $DOCKER)" ]
76+
then
77+
echo "ERROR: $DOCKER command not found! Please install it and make it available in the PATH"
78+
exit 1
79+
fi
80+
81+
# You need jq installed
82+
if ! [ -x "$(command -v $JQ)" ]
83+
then
84+
echo "ERROR: $JQ command not found! Please install it and make it available in the PATH"
85+
exit 1
86+
fi
87+
88+
DOCKER_USER=$(docker info 2> /dev/null | sed -ne 's/Username: \(.*\)/\1/p')
89+
if [ -z "$DOCKER_USER" ]
90+
then
91+
echo "ERROR: Not logged in Docker Hub!"
92+
echo "Please perform 'docker login' with your credentials in order to push images there."
93+
exit 1
94+
fi
95+
96+
# Creating the release
97+
if [ -z "$VERSION" ]
98+
then
99+
VERSION=$(sed -ne 's/^ARG.* VERSION=\(.*\)/\1/p' docker/Dockerfile)
100+
MYVERSION=$(sed -ne 's/^ARG.* MYVERSION=\(.*\)/\1/p' docker/Dockerfile)
101+
[ -n "$MYVERSION" ] && VERSION="$VERSION-$MYVERSION"
102+
echo "* Creating final release version $VERSION (from Dockerfile) ..."
103+
else
104+
echo "* Creating final release version $VERSION (from input)..."
105+
fi
106+
107+
# Get the last git commit made by this script
108+
LASTCOMMIT=$(git show-ref --tags -d | tail -n 1)
109+
if [ -z "$LASTCOMMIT" ]
110+
then
111+
echo "* Changes since the beginning: "
112+
CHANGELOG=$(git log --pretty="%h %aI %s (%an)" | sed 's/^/- /')
113+
else
114+
echo "* Changes since last version with commit $LASTCOMMIT: "
115+
CHANGELOG=$(git log --pretty="%h %aI %s (%an)" "$(echo $LASTCOMMIT | cut -d' ' -f 1)..@" | sed 's/^/- /')
116+
fi
117+
if [ -z "$CHANGELOG" ]
118+
then
119+
echo "ERROR: no commits since last release with commit $LASTCOMMIT!. Please "
120+
echo "commit your changes to create and publish a new release!"
121+
exit 1
122+
fi
123+
echo "$CHANGELOG"
124+
125+
pushd docker
126+
echo "* Building Docker image with tag $NAME:$VERSION ..."
127+
$DOCKER build \
128+
--build-arg ARCH=${ARCH} \
129+
--build-arg TZ=$(timedatectl | awk '/Time zone:/{ print $3 }') \
130+
. -t $NAME
131+
$DOCKER tag $NAME $DOCKER_TAG
132+
133+
# Uploading docker image
134+
echo "* Pusing Docker image to Docker Hub ..."
135+
$DOCKER push $DOCKER_TAG
136+
$DOCKER tag $NAME $DOCKER_TAG:$VERSION
137+
$DOCKER push $DOCKER_TAG
138+
139+
$DOCKER save -o "/tmp/$NAME-$VERSION.tgz" $DOCKER_TAG:$VERSION
140+
popd
141+
142+
# Create annotated tag
143+
echo "* Creating a git tag ... "
144+
git tag -a "v$VERSION" -m "$RELEASE v$VERSION"
145+
git push --tags
146+
147+
# Create a release in Github
148+
echo "* Creating a new release in Github ... "
149+
DESC=$(cat <<EOF
150+
# $RELEASE version $VERSION
151+
152+
$DESCRIPTION
153+
154+
## Changes since last version
155+
156+
$CHANGELOG
157+
158+
## Using it
159+
160+
Given the docker image with name 'dozzle':
161+
162+
docker run --name logging -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock -d jriguera/dozzle
163+
164+
EOF
165+
)
166+
printf -v data '{"tag_name": "v%s","target_commitish": "master","name": "v%s","body": %s,"draft": false, "prerelease": false}' "$VERSION" "$VERSION" "$(echo "$DESC" | $JQ -R -s '@text')"
167+
releaseid=$($CURL -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -XPOST --data "$data" "https://api.github.com/repos/$GITHUB_REPO/releases" | $JQ '.id')
168+
# Upload the release
169+
echo "* Uploading image to Github releases section ... "
170+
echo -n " URL: "
171+
$CURL -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/octet-stream" --data-binary @"/tmp/$NAME-$VERSION.tgz" "https://uploads.github.com/repos/$GITHUB_REPO/releases/$releaseid/assets?name=$NAME-$VERSION.tgz" | $JQ -r '.browser_download_url'
172+
173+
echo
174+
echo "*** Description https://github.com/$GITHUB_REPO/releases/tag/v$VERSION: "
175+
echo
176+
echo "$DESC"
177+
178+
# Delete the release
179+
rm -f "/tmp/$NAME-$VERSION.tgz"
180+
git fetch --tags
181+
182+
exit 0
183+

docker-build.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
DOCKER=docker
4+
NAME="dozzle"
5+
6+
ARCH=""
7+
case "$(uname -m)" in
8+
armv7l)
9+
ARCH='arm32v6'
10+
;;
11+
x86_64|amd64)
12+
ARCH='amd64'
13+
;;
14+
*)
15+
echo "ERROR: unsupported architecture: $(uname -m)"
16+
exit 1
17+
;;
18+
esac
19+
20+
pushd docker
21+
$DOCKER build \
22+
--build-arg ARCH=${ARCH} \
23+
--build-arg TZ=$(timedatectl | awk '/Time zone:/{ print $3 }') \
24+
. -t $NAME
25+
popd
26+

docker/Dockerfile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Dozzle in Docker: https://dozzle.dev/
2+
3+
# docker build . -t dozzle
4+
# docker run --name logging -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock -d dozzle
5+
6+
ARG ARCH=arm32v6
7+
FROM "${ARCH}/alpine:3.11"
8+
9+
ARG VERSION=1.20.12
10+
ARG MYVERSION=jose0
11+
ARG PORT=8080
12+
ARG UID=1000
13+
ARG GUID=1000
14+
ARG TZ=Europe/Amsterdam
15+
ARG ARCH
16+
17+
LABEL org.label-schema.description="Dozzle Docker image based on Alpine for the Raspberry Pi."
18+
LABEL org.label-schema.name="rpi-dozzle"
19+
LABEL org.label-schema.version="${VERSION}-${MYVERSION}"
20+
LABEL org.label-schema.usage="/README.md"
21+
LABEL org.label-schema.url="https://hub.docker.com/r/jriguera/rpi-dozzle"
22+
LABEL org.label-schema.vcs-url="https://github.com/jriguera/docker-rpi-dozzle"
23+
LABEL maintainer="Jose Riguera <jriguera@gmail.com>"
24+
LABEL architecture="${ARCH}"
25+
26+
ENV PORT="${PORT}"
27+
ENV DOCKER_API_VERSION=1.39
28+
ENV LANG=en_US.utf8
29+
ENV LC_ALL=C.UTF-8
30+
31+
RUN set -xe && \
32+
apk -U upgrade && \
33+
# User/group
34+
addgroup -g "${GUID}" -S dozzle && \
35+
adduser -h "/tmp" -D -G dozzle -s /sbin/nologin -u "${UID}" dozzle && \
36+
# Installing Alpine packages
37+
apk add --no-cache \
38+
ca-certificates \
39+
pwgen \
40+
su-exec \
41+
tzdata \
42+
socat \
43+
net-tools \
44+
curl \
45+
bash \
46+
&& \
47+
# Timezone
48+
cp "/usr/share/zoneinfo/${TZ}" /etc/localtime && \
49+
echo "${TZ}" > /etc/timezone && \
50+
# clean up
51+
rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/*
52+
53+
54+
COPY *.sh /usr/local/bin/
55+
56+
RUN set -xe && \
57+
chmod a+x /usr/local/bin/* && \
58+
ln -s /usr/local/bin/dozzle.sh /usr/local/bin/docker-entrypoint.sh && \
59+
ln -s /usr/local/bin/dozzle.sh /docker-entrypoint.sh && \
60+
ln -s /usr/local/bin/dozzle.sh /run.sh && \
61+
mkdir -p /docker-entrypoint-initdb.d
62+
63+
RUN set -ex && \
64+
[ "${ARCH}" == "arm32v6" ] && wget --quiet -O /tmp/dozzle.tgz "https://github.com/amir20/dozzle/releases/download/v${VERSION}/dozzle_${VERSION}_Linux_ARM_32-bitv6.tar.gz"; \
65+
[ "${ARCH}" == "amd64" ] && wget --quiet -O /tmp/dozzle.tgz "https://github.com/amir20/dozzle/releases/download/v${VERSION}/dozzle_${VERSION}_Linux_64-bit.tar.gz"; \
66+
tar -C /usr/bin -xvf /tmp/dozzle.tgz dozzle && \
67+
chmod +x /usr/bin/dozzle && \
68+
rm -f /tmp/dozzle.tgz
69+
70+
EXPOSE "${PORT}"
71+
HEALTHCHECK --interval=1m --timeout=3s CMD curl -f http://127.0.0.1:$PORT/ || exit 1
72+
73+
ENTRYPOINT ["/run.sh"]
74+
CMD ["dozzle"]

docker/dozzle.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
DOZZLE_TAILSIZE="${DOZZLE_TAILSIZE:-1000}"
5+
DOZZLE_FILTER="${DOZZLE_FILTER:-}"
6+
DOZZLE_WEBBASE="${DOZZLE_WEBBASE:-/}"
7+
DOZZLE_PORT="${DOZZLE_PORT:-$PORT}"
8+
9+
# If command starts with an option, prepend dozzle
10+
if [ "${1:0:1}" = '-' ]
11+
then
12+
set -- dozzle "$@"
13+
fi
14+
15+
if [ "${1}" == "dozzle" ]
16+
then
17+
CMD="$@ --addr :${DOZZLE_PORT}"
18+
[ -n "${DOZZLE_TAILSIZE}" ] && CMD="${CMD} --tailSize ${DOZZLE_TAILSIZE}"
19+
[ -n "${DOZZLE_FILTER}" ] && CMD="${CMD} --filter ${DOZZLE_FILTER}"
20+
[ -n "${DOZZLE_WEBBASE}" ] && CMD="${CMD} --base ${DOZZLE_WEBBASE}"
21+
# allow the container to be started with `--user`
22+
if [ "$(id -u)" == "0" ]
23+
then
24+
exec su-exec dozzle ${CMD}
25+
else
26+
exec ${CMD}
27+
fi
28+
else
29+
exec "$@"
30+
fi
31+

0 commit comments

Comments
 (0)