Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: docker-kind-support #428

Merged
merged 57 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ae54f66
add docker and kind
rauerhans Aug 10, 2023
a5b7be0
fix, 24.0.5 not signed yet (?)
rauerhans Aug 11, 2023
a84e8c2
install s6
rauerhans Aug 11, 2023
7065582
need the dockerfiles in the context
rauerhans Aug 11, 2023
f271a3c
s6 services config for docker
rauerhans Aug 11, 2023
a526df3
docker as nonroot
rauerhans Aug 11, 2023
9facf70
rename
rauerhans Aug 11, 2023
d05fd3c
fix typo
rauerhans Aug 11, 2023
9ac19f3
fix iptables issue
rauerhans Aug 14, 2023
d1a2962
add modprobe
rauerhans Aug 14, 2023
ee58c9d
use rootless install script
rauerhans Aug 14, 2023
42ca6ad
add env vars
rauerhans Aug 14, 2023
12b00b9
fix
rauerhans Aug 14, 2023
1b116f8
fix
rauerhans Aug 14, 2023
2ecb415
fix
rauerhans Aug 14, 2023
e8bc23d
rm debug code
rauerhans Aug 14, 2023
e770374
try with fuse-overlayfs
rauerhans Aug 14, 2023
26aaa51
test
rauerhans Aug 15, 2023
99bcb47
test dockerfile systemd
rauerhans Aug 15, 2023
f46f1fc
fix build
rauerhans Aug 15, 2023
9034f80
add missing iproute2
rauerhans Aug 15, 2023
518f7bd
pod yamls
rauerhans Aug 15, 2023
934d37a
jammy test with plural login
rauerhans Aug 15, 2023
67b0cd3
update image
rauerhans Aug 15, 2023
980c7b4
sysbox priv
rauerhans Aug 15, 2023
4bfdf90
add user/contents.d
rauerhans Aug 15, 2023
b3c5de0
test podman build
rauerhans Aug 17, 2023
db55c69
this at least works with --privileged
rauerhans Aug 17, 2023
028913c
rm dockerd s6 service, clogs logs
rauerhans Aug 17, 2023
eb27230
try on sysbox runc
rauerhans Aug 17, 2023
14a0577
shouldn't matter, but let's see
rauerhans Aug 17, 2023
7accdf4
unset mount program, be specific about defaults
rauerhans Aug 17, 2023
3020aba
test with new storage.conf
rauerhans Aug 17, 2023
5bb8d73
simplify
rauerhans Aug 17, 2023
383e8a2
for some reason this does make a difference
rauerhans Aug 18, 2023
475da92
try with vfs
rauerhans Aug 18, 2023
69f07ba
makes it worse
rauerhans Aug 18, 2023
92dbc94
fix perm on volume
rauerhans Aug 18, 2023
82f8584
add back mknod
rauerhans Aug 18, 2023
288b32d
force newer version of podman, crun dep is ancient
rauerhans Aug 18, 2023
d1a57a8
trigger build
rauerhans Aug 20, 2023
952839c
build with docker-ce-cli only
rauerhans Aug 21, 2023
3f77ba2
dind sidecar approach
rauerhans Aug 21, 2023
bf87efe
clean up
rauerhans Aug 21, 2023
b5986ad
create dind dockerfile with systemd conf
rauerhans Aug 21, 2023
21d6bf3
add make target
rauerhans Aug 21, 2023
765086e
dont ignore systemd files
rauerhans Aug 21, 2023
8caac46
add dind build gh wf step
rauerhans Aug 21, 2023
0ea8413
rm trest image dockerfile
rauerhans Aug 21, 2023
bd7ddd1
rm debug yamnls
rauerhans Aug 21, 2023
b42445f
clean up
rauerhans Aug 21, 2023
d2fd7b4
clean up, not needed with correct unit file
rauerhans Aug 21, 2023
6ae1e75
rm dependencies of podman
rauerhans Aug 21, 2023
ad2796a
clean up
rauerhans Aug 21, 2023
1922868
rm get-docker.sh was need for debugging
rauerhans Aug 21, 2023
6643090
update yaml
rauerhans Aug 21, 2023
e7f7127
delete sidecar yaml example, not needed in repo
rauerhans Aug 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ packer/
hack/
Makefile
Dockerfile
dockerfiles/
dockerfiles
!dockerfiles/dind-config
101 changes: 101 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,107 @@ jobs:
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
dind:
name: Build dind image
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
packages: 'write'
security-events: write
actions: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-2
role-to-assume: arn:aws:iam::312272277431:role/github-actions/buildx-deployments
role-session-name: PluralCLI
- name: setup kubectl
uses: azure/setup-kubectl@v3
- name: Get EKS credentials
run: aws eks update-kubeconfig --name pluraldev
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/pluralsh/plural-dind
# generate Docker tags based on the following events/attributes
tags: |
type=sha
type=ref,event=pr
type=ref,event=branch
- name: Set up Docker Buildx
id: builder
uses: docker/setup-buildx-action@v2
with:
driver: kubernetes
platforms: linux/amd64
driver-opts: |
namespace=buildx
requests.cpu=1.5
requests.memory=3.5Gi
"nodeselector=plural.sh/scalingGroup=buildx-spot-x86"
"tolerations=key=plural.sh/capacityType,value=SPOT,effect=NoSchedule;key=plural.sh/reserved,value=BUILDX,effect=NoSchedule"
- name: Append ARM buildx builder from AWS
run: |
docker buildx create \
--append \
--bootstrap \
--name ${{ steps.builder.outputs.name }} \
--driver=kubernetes \
--platform linux/arm64 \
--node=${{ steps.builder.outputs.name }}-arm64 \
--buildkitd-flags "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host" \
--driver-opt namespace=buildx \
--driver-opt requests.cpu=1.5 \
--driver-opt requests.memory=3.5Gi \
'--driver-opt="nodeselector=plural.sh/scalingGroup=buildx-spot-arm64"' \
'--driver-opt="tolerations=key=plural.sh/capacityType,value=SPOT,effect=NoSchedule;key=plural.sh/reserved,value=BUILDX,effect=NoSchedule"'
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get current date
id: date
run: echo "date=$(date -u +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_OUTPUT
- uses: docker/build-push-action@v4
with:
context: .
file: ./dockerfiles/Dockerfile.dind
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
# cache-from: type=gha
# cache-to: type=gha,mode=max
build-args: |
APP_VSN=dev
APP_COMMIT=${{ github.sha }}
APP_DATE=${{ steps.date.outputs.date }}
- name: Run Trivy vulnerability scanner on dind image
uses: aquasecurity/trivy-action@master
with:
scan-type: 'image'
image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
hide-progress: false
format: 'sarif'
output: 'trivy-results.sarif'
scanners: 'vuln'
timeout: 10m
ignore-unfixed: true
#severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'

trivy-scan:
name: Trivy fs scan
runs-on: ubuntu-latest
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ build-cloud: ## build the cloud docker image
-t gcr.io/$(GCP_PROJECT)/$(APP_NAME)-cloud:$(APP_VSN) \
-t $(DKR_HOST)/plural/$(APP_NAME)-cloud:$(APP_VSN) -f dockerfiles/Dockerfile.cloud .

.PHONY: build-dind
build-dind: ## build the dind docker image
docker build --build-arg APP_NAME=$(APP_NAME) \
--build-arg APP_VSN=$(APP_VSN) \
--build-arg APP_DATE=$(APP_DATE) \
--build-arg APP_COMMIT=$(BUILD) \
-t $(APP_NAME)-cloud:$(APP_VSN) \
-t $(APP_NAME)-cloud:latest \
-t gcr.io/$(GCP_PROJECT)/$(APP_NAME)-cloud:$(APP_VSN) \
-t $(DKR_HOST)/plural/$(APP_NAME)-dind:$(APP_VSN) -f dockerfiles/Dockerfile.dind .

.PHONY: push
push: ## push to gcr
docker push gcr.io/$(GCP_PROJECT)/$(APP_NAME):$(APP_VSN)
Expand Down
16 changes: 16 additions & 0 deletions dockerfiles/Dockerfile.cloud
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.
google-cloud-sdk-gke-gcloud-auth-plugin && \
gcloud --help


# install kind
# K8s.io KinD
ENV KIND_VERSION=v0.20.0
RUN curl -Lo ./kind https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-amd64 \
&& chmod +x ./kind \
&& mv ./kind /usr/bin/kind

# install docker cli
RUN install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
chmod a+r /etc/apt/keyrings/docker.gpg && \
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt-get -yq update && apt-get -yq install docker-ce-cli


WORKDIR /root

ENV TERM=xterm-256color
Expand Down
58 changes: 58 additions & 0 deletions dockerfiles/Dockerfile.dind
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
FROM ubuntu:jammy

#
# Systemd installation
#
RUN apt-get update && \
apt-get install -y --no-install-recommends \
systemd \
systemd-sysv \
libsystemd0 \
ca-certificates \
dbus \
iptables \
iproute2 \
kmod \
locales \
sudo \
udev && \
\
# Prevents journald from reading kernel messages from /dev/kmsg
echo "ReadKMsg=no" >> /etc/systemd/journald.conf && \
\
# Housekeeping
apt-get clean -y && \
rm -rf \
/var/cache/debconf/* \
/var/lib/apt/lists/* \
/var/log/* \
/tmp/* \
/var/tmp/* \
/usr/share/doc/* \
/usr/share/man/* \
/usr/share/local/*

# Disable systemd services/units that are unnecessary within a container.
RUN systemctl mask systemd-udevd.service \
systemd-udevd-kernel.socket \
systemd-udevd-control.socket \
systemd-modules-load.service \
sys-kernel-debug.mount \
sys-kernel-tracing.mount

# Make use of stopsignal (instead of sigterm) to stop systemd containers.
STOPSIGNAL SIGRTMIN+3


# Install Docker
RUN apt-get update && apt-get install -y curl \
&& rm -rf /var/lib/apt/lists/* \
&& curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh \
ADD https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker /etc/bash_completion.d/docker.sh

COPY dockerfiles/dind-config/docker.service /lib/systemd/system/docker.service
COPY dockerfiles/dind-config/daemon.json /etc/docker/daemon.json


# Set systemd as entrypoint.
ENTRYPOINT [ "/sbin/init", "--log-level=err" ]
3 changes: 3 additions & 0 deletions dockerfiles/dind-config/daemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]
}
50 changes: 50 additions & 0 deletions dockerfiles/dind-config/docker.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
#### BEGIN MOD ####
ExecStart=/usr/bin/dockerd --config-file /etc/docker/daemon.json --containerd=/run/containerd/containerd.sock
#### END MOD ######
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target