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

chore: Pre-build DevWorkspace templates for devfile v2 #518

Merged
merged 14 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions build/dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ 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 docker.io/node:16.13.0-alpine3.14 as dwtemplates
COPY ./build/scripts /build/
COPY ./devfiles /build/devfiles
WORKDIR /build/
RUN ./generate_devworkspace_templates.sh

FROM docker.io/httpd:2.4.43-alpine AS registry
RUN apk add --no-cache bash && \
# Allow htaccess
Expand All @@ -31,6 +37,7 @@ RUN apk add --no-cache bash && \
apk add --no-cache coreutils
COPY .htaccess README.md /usr/local/apache2/htdocs/
COPY --from=builder /build/devfiles /usr/local/apache2/htdocs/devfiles
COPY --from=dwtemplates /build/out /usr/local/apache2/htdocs/devfiles
COPY ./images /usr/local/apache2/htdocs/images
COPY ./build/dockerfiles/entrypoint.sh /usr/bin/
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
Expand Down
10 changes: 10 additions & 0 deletions build/dockerfiles/rhel.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ 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.access.redhat.com/ubi8/nodejs-16-minimal:1-6 as dwtemplates
USER 0

COPY ./build/scripts /build/
COPY ./devfiles /build/devfiles
WORKDIR /build/
RUN ./generate_devworkspace_templates.sh

#################
# PHASE TWO: configure registry image
#################
Expand Down Expand Up @@ -84,6 +93,7 @@ WORKDIR /var/www/html
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 --from=dwtemplates /build/out /var/www/html/devfiles
COPY ./images /var/www/html/images
COPY ./build/dockerfiles/rhel.entrypoint.sh ./build/dockerfiles/entrypoint.sh /usr/local/bin/
RUN chmod g+rwX /usr/local/bin/entrypoint.sh /usr/local/bin/rhel.entrypoint.sh
Expand Down
25 changes: 25 additions & 0 deletions build/scripts/generate_devworkspace_templates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
#
# Copyright (c) 2021 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
#

npm install -g @eclipse-che/che-theia-devworkspace-handler@0.0.1-1637592995
mkdir /build/out/
for dir in /build/devfiles/*/
do
devfile=$(grep "v2:" "${dir}"meta.yaml)
if [ -n "$devfile" ]; then
devfile=${devfile##*v2: }
dir=${dir%/}
dir=/build/out/${dir##*/}
mkdir "${dir}"
npx @eclipse-che/che-theia-devworkspace-handler --devfile-url:"${devfile}" --output-file:"${dir}"/devworkspace-che-theia-next.yaml
npx @eclipse-che/che-theia-devworkspace-handler --devfile-url:"${devfile}" --editor:eclipse/che-theia/latest \
--output-file:"${dir}"/devworkspace-che-theia-latest.yaml
fi
done
7 changes: 7 additions & 0 deletions build/scripts/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@ for meta in "${metas[@]}"; do
# Ignore double quotes warning for yq expression
# shellcheck disable=SC2016,SC2094
cat <<< "$(yq --arg metadir "${META_DIR}" '.links |= . + {self: "/\($metadir)/devfile.yaml" }' "${meta}")" > "${meta}"
if [ "$(yq '.links.v2' "${meta}")" != "null" ]; then
# Ignore double quotes warning for yq expression
# shellcheck disable=SC2016,SC2094
benoitf marked this conversation as resolved.
Show resolved Hide resolved
cat <<< "$(yq --arg metadir "${META_DIR}" '.links.devWorkspaces |= . +
{"eclipse/che-theia/latest": "/\($metadir)/devworkspace-che-theia-latest.yaml",
"eclipse/che-theia/next": "/\($metadir)/devworkspace-che-theia-next.yaml"}' "${meta}")" > "${meta}"
fi
done
yq -s 'map(.)' "${metas[@]}"