generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add tests for distroless image #7
Open
g-gaston
wants to merge
2
commits into
kubernetes-sigs:master
Choose a base branch
from
g-gaston:follow-up-distroless-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,11 @@ FROM debian:buster | |
ARG INSTALL_ARGS= | ||
ARG REPO=buster | ||
|
||
RUN echo deb http://deb.debian.org/debian buster-backports main >> /etc/apt/sources.list; \ | ||
RUN echo deb http://archive.debian.org/debian buster-backports main >> /etc/apt/sources.list; \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they changed this url for buster and that broke the test |
||
apt-get update; \ | ||
apt-get -t ${REPO} -y --no-install-recommends install iptables | ||
|
||
COPY iptables-wrapper-installer.sh / | ||
COPY bin/iptables-wrapper / | ||
RUN /iptables-wrapper-installer.sh ${INSTALL_ARGS} | ||
COPY test/test.sh / | ||
COPY bin/tests / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2023 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
### Dockerfile for building a distroless image for testing | ||
# Modified version of https://github.com/kubernetes/release/blob/master/images/build/distroless-iptables/distroless/Dockerfile | ||
|
||
ARG STAGE_DIR="/opt/stage" | ||
|
||
FROM debian:bullseye-slim AS build | ||
ARG STAGE_DIR | ||
|
||
COPY test/build/stage-binaries-from-package.sh / | ||
COPY test/build/package-utils.sh / | ||
COPY test/build/stage-binary-and-deps.sh / | ||
|
||
RUN mkdir -p "${STAGE_DIR}" && \ | ||
/stage-binaries-from-package.sh "${STAGE_DIR}" iptables | ||
|
||
FROM gcr.io/distroless/static | ||
ARG STAGE_DIR | ||
|
||
COPY --from=build "${STAGE_DIR}" / | ||
COPY bin/iptables-wrapper /usr/sbin/iptables-wrapper | ||
RUN ["/usr/sbin/iptables-wrapper", "install", "/usr/sbin"] | ||
COPY bin/tests / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# Copied from https://github.com/kubernetes/release/blob/master/images/build/distroless-iptables/distroless/package-utils.sh | ||
|
||
# Copyright 2022 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# file_to_package identifies the debian package that provided the file $1 | ||
file_to_package() { | ||
# `dpkg-query --search $file-pattern` outputs lines with the format: "$package: $file-path" | ||
# where $file-path belongs to $package | ||
# https://manpages.debian.org/jessie/dpkg/dpkg-query.1.en.html | ||
dpkg-query --search "$(realpath "${1}")" | cut -d':' -f1 | ||
} | ||
|
||
# package_to_copyright gives the path to the copyright file for the package $1 | ||
package_to_copyright() { | ||
echo "/usr/share/doc/${1}/copyright" | ||
} | ||
|
||
# stage_file stages the filepath $1 to $2, following symlinks | ||
# and staging copyrights | ||
stage_file() { | ||
cp -a --parents "${1}" "${2}" | ||
# recursively follow symlinks | ||
if [[ -L "${1}" ]]; then | ||
stage_file "$(cd "$(dirname "${1}")" || exit; realpath -s "$(readlink "${1}")")" "${2}" | ||
fi | ||
# get the package so we can stage package metadata as well | ||
package="$(file_to_package "${1}")" | ||
# stage the copyright for the file | ||
cp -a --parents "$(package_to_copyright "${package}")" "${2}" | ||
# stage the package status mimicking bazel | ||
# https://github.com/bazelbuild/rules_docker/commit/f5432b813e0a11491cf2bf83ff1a923706b36420 | ||
# instead of parsing the control file, we can just get the actual package status with dpkg | ||
dpkg -s "${package}" > "${2}/var/lib/dpkg/status.d/${package}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
|
||
# Copied from https://github.com/kubernetes/release/blob/master/images/build/distroless-iptables/distroless/stage-binaries-from-package.sh | ||
|
||
# Copyright 2022 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# USAGE: stage-binaries-from-package.sh /opt/stage package1 package2 | ||
# | ||
# Stages all the packages and its dependencies (+ libraries and copyrights) to $1 | ||
# | ||
# This is intended to be used in a multi-stage docker build with a distroless/base | ||
# or distroless/cc image. | ||
set -e | ||
|
||
. package-utils.sh | ||
|
||
stage_file_list() { | ||
IFS=" | ||
" | ||
REQUIRED_FILES="$(dpkg -L "${1}" | grep -vE '(/\.|/s?bin/|/usr/share/(man|doc|.*-completion))' | sed 's/\n/ /g')" | ||
for file in $REQUIRED_FILES; do | ||
if [ -f "$file" ]; then | ||
stage_file "${file}" "${STAGE_DIR}" | ||
fi | ||
done | ||
|
||
BIN_LIST="$(dpkg -L "${1}" | grep -E '/s?bin/' |sed 's/\n/ /g')" | ||
for binary in $BIN_LIST; do | ||
/stage-binary-and-deps.sh "${2}" "${binary}" | ||
done | ||
} | ||
|
||
get_dependent_packages() { | ||
apt-cache depends "${1}" |grep Depends|awk -F '.*Depends:[[:space:]]?' '{print $2}' | ||
} | ||
|
||
main() { | ||
STAGE_DIR="${1}/" | ||
mkdir -p "${STAGE_DIR}"/var/lib/dpkg/status.d/ | ||
apt-get -y update | ||
shift | ||
while (( "$#" )); do # While there are arguments still to be shifted | ||
PACKAGE="${1}" | ||
apt-get -y install "${PACKAGE}" | ||
stage_file_list "${PACKAGE}" "$STAGE_DIR" | ||
while IFS= read -r c_dep; do | ||
stage_file_list "${c_dep}" "${STAGE_DIR}" | ||
done < <(get_dependent_packages "${PACKAGE}") | ||
shift | ||
done | ||
} | ||
|
||
main "$@" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be wrong here bu I think before this change it wasn't creating symlinks for
ip6tables-*
because the name overlapped with the previous slaves. Or at least that's what I found during testing.