======= BOOTSTRAP DOCKERFILE =======>
#
# Copyright (c) 2018-2023 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
#
# Contributors:
#   Red Hat, Inc. - initial API and implementation
#   IBM Corporation - implementation
#

# Builder: check meta.yamls and create index.json
# https://registry.access.redhat.com/ubi8/python-38
FROM registry.access.redhat.com/ubi8/python-38:1-125.1682304659 as builder
#FROM registry-proxy.engineering.redhat.com/ubi8/python-38:1 as builder
USER 0

ARG BOOTSTRAP=true
ENV BOOTSTRAP=${BOOTSTRAP}
# if not defined or string is null, allow all registries/tags in list_referenced_images
# otherwise restrict to only those space-separated registries/tags; if others found, build will fail
# useful for failing build if quay images in an RC, or wrong devspaces image tag (3.2 in 3.1 build)
ARG ALLOWED_REGISTRIES=""
ENV ALLOWED_REGISTRIES=${ALLOWED_REGISTRIES}
ARG ALLOWED_TAGS=""
ENV ALLOWED_TAGS=${ALLOWED_TAGS}

COPY ./build/dockerfiles/content_sets_rhel8.repo /etc/yum.repos.d/
COPY ./build/dockerfiles/rhel.install.sh /tmp
RUN /tmp/rhel.install.sh && rm -f /tmp/rhel.install.sh

COPY ./build/scripts ./versions.json /build/
COPY ./build/scripts/clone_and_zip.sh /build/build/scripts/
COPY ./VERSION /
COPY ./devfiles /build/devfiles
WORKDIR /build/

RUN ./generate_devworkspace_templates.sh
RUN chmod -R g+rwX /build/resources

# validate devfile content
RUN ./check_referenced_images.sh devfiles --registries "${ALLOWED_REGISTRIES}" --tags "${ALLOWED_TAGS}"
RUN ./check_mandatory_fields.sh devfiles

# Cache projects in DS 
COPY ./build/dockerfiles/rhel.cache_projects.sh /tmp/ 
RUN /tmp/rhel.cache_projects.sh /build/ && rm -rf /tmp/rhel.cache_projects.sh /tmp/resources.tgz 

# don't do swaps, or we end up with missing content if built on s390x or ppc64le worker
# RUN ./swap_yamlfiles.sh devfiles
# RUN ./swap_images.sh devfiles
RUN ./index.sh > /build/devfiles/index.json && \
    ./list_referenced_images.sh devfiles > /build/devfiles/external_images.txt && \
    ./list_referenced_images_by_file.sh devfiles > /build/devfiles/external_images_by_devfile.txt && \
    chmod -R g+rwX /build/devfiles

<======= BOOTSTRAP DOCKERFILE =======
======= START BOOTSTRAP BUILD =======>
STEP 1/23: FROM registry.access.redhat.com/ubi8/python-38:1-125.1682304659 AS builder
STEP 2/23: USER 0
--> 6f95869bae8
STEP 3/23: ARG BOOTSTRAP=true
--> d290e29c208
STEP 4/23: ENV BOOTSTRAP=${BOOTSTRAP}
--> c8f9cf57fe7
STEP 5/23: ARG ALLOWED_REGISTRIES=""
--> 0022dd1f60d
STEP 6/23: ENV ALLOWED_REGISTRIES=${ALLOWED_REGISTRIES}
--> 19765c0115d
STEP 7/23: ARG ALLOWED_TAGS=""
--> ea18fd31108
STEP 8/23: ENV ALLOWED_TAGS=${ALLOWED_TAGS}
--> 57518bc6fc1
STEP 9/23: COPY ./build/dockerfiles/content_sets_rhel8.repo /etc/yum.repos.d/
--> 0e1c90b2c00
STEP 10/23: COPY ./build/dockerfiles/rhel.install.sh /tmp
--> 1a8a0b9c234
STEP 11/23: RUN /tmp/rhel.install.sh && rm -f /tmp/rhel.install.sh

Installed:
  containers-common-2:1-46.module+el8.7.0+17824+66a0202b.x86_64                 
  criu-3.15-3.module+el8.7.0+17824+66a0202b.x86_64                              
  fuse-common-3.3.0-16.el8.x86_64                                               
  fuse-overlayfs-1.9-1.module+el8.7.0+17824+66a0202b.x86_64                     
  fuse3-3.3.0-16.el8.x86_64                                                     
  fuse3-libs-3.3.0-16.el8.x86_64                                                
  iptables-libs-1.8.4-23.el8_7.1.x86_64                                         
  jansson-2.14-1.el8.x86_64                                                     
  jq-1.6-3.el8.x86_64                                                           
  kmod-25-19.el8.x86_64                                                         
  libibverbs-41.0-1.el8.x86_64                                                  
  libmnl-1.0.4-6.el8.x86_64                                                     
  libnet-1.1.6-15.el8.x86_64                                                    
  libnftnl-1.1.5-5.el8.x86_64                                                   
  libpcap-14:1.9.1-5.el8.x86_64                                                 
  libslirp-4.4.0-1.module+el8.7.0+17824+66a0202b.x86_64                         
  nftables-1:0.9.3-26.el8.x86_64                                                
  oniguruma-6.8.2-2.el8.x86_64                                                  
  protobuf-c-1.3.0-6.el8.x86_64                                                 
  runc-1:1.1.4-1.module+el8.7.0+17824+66a0202b.x86_64                           
  skopeo-2:1.9.4-0.1.module+el8.7.0+17824+66a0202b.x86_64                       
  slirp4netns-1.2.0-2.module+el8.7.0+17824+66a0202b.x86_64                      

Collecting yq
  Downloading https://files.pythonhosted.org/packages/f7/00/144b1dbfcd62c50475b4c6fb09d832ac553e3a0fd969d31bdc608852084b/yq-3.2.2-py3-none-any.whl
Collecting argcomplete
  Downloading https://files.pythonhosted.org/packages/ab/ce/2141e1cabe39c90e01fde7feb44c07867fb49bf1c0c091d68fd8924fd6a2/argcomplete-3.0.8-py3-none-any.whl (40kB)
Collecting PyYAML>=5.3.1
  Downloading https://files.pythonhosted.org/packages/d7/42/7ad4b6d67a16229496d4f6e74201bdbebcf4bc1e87d5a70c9297d4961bd2/PyYAML-6.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (701kB)
Collecting tomlkit>=0.11.6
  Downloading https://files.pythonhosted.org/packages/ef/a8/b1c193be753c02e2a94af6e37ee45d3378a74d44fe778c2434a63af92731/tomlkit-0.11.8-py3-none-any.whl
Collecting xmltodict>=0.11.0
  Downloading https://files.pythonhosted.org/packages/94/db/fd0326e331726f07ff7f40675cd86aa804bfd2e5016c727fa761c934990e/xmltodict-0.13.0-py2.py3-none-any.whl
Installing collected packages: argcomplete, PyYAML, tomlkit, xmltodict, yq
Successfully installed PyYAML-6.0 argcomplete-3.0.8 tomlkit-0.11.8 xmltodict-0.13.0 yq-3.2.2
python: Python 3.8.13
yq: yq 3.2.2
jq: jq-1.6
--> 4e4ca3490c2
STEP 12/23: COPY ./build/scripts ./versions.json /build/
--> 317a10dae2f
STEP 13/23: COPY ./build/scripts/clone_and_zip.sh /build/build/scripts/
--> 3e250ab76ce
STEP 14/23: COPY ./VERSION /
--> 6abdf1f7796
STEP 15/23: COPY ./devfiles /build/devfiles
--> 4730e55859d
STEP 16/23: WORKDIR /build/
--> bc6b5764433
STEP 17/23: RUN ./generate_devworkspace_templates.sh

> core-js@2.6.12 postinstall /build/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

[96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling JavaScript standard library![0m

[96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: [0m
[96m>[94m https://opencollective.com/core-js [0m
[96m>[94m https://www.patreon.com/zloirock [0m

[96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m

+ @eclipse-che/che-devworkspace-generator@0.0.1-c8bd5c0
added 119 packages from 183 contributors and audited 119 packages in 9.998s

5 packages are looking for funding
  run `npm fund` for details

found 2 vulnerabilities (1 moderate, 1 high)
  run `npm audit fix` to fix them, or `npm audit` for details
DevWorkspace che-code-java-lombok was generated.
DevWorkspace che-code-java-lombok was generated.
DevWorkspace che-idea-java-lombok was generated.
DevWorkspace che-code-quarkus-quickstart was generated.
DevWorkspace che-code-quarkus-quickstart was generated.
DevWorkspace che-idea-quarkus-quickstart was generated.
DevWorkspace che-code-nodejs-mongodb was generated.
DevWorkspace che-code-nodejs-mongodb was generated.
DevWorkspace che-idea-nodejs-mongodb was generated.
DevWorkspace che-code-nodejs-web-app was generated.
DevWorkspace che-code-nodejs-web-app was generated.
DevWorkspace che-idea-nodejs-web-app was generated.
DevWorkspace che-code-python-hello-world was generated.
DevWorkspace che-code-python-hello-world was generated.
DevWorkspace che-idea-python-hello-world was generated.
DevWorkspace che-code-cpp was generated.
DevWorkspace che-code-cpp was generated.
DevWorkspace che-idea-cpp was generated.
DevWorkspace che-code-dotnet was generated.
DevWorkspace che-code-dotnet was generated.
DevWorkspace che-idea-dotnet was generated.
DevWorkspace che-code-golang was generated.
DevWorkspace che-code-golang was generated.
DevWorkspace che-idea-golang was generated.
DevWorkspace che-code-php-hello-world was generated.
DevWorkspace che-code-php-hello-world was generated.
DevWorkspace che-idea-php-hello-world was generated.
--> 43d16993e97
STEP 18/23: RUN chmod -R g+rwX /build/resources
--> fb86acd3d6f
STEP 19/23: RUN ./check_referenced_images.sh devfiles --registries "${ALLOWED_REGISTRIES}" --tags "${ALLOWED_TAGS}"
 + registry.redhat.io/devspaces/code-rhel8:3.6 PASS - registry.redhat.io allowed
 + registry.redhat.io/devspaces/idea-rhel8:3.6 PASS - registry.redhat.io allowed
 + registry.redhat.io/devspaces/udi-rhel8:3.6 PASS - registry.redhat.io allowed
 + registry.redhat.io/rhscl/mongodb-36-rhel7:1-50 PASS - registry.redhat.io allowed
 + registry.redhat.io/devspaces/code-rhel8:3.6 PASS - 3.6 allowed
 + registry.redhat.io/devspaces/idea-rhel8:3.6 PASS - 3.6 allowed
 + registry.redhat.io/devspaces/udi-rhel8:3.6 PASS - 3.6 allowed
 = registry.redhat.io/rhscl/mongodb-36-rhel7:1-50 PASS
--> 836c72938ed
STEP 20/23: RUN ./check_mandatory_fields.sh devfiles
Checking devfile 'devfiles/TP__cpp__c-plus-plus/meta.yaml'
Checking devfile 'devfiles/TP__dotnet__dotnet-web-simple/meta.yaml'
Checking devfile 'devfiles/TP__go__golang-health-check/meta.yaml'
Checking devfile 'devfiles/TP__php__php-hello-world/meta.yaml'
Checking devfile 'devfiles/java11-maven-lombok__lombok-project-sample/meta.yaml'
Checking devfile 'devfiles/java11-maven-quarkus__quarkus-quickstarts/meta.yaml'
Checking devfile 'devfiles/nodejs__nodejs-mongodb-sample/meta.yaml'
Checking devfile 'devfiles/nodejs__web-nodejs-sample/meta.yaml'
Checking devfile 'devfiles/python__python-hello-world/meta.yaml'
--> 3ae3b503ec3
STEP 21/23: COPY ./build/dockerfiles/rhel.cache_projects.sh /tmp/ 
--> e3697de14f6
STEP 22/23: RUN /tmp/rhel.cache_projects.sh /build/ && rm -rf /tmp/rhel.cache_projects.sh /tmp/resources.tgz 
--> 28073cfe831
STEP 23/23: RUN ./index.sh > /build/devfiles/index.json &&     ./list_referenced_images.sh devfiles > /build/devfiles/external_images.txt &&     ./list_referenced_images_by_file.sh devfiles > /build/devfiles/external_images_by_devfile.txt &&     chmod -R g+rwX /build/devfiles
COMMIT devfileregistry:tmp
--> 50106d9cfba
Successfully tagged localhost/devfileregistry:tmp
50106d9cfba12cb77356d1973802479ae00f45f0f25f4e460d57fbce0c19e750
<======= END BOOTSTRAP BUILD =======
Not downloading unused root-local.tgz
Not downloading unused resources.tgz
DIFF START *****
No such file root-local.tgz -- could not fetch from 'rhpkg sources'
***** END DIFF
DIFF START *****
No such file resources.tgz -- could not fetch from 'rhpkg sources'
***** END DIFF
Untagged: localhost/devfileregistry:tmp
Deleted: 50106d9cfba12cb77356d1973802479ae00f45f0f25f4e460d57fbce0c19e750
Deleted: 28073cfe831a792616208094bafe99e1e32f9f3ca4f59444fef250f6c3362fcf
Deleted: e3697de14f63a8e2d6382c29c78612950c6e022e15b3cd3890cfea6e922d9b93
Deleted: 3ae3b503ec3a3db49adb6deb78a946148cf69165ed4da2f0d253cb510347e2b9
Deleted: 836c72938ed597d1de0959f4d0b21efb540bc8c82a0cad4bb0d7620bec6b078f
Deleted: fb86acd3d6fa5d7b1111f5b21e145da8db3bce1efad275e5d780cf07cae46632
Deleted: 43d16993e977484ef1a1d1a041d9cde76d44796a555160e2d3e9d1123a4d5362
Deleted: bc6b5764433dfdbe58eff5b0ebd111ec614a0bda3461d0904aad219504784a03
Deleted: 4730e55859d7c761d459e283e40e5c27580455ae177bae8b153b519c158dad55
Deleted: 6abdf1f77969edd22e5e8ee89201ddc5245bd3bbfe4ea73c47e512ff5eb1831b
Deleted: 3e250ab76cef7eebf6c6694649b23433a844ca053cae188c4697e8729a10c6ae
Deleted: 317a10dae2f4e2dff970a0f76d070374edc6eb6a20b39581b323c3619d080379
Deleted: 4e4ca3490c29bc16de339e19cdf35efcc214cf8490b9ef63252b291e4bc65587
Deleted: 1a8a0b9c23444c75cff20ffd9c128107165e91dd03402f2017072a15898f2275
Deleted: 0e1c90b2c009d3093d2009458002dd545197823bff9328ea6091e977cf2bab0e
Deleted: 57518bc6fc1d7c9e2ff6d5cc0fe5b4fedd3ea1852a7780cbf9451d7d05529757
Deleted: ea18fd31108d78a918e99e006aae481144392fde8eaa7a5032fea036335ded7b
Deleted: 19765c0115ddf944aa85c438b3c566a01d3203c36b32fca421fc585f39d70dbc
Deleted: 0022dd1f60dea7659053aa8181e3bd84ed3643cea2a54dcfdb877e5bba874881
Deleted: c8f9cf57fe757fb265c3c93214a27714531e3c97fa61ac2ea37ec50823afba9d
Deleted: d290e29c20814a7e5f95cb204ae9c937397259d1d7b9c355c5fd86dfbeb5a595
Deleted: 6f95869bae8c813d07cb95f79b1b1d9000cd41101a440f5a2462cb74f32ccd09
Uploading: root-local.tgz
Uploading: resources.tgz
Source upload succeeded. Don't forget to commit the sources file
rm 'resources.tgz'
rm 'root-local.tgz'
