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: migrate to fully distroless ocm image #1087

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 9 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ARG GO_VERSION="1.23"
ARG ALPINE_VERSION="3.20"
ARG DISTROLESS_VERSION=debian12@sha256:d71f4b239be2d412017b798a0a401c44c3049a3ca454838473a4c32ed076bfea

FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build

Expand All @@ -20,26 +21,21 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
"-s -w -X ocm.software/ocm/api/version.gitVersion=$VERSION -X ocm.software/ocm/api/version.buildDate=$NOW" \
-o /bin/ocm ./cmds/ocm/main.go

FROM alpine:${ALPINE_VERSION}
FROM gcr.io/distroless/static-${DISTROLESS_VERSION}
# pass arg from initial build
ARG DISTROLESS_VERSION

# Create group and user
ARG UID=1000
ARG GID=1000
RUN addgroup -g "${GID}" ocmGroup && adduser -u "${UID}" ocmUser -G ocmGroup -D

COPY --from=build /bin/ocm /bin/ocm
COPY --chmod=0755 components/ocmcli/ocm.sh /bin/ocm.sh
COPY --from=build /bin/ocm /usr/local/bin/ocm

# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
LABEL org.opencontainers.image.description="Open Component Model command line interface based on Alpine ${ALPINE_VERSION}"
LABEL org.opencontainers.image.description="Open Component Model command line interface based on Distroless ${DISTROLESS_VERSION}"
LABEL org.opencontainers.image.vendor="SAP SE"
LABEL org.opencontainers.image.licenses="Apache-2.0"
LABEL org.opencontainers.image.url="https://ocm.software/"
LABEL org.opencontainers.image.source="https://github.com/open-component-model/ocm"
LABEL org.opencontainers.image.title="ocm"
LABEL org.opencontainers.image.documentation="https://github.com/open-component-model/ocm/blob/main/docs/reference/ocm.md"
LABEL org.opencontainers.image.base.name="alpine:${ALPINE_VERSION}"
LABEL org.opencontainers.image.base.name="gcr.io/distroless/static-${DISTROLESS_VERSION}"

USER ocmUser
ENTRYPOINT ["/bin/ocm.sh"]
CMD ["/bin/ocm"]
ENTRYPOINT ["/usr/local/bin/ocm"]
CMD ["version"]
24 changes: 10 additions & 14 deletions components/ocmcli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
# This Dockerfile is used by `make` via the Makefile

ARG ALPINE_VERSION="3.20.2"
FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION}

# Create group and user
ARG UID=1000
ARG GID=1000
RUN addgroup -g "${GID}" ocmGroup && adduser -u "${UID}" ocmUser -G ocmGroup -D
# debian12:nonroot
ARG DISTROLESS_VERSION=debian12@sha256:d71f4b239be2d412017b798a0a401c44c3049a3ca454838473a4c32ed076bfea
FROM --platform=$BUILDPLATFORM gcr.io/distroless/static-${DISTROLESS_VERSION}
# pass arg from initial build
ARG DISTROLESS_VERSION

ARG SUFFIX
ARG OCM_VERSION

COPY gen/ocmcli/ocmcli.$SUFFIX /bin/ocm
COPY --chmod=0755 components/ocmcli/ocm.sh /bin/ocm.sh
COPY gen/ocmcli/ocmcli.$SUFFIX /usr/local/bin/ocm

# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
LABEL org.opencontainers.image.description="Open Component Model command line interface based on Alpine ${ALPINE_VERSION}"
LABEL org.opencontainers.image.description="Open Component Model command line interface based on Distroless ${DISTROLESS_VERSION}"
LABEL org.opencontainers.image.vendor="SAP SE"
LABEL org.opencontainers.image.licenses="Apache-2.0"
LABEL org.opencontainers.image.url="https://ocm.software/"
Expand All @@ -24,8 +21,7 @@ LABEL org.opencontainers.image.title="ocm"
LABEL org.opencontainers.image.version="${OCM_VERSION}"
LABEL org.opencontainers.image.revision="${OCM_VERSION}"
LABEL org.opencontainers.image.documentation="https://github.com/open-component-model/ocm/blob/main/docs/reference/ocm.md"
LABEL org.opencontainers.image.base.name="alpine:${ALPINE_VERSION}"
LABEL org.opencontainers.image.base.name="gcr.io/distroless/static-${DISTROLESS_VERSION}"

USER ocmUser
ENTRYPOINT ["/bin/ocm.sh"]
CMD ["/bin/ocm"]
ENTRYPOINT ["/usr/local/bin/ocm"]
CMD ["version"]
6 changes: 0 additions & 6 deletions components/ocmcli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ BUILD_FLAGS := "-s -w \
-X ocm.software/ocm/api/version.gitCommit=$(COMMIT) \
-X ocm.software/ocm/api/version.buildDate=$(NOW)"

ALPINE_LATEST_VER=$(shell curl -s https://registry.hub.docker.com/v2/repositories/library/alpine/tags | jq '.results[1].name' | xargs)

.PHONY: build
build: $(GEN)/build

Expand All @@ -72,13 +70,11 @@ $(GEN)/image: $(GEN)/.exists Dockerfile $(GEN)/build
echo; echo "Building linux instead of darwin as there's no native Docker platform for darwin"; echo; \
docker buildx build -t $(IMAGE):$(VERSION) --platform linux/$(PLATFORM_ARCH) --file Dockerfile $(REPO_ROOT) \
--build-arg OCM_VERSION=$(EFFECTIVE_VERSION) \
--build-arg ALPINE_VERSION=$(ALPINE_LATEST_VER) \
--build-arg SUFFIX=$$(echo linux/$(PLATFORM_ARCH) | sed -e s:/:-:g); \
else \
echo; echo "Building for $(PLATFORM_OS)/$(ARCH)"; echo; \
docker buildx build -t $(IMAGE):$(VERSION) --platform $(PLATFORM_OS)/$(PLATFORM_ARCH) --file Dockerfile $(REPO_ROOT) \
--build-arg OCM_VERSION=$(EFFECTIVE_VERSION) \
--build-arg ALPINE_VERSION=$(ALPINE_LATEST_VER) \
--build-arg SUFFIX=$$(echo $(PLATFORM_OS)/$(PLATFORM_ARCH) | sed -e s:/:-:g); \
fi
@touch $(GEN)/image
Expand All @@ -87,13 +83,11 @@ $(GEN)/image: $(GEN)/.exists Dockerfile $(GEN)/build
image.multi: $(GEN)/image.multi

$(GEN)/image.multi: Dockerfile $(GEN)/build
echo "Building with Alpine version: ${ALPINE_LATEST_VER}"
for i in $(IMAGE_PLATFORMS); do \
tag=$$(echo $$i | sed -e s:/:-:g); \
echo building platform $$i; \
docker buildx build --load -t $(IMAGE):$(VERSION)-$$tag --platform $$i --file Dockerfile $(REPO_ROOT) \
--build-arg OCM_VERSION=$(EFFECTIVE_VERSION) \
--build-arg ALPINE_VERSION=$(ALPINE_LATEST_VER) \
--build-arg SUFFIX=$$tag; \
done
@touch $(GEN)/image.multi
Expand Down
20 changes: 0 additions & 20 deletions components/ocmcli/ocm.sh

This file was deleted.