Skip to content

Commit 33d83a8

Browse files
Merge remote-tracking branch 'origin/rootless' into CR-17416-rootless
2 parents 589a0d0 + f2ae1ea commit 33d83a8

File tree

15 files changed

+94
-58
lines changed

15 files changed

+94
-58
lines changed

Dockerfile

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,28 @@ RUN go mod tidy
1111
COPY cleaner/dind-cleaner/cmd ./cmd/
1212

1313
RUN CGO_ENABLED=0 go build -o /usr/local/bin/dind-cleaner ./cmd && \
14-
chmod +x /usr/local/bin/dind-cleaner && \
15-
rm -rf /go/*
14+
chmod +x /usr/local/bin/dind-cleaner && \
15+
rm -rf /go/*
1616

1717
# bolter
1818
FROM golang:1.19-alpine3.16 AS bolter
19+
RUN apk add git
1920
RUN go install github.com/hasit/[email protected]
2021

2122
# node-exporter
2223
FROM quay.io/prometheus/node-exporter:v1.5.0 AS node-exporter
2324

2425
# Main
25-
FROM docker:${DOCKER_VERSION}-dind
26+
FROM docker:${DOCKER_VERSION}-dind-rootless
2627

27-
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.11/main' >> /etc/apk/repositories \
28+
USER root
29+
30+
RUN chown -R $(id -u rootless) /var /run /lib /home /etc/ssl /etc/apk
31+
32+
# Add community for fuse-overlayfs
33+
RUN echo -en "https://dl-cdn.alpinelinux.org/alpine/v$(cut -d'.' -f1,2 /etc/alpine-release)/main\nhttps://dl-cdn.alpinelinux.org/alpine/v$(cut -d'.' -f1,2 /etc/alpine-release)/community" > /etc/apk/repositories \
2834
&& apk upgrade \
29-
&& apk add bash jq --no-cache \
35+
&& apk add bash jq fuse-overlayfs --no-cache \
3036
&& rm -rf /var/cache/apk/*
3137

3238
COPY --from=node-exporter /bin/node_exporter /bin/
@@ -36,4 +42,10 @@ COPY --from=bolter /go/bin/bolter /bin/
3642
WORKDIR /dind
3743
ADD . /dind
3844

45+
RUN chown -R $(id -u rootless) /dind
46+
RUN chown -R $(id -u rootless) /var/run
47+
48+
RUN chown -R $(id -u rootless) /etc/ssl && chmod 777 -R /etc/ssl
49+
USER rootless
50+
RUN rm -i -f /var/run && ln -s /run/user/1000 /var/run
3951
ENTRYPOINT ["./run.sh"]

cleaner/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Prunes unneeded containers, images, volumes
44

55
We intend to run dind cleaner on every SIGTERM
66

7-
To determine what to delete we will use information stored in /var/lib/docker/dind-volume
8-
- /var/lib/docker/dind-volume/last_cleaned_ts - contains timestamp of last clean (unix timestamp since 1970)
9-
- /var/lib/docker/dind-volume/last_cleaned_pod - contains pod name of last clean
10-
- /var/lib/docker/dind-volume/events/ - directory with files of docker events list from previous builds.
7+
To determine what to delete we will use information stored in /home/rootless/.local/share/docker/dind-volume
8+
- /home/rootless/.local/share/docker/dind-volume/last_cleaned_ts - contains timestamp of last clean (unix timestamp since 1970)
9+
- /home/rootless/.local/share/docker/dind-volume/last_cleaned_pod - contains pod name of last clean
10+
- /home/rootless/.local/share/docker/dind-volume/events/ - directory with files of docker events list from previous builds.
1111

1212
##### Environent Variables:
1313
CLEANER_DRY_RUN - do not actually delete - "echo docker rmi" instead of "docker rmi"
@@ -25,7 +25,7 @@ To determine what to delete we will use information stored in /var/lib/docker/di
2525
VOLUMES_RETAIN_PERIOD=${VOLUMES_RETAIN_PERIOD:-259200}
2626

2727
##### Logic:
28-
- save current docker events by `docker events --until 0s -f ${EVENT_FORMAT} > /var/lib/docker/dind-volume/events/$(date +%s)`
28+
- save current docker events by `docker events --until 0s -f ${EVENT_FORMAT} > /home/rootless/.local/share/docker/dind-volume/events/$(date +%s)`
2929
- checks last_cleaned_timestamp and exit if:
3030
`( current_timestamp - last_cleaned ) < ${CLEAN_PERIOD_SECONDS} and
3131
mount_count since last clean < ${CLEAN_PERIOD_BUILDS}

cleaner/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ DISK_USAGE_THRESHOLD=${DISK_USAGE_THRESHOLD:-0.8}
88
INODES_USAGE_THRESHOLD=${INODES_USAGE_THRESHOLD:-0.8}
99

1010
#### Defining DIND_VOLUME_STAT dir and stat files
11-
DOCKERD_DATA_ROOT=${DOCKERD_DATA_ROOT:-/var/lib/docker}
11+
DOCKERD_DATA_ROOT=${DOCKERD_DATA_ROOT:-/home/rootless/.local/share/docker}
1212
DIND_VOLUME_STAT_DIR=${DIND_VOLUME_STAT_DIR:-${DOCKERD_DATA_ROOT}/dind-volume}
1313
# mkdir -pv ${DIND_VOLUME_STAT_DIR}
1414

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"hosts": [ "unix:///var/run/docker.sock",
2+
"hosts": [ "unix:///run/user/1000/docker.sock",
33
"tcp://0.0.0.0:1300"],
44
"storage-driver": "overlay2"
55
}

cleaner/dind-cleaner/test/run-dind.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ if [[ $? == 0 ]]; then
2525
fi
2626

2727
docker run -d --privileged -p ${DIND_PORT}:1300 --name $CONTAINER_NAME \
28-
-v dind-cleaner-test:/var/lib/docker \
29-
-v $(realpath $DIR/dind-config-no-tls.json):/etc/docker/daemon.json \
28+
-v dind-cleaner-test:/home/rootless/.local/share/docker \
29+
-v $(realpath $DIR/dind-config-no-tls.json):~/.config/docker/daemon.json \
3030
$DIND_IMAGE $DIND_IMAGE_COMMAND
3131

3232
export DOCKER_HOST=localhost:1300

cleaner/docker-clean-sigterm.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ INODES_USAGE_THRESHOLD=${INODES_USAGE_THRESHOLD}
2626
"
2727

2828
#### Defining DIND_VOLUME_STAT dir and stat files
29-
DOCKERD_DATA_ROOT=${DOCKERD_DATA_ROOT:-/var/lib/docker}
29+
DOCKERD_DATA_ROOT=${DOCKERD_DATA_ROOT:-/home/rootless/.local/share/docker}
3030
DIND_VOLUME_STAT_DIR=${DIND_VOLUME_STAT_DIR:-${DOCKERD_DATA_ROOT}/dind-volume}
3131
mkdir -p ${DIND_VOLUME_STAT_DIR}
3232

@@ -157,7 +157,7 @@ clean_networks(){
157157

158158
clean_volumes(){
159159
echo -e "\n############# Cleaning Volumes ############# - $(date) "
160-
# Listing directories in /var/lib/docker/volumes and delete volume if its folder mtime>VOLUMES_RETAIN_PERIOD
160+
# Listing directories in /home/rootless/.local/share/docker/volumes and delete volume if its folder mtime>VOLUMES_RETAIN_PERIOD
161161
if [[ -n "${CLEANER_DRY_RUN}" ]]; then
162162
echo "Running in DRY_RUN, just display rm commands"
163163
fi

cleaner/docker-clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ INODES_USAGE_THRESHOLD=${INODES_USAGE_THRESHOLD}
2727
"
2828

2929
#### Defining DIND_VOLUME_STAT dir and stat files
30-
DOCKERD_DATA_ROOT=${DOCKERD_DATA_ROOT:-/var/lib/docker}
30+
DOCKERD_DATA_ROOT=${DOCKERD_DATA_ROOT:-/home/rootless/.local/share/docker}
3131
DIND_VOLUME_STAT_DIR=${DIND_VOLUME_STAT_DIR:-${DOCKERD_DATA_ROOT}/dind-volume}
3232
mkdir -p ${DIND_VOLUME_STAT_DIR}
3333

cleaner/functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ clean_networks(){
9898

9999
clean_volumes(){
100100
echo -e "\n############# Cleaning Volumes ############# - $(date) "
101-
# Listing directories in /var/lib/docker/volumes and delete volume if its folder mtime>VOLUMES_RETAIN_PERIOD
101+
# Listing directories in /home/rootless/.local/share/docker/volumes and delete volume if its folder mtime>VOLUMES_RETAIN_PERIOD
102102
if [[ -n "${CLEANER_DRY_RUN}" ]]; then
103103
echo "Running in DRY_RUN, just display rm commands"
104104
fi

default-daemon.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"storage-driver": "overlay2",
3+
"tlsverify": true,
4+
"tls": true,
5+
"tlscacert": "/etc/ssl/cf/ca.pem",
6+
"tlscert": "/etc/ssl/cf/server-cert.pem",
7+
"tlskey": "/etc/ssl/cf/server-key.pem",
8+
"metrics-addr" : "0.0.0.0:9323",
9+
"experimental" : true
10+
}

docker/azure-daemon.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"hosts": [ "unix:///var/run/docker.sock",
2+
"hosts": [ "unix:///run/user/1000/docker.sock",
33
"tcp://0.0.0.0:1300"],
44
"storage-driver": "overlay2",
55
"tlsverify": true,

0 commit comments

Comments
 (0)