======= 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
--> 21538c9bf753
STEP 3/23: ARG BOOTSTRAP=true
--> 68187f485203
STEP 4/23: ENV BOOTSTRAP=${BOOTSTRAP}
--> 0465d715db2b
STEP 5/23: ARG ALLOWED_REGISTRIES=""
--> 190fff2d0144
STEP 6/23: ENV ALLOWED_REGISTRIES=${ALLOWED_REGISTRIES}
--> e72924a369c3
STEP 7/23: ARG ALLOWED_TAGS=""
--> da860f477426
STEP 8/23: ENV ALLOWED_TAGS=${ALLOWED_TAGS}
--> dd216a723869
STEP 9/23: COPY ./build/dockerfiles/content_sets_rhel8.repo /etc/yum.repos.d/
--> a30b15d233ca
STEP 10/23: COPY ./build/dockerfiles/rhel.install.sh /tmp
--> 577d554b2830
STEP 11/23: RUN /tmp/rhel.install.sh && rm -f /tmp/rhel.install.sh

Upgraded:
  bash-4.4.20-5.el8.x86_64             chkconfig-1.19.2-1.el8.x86_64           
  dnf-4.7.0-20.el8.noarch              dnf-data-4.7.0-20.el8.noarch            
  findutils-1:4.6.0-22.el8.x86_64      git-2.43.5-1.el8_10.x86_64              
  git-core-2.43.5-1.el8_10.x86_64      git-core-doc-2.43.5-1.el8_10.noarch     
  perl-Git-2.43.5-1.el8_10.noarch      python3-dnf-4.7.0-20.el8.noarch         
  yum-4.7.0-20.el8.noarch             
Installed:
  containers-common-2:1-81.module+el8.10.0+21962+8143777b.x86_64                
  criu-3.18-5.module+el8.10.0+21962+8143777b.x86_64                             
  fuse-common-3.3.0-19.el8.x86_64                                               
  fuse-overlayfs-1.13-1.module+el8.10.0+21962+8143777b.x86_64                   
  fuse3-3.3.0-19.el8.x86_64                                                     
  fuse3-libs-3.3.0-19.el8.x86_64                                                
  jq-1.6-9.el8_10.x86_64                                                        
  kmod-25-20.el8.x86_64                                                         
  libnet-1.1.6-15.el8.x86_64                                                    
  libslirp-4.4.0-2.module+el8.10.0+21962+8143777b.x86_64                        
  mpdecimal-2.5.1-3.el8.x86_64                                                  
  oniguruma-6.8.2-3.el8.x86_64                                                  
  protobuf-c-1.3.0-8.el8.x86_64                                                 
  python3.11-3.11.9-2.el8_10.x86_64                                             
  python3.11-devel-3.11.9-2.el8_10.x86_64                                       
  python3.11-libs-3.11.9-2.el8_10.x86_64                                        
  python3.11-pip-22.3.1-5.el8.noarch                                            
  python3.11-pip-wheel-22.3.1-5.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.12-1.module+el8.10.0+21974+acd2159c.x86_64                         
  skopeo-2:1.14.4-1.module+el8.10.0+21995+81e8507c.x86_64                       
  slirp4netns-1.2.3-1.module+el8.10.0+21962+8143777b.x86_64                     

Collecting yq
  Downloading yq-3.4.3-py3-none-any.whl (18 kB)
Collecting argcomplete
  Downloading argcomplete-3.4.0-py3-none-any.whl (42 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.6/42.6 kB 5.5 MB/s eta 0:00:00
Requirement already satisfied: pip in /usr/lib/python3.11/site-packages (22.3.1)
Collecting pip
  Downloading pip-24.1.1-py3-none-any.whl (1.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 55.2 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 413.3 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.5-py3-none-any.whl (37 kB)
Installing collected packages: xmltodict, tomlkit, PyYAML, pip, argcomplete, yq
Successfully installed PyYAML-6.0.1 argcomplete-3.4.0 pip-24.1.1 tomlkit-0.12.5 xmltodict-0.13.0 yq-3.4.3
python: Python 3.8.16
yq: yq 3.4.3
jq: jq-1.6
--> eb706babd061
STEP 12/23: COPY ./build/scripts ./versions.json /build/
--> ebacf733ee1f
STEP 13/23: COPY ./build/scripts/clone_and_zip.sh /build/build/scripts/
--> f275eac70497
STEP 14/23: COPY ./VERSION /
--> 3577dc3b55e7
STEP 15/23: COPY ./devfiles /build/devfiles
--> c5e782397ac8
STEP 16/23: WORKDIR /build/
--> 4630f71912bf
STEP 17/23: RUN ./generate_devworkspace_templates.sh
+ @eclipse-che/che-devworkspace-generator@0.0.1-99986b8
added 31 packages from 83 contributors and audited 31 packages in 4.365s

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-idea-ansible-demo 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-idea-quarkus-quickstart 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-idea-nodejs-web-app 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-idea-cpp was generated.
DevWorkspace che-code-dotnet was generated.
DevWorkspace che-idea-dotnet was generated.
DevWorkspace che-code-golang was generated.
DevWorkspace che-idea-golang was generated.
DevWorkspace che-code-php-hello-world was generated.
DevWorkspace che-idea-php-hello-world was generated.
--> 31501510d668
STEP 18/23: RUN chmod -R g+rwX /build/resources
--> 388ccbd04f36
STEP 19/23: RUN ./check_referenced_images.sh devfiles --registries "${ALLOWED_REGISTRIES}" --tags "${ALLOWED_TAGS}"
 = ghcr.io/ansible/ansible-workspace-env-reference@sha256:03d7f0fe6caaae62ff2266906b63d67ebd9cf6e4a056c7c0a0c1320e6cfbebce PASS
 + registry.redhat.io/devspaces/code-rhel8:3.15 PASS - registry.redhat.io allowed
 + registry.redhat.io/devspaces/idea-rhel8:3.15 PASS - registry.redhat.io allowed
 + registry.redhat.io/devspaces/udi-rhel8:3.15 PASS - registry.redhat.io allowed
 + registry.redhat.io/rhscl/mongodb-36-rhel7:1-50 PASS - registry.redhat.io allowed
 = ghcr.io/ansible/ansible-workspace-env-reference@sha256:03d7f0fe6caaae62ff2266906b63d67ebd9cf6e4a056c7c0a0c1320e6cfbebce PASS
 + registry.redhat.io/devspaces/code-rhel8:3.15 PASS - 3.15 allowed
 + registry.redhat.io/devspaces/idea-rhel8:3.15 PASS - 3.15 allowed
 + registry.redhat.io/devspaces/udi-rhel8:3.15 PASS - 3.15 allowed
 = registry.redhat.io/rhscl/mongodb-36-rhel7:1-50 PASS
--> 6903393a7fa1
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'
--> 39c5b111e07f
STEP 21/23: COPY ./build/dockerfiles/rhel.cache_projects.sh /tmp/ 
--> 5a9fd9ca0ffe
STEP 22/23: RUN /tmp/rhel.cache_projects.sh /build/ && rm -rf /tmp/rhel.cache_projects.sh /tmp/resources.tgz 
--> 9600602699d5
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
--> 301603f10cb5
Successfully tagged localhost/devfileregistry:tmp
301603f10cb51059c699add733d7aec830e69669507d04ba47555810a3435bd8
<======= END BOOTSTRAP BUILD =======
Downloading root-local.tgz
Downloading resources.tgz
Untagged: localhost/devfileregistry:tmp
Deleted: 301603f10cb51059c699add733d7aec830e69669507d04ba47555810a3435bd8
Deleted: 9600602699d5f5e6e6b78c5eabdb276f399fb3d2e883aaf811fd9eb622aabfdf
Deleted: 5a9fd9ca0ffeeadd009c04e5c2ca527625b4d9bfdf24944fe411922e6de41679
Deleted: 39c5b111e07f205ae41f0476f20569227474c88e27b6ed399a64477e8a7bb5d4
Deleted: 6903393a7fa1ab07f02afa2bf374fed93293dd42e938c77a137ff8f25cf44e10
Deleted: 388ccbd04f363e2db6c4d027e524309d24ad2e84d2bb637d07a72aed22dba793
Deleted: 31501510d6683821f59aaff03cbf1e0aad4275ab65cec0bf063c6d53c7866319
Deleted: 4630f71912bf16ca70022424241c0560830a94be5ce76a17c0fac1d9625f61bc
Deleted: c5e782397ac88f8f900f4eff7d21ebcc777a04acb629193132eaeed604e51328
Deleted: 3577dc3b55e7ded9b2dd96476122ea0a0b313696317210cad9cd9d31c98f36f5
Deleted: f275eac7049732ce5e0a1c816f6dd966fa4c2afc1722e5d56227064660f40185
Deleted: ebacf733ee1f7664d7fcf865b37d43235c9eaa3faf73938873ac2660c866deae
Deleted: eb706babd06123e316210b6b4f17131bc0f3bf3a4f547dac596bb2630e587752
Deleted: 577d554b28308aec62981231d2c18d53708a1001819e45b34824915950b4ca30
Deleted: a30b15d233ca9e9f170dd564cddbe67062686b123f1c2288a8b9c6fbccd3fcf5
Deleted: dd216a72386958e112952a02afd172b231056a4f49bad508b63997e50d05c410
Deleted: da860f477426cf0d42614d9b151ae7219e3a5f5ba8d54ed3a1d50504a5fb463c
Deleted: e72924a369c32d92df6e2c3832da4e1282dc851c2cdb8e78abdafb34a2e5b802
Deleted: 190fff2d014460f5023f92c796e86e24580b02232780a76c937355fd924edf3f
Deleted: 0465d715db2b6397e6dbd63f4f6f519af0b90a281c155f091ec5c01df5d19aa7
Deleted: 68187f4852039c864eeaf1f3f021b9394cd580fa267d10debd1ba9c1663e2ac3
Deleted: 21538c9bf75330f7e13879ee02d0b09b6a34c4b8c56676ebd297c3cabe7f3cd3
File already uploaded: root-local.tgz
File already uploaded: resources.tgz
All sources were already uploaded.
rm 'resources.tgz'
rm 'root-local.tgz'
