======= 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-131 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-131 AS builder
STEP 2/23: USER 0
--> 9f4d80d395a8
STEP 3/23: ARG BOOTSTRAP=true
--> f32d954bbee1
STEP 4/23: ENV BOOTSTRAP=${BOOTSTRAP}
--> b753e1678f82
STEP 5/23: ARG ALLOWED_REGISTRIES=""
--> 9edc105f3bcf
STEP 6/23: ENV ALLOWED_REGISTRIES=${ALLOWED_REGISTRIES}
--> b178fe94ca9b
STEP 7/23: ARG ALLOWED_TAGS=""
--> 2b8ec9b9edf6
STEP 8/23: ENV ALLOWED_TAGS=${ALLOWED_TAGS}
--> 097a5d31bd92
STEP 9/23: COPY ./build/dockerfiles/content_sets_rhel8.repo /etc/yum.repos.d/
--> ad137938fb4d
STEP 10/23: COPY ./build/dockerfiles/rhel.install.sh /tmp
--> 6794a1864d11
STEP 11/23: RUN /tmp/rhel.install.sh && rm -f /tmp/rhel.install.sh

Upgraded:
  dnf-4.7.0-19.el8.noarch                dnf-data-4.7.0-19.el8.noarch          
  findutils-1:4.6.0-21.el8.x86_64        python3-dnf-4.7.0-19.el8.noarch       
  yum-4.7.0-19.el8.noarch               
Installed:
  containers-common-2:1-70.module+el8.9.0+20326+387084d0.x86_64                 
  criu-3.18-4.module+el8.9.0+20326+387084d0.x86_64                              
  fuse-common-3.3.0-17.el8.x86_64                                               
  fuse-overlayfs-1.12-1.module+el8.9.0+20326+387084d0.x86_64                    
  fuse3-3.3.0-17.el8.x86_64                                                     
  fuse3-libs-3.3.0-17.el8.x86_64                                                
  jq-1.6-7.el8.x86_64                                                           
  kmod-25-19.el8.x86_64                                                         
  libnet-1.1.6-15.el8.x86_64                                                    
  libslirp-4.4.0-1.module+el8.9.0+20326+387084d0.x86_64                         
  mpdecimal-2.5.1-3.el8.x86_64                                                  
  oniguruma-6.8.2-2.el8.x86_64                                                  
  protobuf-c-1.3.0-8.el8.x86_64                                                 
  python3.11-3.11.5-1.el8_9.x86_64                                              
  python3.11-devel-3.11.5-1.el8_9.x86_64                                        
  python3.11-libs-3.11.5-1.el8_9.x86_64                                         
  python3.11-pip-22.3.1-4.el8.noarch                                            
  python3.11-pip-wheel-22.3.1-4.el8.noarch                                      
  python3.11-setuptools-65.5.1-2.el8.noarch                                     
  python3.11-setuptools-wheel-65.5.1-2.el8.noarch                               
  runc-1:1.1.9-1.module+el8.9.0+20326+387084d0.x86_64                           
  skopeo-2:1.13.3-1.module+el8.9.0+20326+387084d0.x86_64                        
  slirp4netns-1.2.1-1.module+el8.9.0+20326+387084d0.x86_64                      

Collecting yq
  Downloading yq-3.2.3-py3-none-any.whl (17 kB)
Collecting argcomplete
  Downloading argcomplete-3.2.1-py3-none-any.whl (42 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.3/42.3 kB 2.6 MB/s eta 0:00:00
Requirement already satisfied: pip in /usr/lib/python3.11/site-packages (22.3.1)
Collecting pip
  Downloading pip-23.3.2-py3-none-any.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 31.9 MB/s eta 0:00:00
Collecting PyYAML>=5.3.1
  Downloading PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (757 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 757.7/757.7 kB 502.1 MB/s eta 0:00:00
Collecting xmltodict>=0.11.0
  Downloading xmltodict-0.13.0-py2.py3-none-any.whl (10.0 kB)
Collecting tomlkit>=0.11.6
  Downloading tomlkit-0.12.3-py3-none-any.whl (37 kB)
Installing collected packages: xmltodict, tomlkit, PyYAML, pip, argcomplete, yq
Successfully installed PyYAML-6.0.1 argcomplete-3.2.1 pip-23.3.2 tomlkit-0.12.3 xmltodict-0.13.0 yq-3.2.3
python: Python 3.8.16
yq: yq 3.2.3
jq: jq-1.6
--> e897759fb8c0
STEP 12/23: COPY ./build/scripts ./versions.json /build/
--> 2bcbfdb457c4
STEP 13/23: COPY ./build/scripts/clone_and_zip.sh /build/build/scripts/
--> 608722a5d456
STEP 14/23: COPY ./VERSION /
--> 69764d100286
STEP 15/23: COPY ./devfiles /build/devfiles
--> 6bcca6f046b8
STEP 16/23: WORKDIR /build/
--> e4ef0a38841a
STEP 17/23: RUN ./generate_devworkspace_templates.sh
+ @eclipse-che/che-devworkspace-generator@0.0.1-99986b8
added 31 packages from 84 contributors and audited 31 packages in 4.583s

1 package is looking for funding
  run `npm fund` for details

found 1 moderate severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details
DevWorkspace che-code-ansible-demo was generated.
DevWorkspace che-code-ansible-demo was generated.
DevWorkspace che-idea-ansible-demo was generated.
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.
--> 4e896837ae31
STEP 18/23: RUN chmod -R g+rwX /build/resources
--> 99cd158f3513
STEP 19/23: RUN ./check_referenced_images.sh devfiles --registries "${ALLOWED_REGISTRIES}" --tags "${ALLOWED_TAGS}"
 = quay.io/devspaces/ansible-creator-ee@sha256:a5c5f3c1e7e594e00d53e039689d9e2f781ad3f229187458e710ca11898a77ed PASS
 + registry.redhat.io/devspaces/code-rhel8:3.11 PASS - registry.redhat.io allowed
 + registry.redhat.io/devspaces/idea-rhel8:3.11 PASS - registry.redhat.io allowed
 + registry.redhat.io/devspaces/udi-rhel8:3.11 PASS - registry.redhat.io allowed
 + registry.redhat.io/rhscl/mongodb-36-rhel7:1-50 PASS - registry.redhat.io allowed
 = quay.io/devspaces/ansible-creator-ee@sha256:a5c5f3c1e7e594e00d53e039689d9e2f781ad3f229187458e710ca11898a77ed PASS
 + registry.redhat.io/devspaces/code-rhel8:3.11 PASS - 3.11 allowed
 + registry.redhat.io/devspaces/idea-rhel8:3.11 PASS - 3.11 allowed
 + registry.redhat.io/devspaces/udi-rhel8:3.11 PASS - 3.11 allowed
 = registry.redhat.io/rhscl/mongodb-36-rhel7:1-50 PASS
--> 080b075ad1a9
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/ansible__ansible-demo/meta.yaml'
Checking devfile 'devfiles/java-maven-lombok__lombok-project-sample/meta.yaml'
Checking devfile 'devfiles/java-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'
--> 87f0184679e1
STEP 21/23: COPY ./build/dockerfiles/rhel.cache_projects.sh /tmp/ 
--> 971447101c2a
STEP 22/23: RUN /tmp/rhel.cache_projects.sh /build/ && rm -rf /tmp/rhel.cache_projects.sh /tmp/resources.tgz 
--> ab96694bb22e
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
--> cc408aa90423
Successfully tagged localhost/devfileregistry:tmp
cc408aa90423951c7a14aa8dccac61f71efb0ff2cf977fb8fb6da9ad6b695b17
<======= END BOOTSTRAP BUILD =======
Downloading root-local.tgz
Downloading resources.tgz
Untagged: localhost/devfileregistry:tmp
Deleted: cc408aa90423951c7a14aa8dccac61f71efb0ff2cf977fb8fb6da9ad6b695b17
Deleted: ab96694bb22ef3b5d1003c5c3aacc8cf30a7f3ea4a31f82986194c79a532ce5d
Deleted: 971447101c2a7c88a53203b9caa0ec06fa36316f21badc5f0190cee8c1698ca3
Deleted: 87f0184679e1f149f87624dc4ff5e1f03c21957340b631e9486e2ee93a53bb2a
Deleted: 080b075ad1a95a6a437e745df488743e79097a4a4a8ba0a4a3fbff15a773f310
Deleted: 99cd158f3513fabe0f02d5a4f5e90e436dc66ea651b663f789c0ae3939eb7dcd
Deleted: 4e896837ae31e18192c3802fe139b5a2eb3e259cb9411250268d00a07bcfd4fc
Deleted: e4ef0a38841a027bda767d2aa1e9be557ef4928fd4042568bf56dee7f804bcc0
Deleted: 6bcca6f046b8124c7362627d196c5eab8a7ed1ba263040bf27a6b67a43a4be66
Deleted: 69764d1002860e9ed6778e11cd2da8cc3cc3661c9e686a6857498f23d65f073f
Deleted: 608722a5d4564e0c63aaca915f6693f633926ef868e6e7dfda618cf8eb6d094e
Deleted: 2bcbfdb457c45c09b582d563c46943c880819017d94a99f3fd935926b969db15
Deleted: e897759fb8c011eb711dcd34e82c7477d0f0ea621430f26f333c2c7f85268b1c
Deleted: 6794a1864d11bb23375853d3b84550dd766212360414905f952710679333a6dc
Deleted: ad137938fb4d2029b79d639481b222789d72b52500a2c3e2d1ee5a1b4b4e7406
Deleted: 097a5d31bd9218af7efc092512056627101849f59c95206d362337054d487fee
Deleted: 2b8ec9b9edf6fb8b9775a1f9030c81c49f5458270b284159617586e96a319137
Deleted: b178fe94ca9b6456c732daf2367aa420824070e56ac481c824e2252bf4952886
Deleted: 9edc105f3bcf7f16e47240e50a45615c4dcf7bd0a944caae97c2f77261834514
Deleted: b753e1678f82a2e50292138d8ce607879d9b24de909e607c46308ecc5275d46f
Deleted: f32d954bbee1f4d785c5c1bf305150c9bb87fdb44d13519032cdcdddcb98da1f
Deleted: 9f4d80d395a8c7e7153af6f865ea6b878ac37e967c5dafe187aaf1f3b2a1bc3b
File already uploaded: root-local.tgz
File already uploaded: resources.tgz
All sources were already uploaded.
rm 'resources.tgz'
rm 'root-local.tgz'
