-
Notifications
You must be signed in to change notification settings - Fork 524
Add arm64 support for linux images #3607
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c9341a5
Initial start adding multi platform images
marcofranssen 02057b6
Add caching for go mod download
marcofranssen 0f6d298
Fix ldflags for static build
marcofranssen adda222
Fix cross compilation
developer-guy 70d9544
Remove bind mount to ensure arch is not mixed up
marcofranssen e27d70f
Prevent unneeded files from being copied into builder images
marcofranssen b6615ff
Utilize alpine image with musl for static compile
developer-guy f9ec898
Add --no-cache and --update to apk add
marcofranssen 7d1536b
Lock tonistiigi/xx by digest (immutable)
marcofranssen a2fcb40
Don't remove dangling images
marcofranssen f75bc88
Improve caching slightly for scratch images
marcofranssen 8a6b358
Merge branch 'main' into multi-platform-images
marcofranssen 815b9e7
Merge branch 'main' into multi-platform-images
marcofranssen 175e290
Merge branch 'main' into multi-platform-images
marcofranssen 74f0cf0
Merge branch 'main' into multi-platform-images
429a9ef
Merge branch 'main' into multi-platform-images
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 hidden or 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 |
---|---|---|
|
@@ -3,3 +3,9 @@ | |
.cache | ||
releases/ | ||
artifacts/ | ||
.githooks/ | ||
script/ | ||
doc/ | ||
examples/ | ||
oci/ | ||
*-image.tar |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,74 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck shell=bash | ||
## | ||
## USAGE: __PROG__ | ||
## | ||
## "__PROG__" loads oci tarballs created with xbuild into docker. | ||
## | ||
## Usage example(s): | ||
## ./__PROG__ | ||
## ./__PROG__ -scratch | ||
## PLATFORM=linux/arm64 ./__PROG__ -scratch | ||
## | ||
## Commands | ||
## - ./__PROG__ <image-variant> loads the oci tarball for the optional variant into Docker. | ||
|
||
function usage { | ||
grep '^##' "$0" | sed -e 's/^##//' -e "s/__PROG__/$me/" >&2 | ||
} | ||
|
||
function normalize_path { | ||
# Remove all /./ sequences. | ||
local path=${1//\/.\//\/} | ||
local npath | ||
# Remove first dir/.. sequence. | ||
npath="${path//[^\/][^\/]*\/\.\.\//}" | ||
# Remove remaining dir/.. sequence. | ||
while [[ $npath != "$path" ]] ; do | ||
path=$npath | ||
npath="${path//[^\/][^\/]*\/\.\.\//}" | ||
done | ||
echo "$path" | ||
} | ||
|
||
me=$(basename "$0") | ||
BASEDIR=$(dirname "$0") | ||
ROOTDIR="$(normalize_path "$BASEDIR/../../../")" | ||
|
||
command -v regctl >/dev/null 2>&1 || { usage; echo -e "\n * The regctl cli is required to run this script." >&2 ; exit 1; } | ||
command -v docker >/dev/null 2>&1 || { usage; echo -e "\n * The docker cli is required to run this script." >&2 ; exit 1; } | ||
|
||
variant="$1" | ||
|
||
if [ -n "$variant" ] && [ "$variant" != "-scratch" ] ; then | ||
usage | ||
echo -e "The only supported variants are '-scratch'." >&2 | ||
exit 1 | ||
fi | ||
|
||
# Takes the current platform architecture or plaftorm as defined externally in a platform variable. | ||
# e.g.: | ||
# linux/amd64 | ||
# linux/arm64 | ||
# linux/arm64/v7 | ||
PLATFORM="${PLATFORM:-local}" | ||
OCI_IMAGES=( | ||
spire-server spire-agent k8s-workload-registrar oidc-discovery-provider | ||
) | ||
|
||
echo "Importing ${OCI_IMAGES[*]} into docker". | ||
for img in "${OCI_IMAGES[@]}"; do | ||
image_variant="${img}${variant}" | ||
oci_dir="ocidir://${ROOTDIR}oci/${image_variant}" | ||
platform_tar="${image_variant}-${PLATFORM}-image.tar" | ||
|
||
# regclient works with directories rather than tars, so import the OCI tar to a directory | ||
regctl image import "$oci_dir" "${image_variant}-image.tar" | ||
dig="$(regctl image digest --platform "$PLATFORM" "$oci_dir")" | ||
# export the single platform image using the digest | ||
regctl image export "$oci_dir@${dig}" "${platform_tar}" | ||
|
||
docker load < "${platform_tar}" | ||
docker image tag "localhost/oci/${image_variant}:latest" "${image_variant}:latest-local" | ||
docker image rm "localhost/oci/${image_variant}:latest" | ||
done |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,37 +1,44 @@ | ||
# Build stage | ||
# syntax = docker/dockerfile:1.4.2@sha256:443aab4ca21183e069e7d8b2dc68006594f40bddf1b15bbd83f5137bd93e80e2 | ||
ARG goversion | ||
FROM golang:${goversion}-alpine as builder | ||
FROM --platform=${BUILDPLATFORM} golang:${goversion}-alpine as base | ||
WORKDIR /spire | ||
COPY go.* ./ | ||
# https://go.dev/ref/mod#module-cache | ||
RUN --mount=type=cache,target=/go/pkg/mod go mod download | ||
COPY . . | ||
|
||
FROM base as builder | ||
ARG TARGETOS TARGETARCH | ||
RUN apk --no-cache --update add build-base git mercurial | ||
ADD go.* ./ | ||
RUN go mod download | ||
ADD . . | ||
RUN make build | ||
RUN --mount=type=cache,target=/root/.cache/go-build \ | ||
--mount=type=cache,target=/go/pkg/mod \ | ||
GOOS=$TARGETOS GOARCH=$TARGETARCH \ | ||
make build | ||
|
||
# Common base | ||
FROM alpine AS spire-base | ||
FROM --platform=${BUILDPLATFORM} alpine AS spire-base | ||
WORKDIR /opt/spire | ||
RUN mkdir -p /opt/spire/bin | ||
CMD [] | ||
RUN apk --no-cache --update add dumb-init | ||
RUN apk --no-cache --update add ca-certificates | ||
|
||
# SPIRE Server | ||
FROM spire-base AS spire-server | ||
ENTRYPOINT ["/usr/bin/dumb-init", "/opt/spire/bin/spire-server", "run"] | ||
COPY --from=builder /spire/bin/spire-server bin/spire-server | ||
COPY --link --from=builder /spire/bin/spire-server bin/spire-server | ||
|
||
# SPIRE Agent | ||
FROM spire-base AS spire-agent | ||
ENTRYPOINT ["/usr/bin/dumb-init", "/opt/spire/bin/spire-agent", "run"] | ||
COPY --from=builder /spire/bin/spire-agent bin/spire-agent | ||
COPY --link --from=builder /spire/bin/spire-agent bin/spire-agent | ||
|
||
# K8S Workload Registrar | ||
FROM spire-base AS k8s-workload-registrar | ||
ENTRYPOINT ["/usr/bin/dumb-init", "/opt/spire/bin/k8s-workload-registrar"] | ||
COPY --from=builder /spire/bin/k8s-workload-registrar bin/k8s-workload-registrar | ||
COPY --link --from=builder /spire/bin/k8s-workload-registrar bin/k8s-workload-registrar | ||
|
||
# OIDC Discovery Provider | ||
FROM spire-base AS oidc-discovery-provider | ||
ENTRYPOINT ["/usr/bin/dumb-init", "/opt/spire/bin/oidc-discovery-provider"] | ||
COPY --from=builder /spire/bin/oidc-discovery-provider bin/oidc-discovery-provider | ||
COPY --link --from=builder /spire/bin/oidc-discovery-provider bin/oidc-discovery-provider |
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.
Uses regctl to load the image for the architecture of this github runner into docker.