Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from johnmcollier/masterfix
Browse files Browse the repository at this point in the history
Fix devfile registry image
  • Loading branch information
makandre authored Apr 15, 2020
2 parents a53d8b6 + 1c91e05 commit 0a1e32f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
9 changes: 6 additions & 3 deletions build/dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#
# Copyright (c) 2018-2019 Red Hat, Inc.
# Copyright (c) 2018-2020 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
FROM alpine:3.10 AS builder
RUN apk add --no-cache py-pip jq bash wget git && pip install yq
RUN apk add --no-cache py-pip jq bash wget git skopeo && pip install yq

# Registry, organization, and tag to use for base images in dockerfiles. Devfiles
# will be rewritten during build to use these values for base images.
ARG PATCHED_IMAGES_REG="quay.io"
ARG PATCHED_IMAGES_ORG="eclipse"
ARG PATCHED_IMAGES_TAG="nightly"
ARG USE_DIGESTS=false

COPY ./build/scripts ./arbitrary-users-patch/base_images /build/
COPY ./devfiles /build/devfiles
Expand All @@ -23,14 +24,16 @@ RUN TAG=${PATCHED_IMAGES_TAG} \
REGISTRY=${PATCHED_IMAGES_REG} \
./update_devfile_patched_image_tags.sh
RUN ./check_mandatory_fields.sh devfiles
RUN if [[ ${USE_DIGESTS} == "true" ]]; then ./write_image_digests.sh devfiles; fi
RUN ./index.sh > /build/devfiles/index.json
RUN ./list_referenced_images.sh devfiles > /build/devfiles/external_images.txt
RUN chmod -R g+rwX /build/devfiles

FROM registry.centos.org/centos/httpd-24-centos7 AS registry
RUN mkdir /var/www/html/devfiles
RUN mkdir -m 777 /var/www/html/devfiles
COPY .htaccess README.md /var/www/html/
COPY --from=builder /build/devfiles /var/www/html/devfiles
COPY ./images /var/www/html/images
COPY ./build/dockerfiles/entrypoint.sh /usr/bin/
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
CMD ["/usr/bin/run-httpd"]
Expand Down
46 changes: 46 additions & 0 deletions build/scripts/write_image_digests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
#
# Copyright (c) 2020 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#

SCRIPT_DIR=$(cd "$(dirname "$0")" || exit; pwd)
LOG_FILE="/tmp/image_digests.log"

function handle_error() {
the_image="$1"
echo " Could not read image metadata through skopeo inspect; skip $the_image"
echo -n " Reason: "
sed 's|^| |g' $LOG_FILE
}

readarray -d '' devfiles < <(find "$1" -name 'devfile.yaml' -print0)
for image in $(yq -r '.components[]?.image' "${devfiles[@]}" | grep -v "null" | sort | uniq); do
digest="$(skopeo inspect "docker://${image}" 2>"$LOG_FILE" | jq -r '.Digest')"
if [[ ${digest} ]]; then
echo " $digest # ${image}"
else
# for other build methods or for falling back to other registries when not found, can apply transforms here
if [[ -x "${SCRIPT_DIR}/write_image_digests_alternate_urls.sh" ]]; then
# since extension file may not exist, disable this check
# shellcheck disable=SC1090
source "${SCRIPT_DIR}/write_image_digests_alternate_urls.sh"
fi
fi

# don't rewrite if we couldn't get a digest from either the basic image or the alternative image
if [[ ! ${digest} ]]; then
handle_error "$image"
continue
fi

digest_image="${image%:*}@${digest}"

# Rewrite images to use sha-256 digests
sed -i -E 's|"?'"${image}"'"?|"'"${digest_image}"'" # tag: '"${image}"'|g' "${devfiles[@]}"
done
rm $LOG_FILE
16 changes: 16 additions & 0 deletions images/codewind.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0a1e32f

Please sign in to comment.