======= 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
--> 598c5304a196
STEP 3/23: ARG BOOTSTRAP=true
--> bc8a27bf5dc6
STEP 4/23: ENV BOOTSTRAP=${BOOTSTRAP}
--> cc36079db3aa
STEP 5/23: ARG ALLOWED_REGISTRIES=""
--> a933a6ea3e82
STEP 6/23: ENV ALLOWED_REGISTRIES=${ALLOWED_REGISTRIES}
--> ae9f59236624
STEP 7/23: ARG ALLOWED_TAGS=""
--> 174b8a897085
STEP 8/23: ENV ALLOWED_TAGS=${ALLOWED_TAGS}
--> 390a954d18cf
STEP 9/23: COPY ./build/dockerfiles/content_sets_rhel8.repo /etc/yum.repos.d/
--> c67881501d16
STEP 10/23: COPY ./build/dockerfiles/rhel.install.sh /tmp
--> 7d447149c71f
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         
  wget-1.19.5-12.el8_10.x86_64         yum-4.7.0-20.el8.noarch                 
Installed:
  containers-common-2:1-82.module+el8.10.0+22202+761b9a65.x86_64                
  criu-3.18-5.module+el8.10.0+22202+761b9a65.x86_64                             
  fuse-common-3.3.0-19.el8.x86_64                                               
  fuse-overlayfs-1.13-1.module+el8.10.0+22202+761b9a65.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+22202+761b9a65.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-3.el8_10.noarch                                  
  python3.11-setuptools-wheel-65.5.1-3.el8_10.noarch                            
  runc-1:1.1.12-4.module+el8.10.0+22202+761b9a65.x86_64                         
  skopeo-2:1.14.5-3.module+el8.10.0+22202+761b9a65.x86_64                       
  slirp4netns-1.2.3-1.module+el8.10.0+22202+761b9a65.x86_64                     

Collecting yq
  Downloading yq-3.4.3-py3-none-any.whl (18 kB)
Collecting argcomplete
  Downloading argcomplete-3.5.0-py3-none-any.whl (43 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 43.5/43.5 kB 3.0 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.2-py3-none-any.whl (1.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 32.1 MB/s eta 0:00:00
Collecting PyYAML>=5.3.1
  Downloading PyYAML-6.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (762 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 763.0/763.0 kB 523.2 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.13.2-py3-none-any.whl (37 kB)
Installing collected packages: xmltodict, tomlkit, PyYAML, pip, argcomplete, yq
Successfully installed PyYAML-6.0.2 argcomplete-3.5.0 pip-24.2 tomlkit-0.13.2 xmltodict-0.13.0 yq-3.4.3
python: Python 3.8.16
yq: yq 3.4.3
jq: jq-1.6
--> b4c9134d6488
STEP 12/23: COPY ./build/scripts ./versions.json /build/
--> a8d04d197cdc
STEP 13/23: COPY ./build/scripts/clone_and_zip.sh /build/build/scripts/
--> 39d8828a9af7
STEP 14/23: COPY ./VERSION /
--> 055ab48eb274
STEP 15/23: COPY ./devfiles /build/devfiles
--> e4d1a2f24e38
STEP 16/23: WORKDIR /build/
--> 5ff64665306c
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 5.759s

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.
--> fb141d92ba43
STEP 18/23: RUN chmod -R g+rwX /build/resources
--> cae28b9f75b3
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.16 PASS - registry.redhat.io allowed
 + registry.redhat.io/devspaces/idea-rhel8:3.16 PASS - registry.redhat.io allowed
 + registry.redhat.io/devspaces/udi-rhel8:3.16 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.16 PASS - 3.16 allowed
 + registry.redhat.io/devspaces/idea-rhel8:3.16 PASS - 3.16 allowed
 + registry.redhat.io/devspaces/udi-rhel8:3.16 PASS - 3.16 allowed
 = registry.redhat.io/rhscl/mongodb-36-rhel7:1-50 PASS
--> f867dccbab29
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'
--> b89d84047711
STEP 21/23: COPY ./build/dockerfiles/rhel.cache_projects.sh /tmp/ 
--> 386e17b22ec0
STEP 22/23: RUN /tmp/rhel.cache_projects.sh /build/ && rm -rf /tmp/rhel.cache_projects.sh /tmp/resources.tgz 
--> b55d8701250c
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
--> d1ebece69b2c
Successfully tagged localhost/devfileregistry:tmp
d1ebece69b2c9a7ae49f93585df39fcebdc1b4f3d25e6fa2823b4486dfce7449
<======= END BOOTSTRAP BUILD =======
Downloading root-local.tgz from https://pkgs.devel.redhat.com/repo/
Downloading resources.tgz from https://pkgs.devel.redhat.com/repo/
Untagged: localhost/devfileregistry:tmp
Deleted: d1ebece69b2c9a7ae49f93585df39fcebdc1b4f3d25e6fa2823b4486dfce7449
Deleted: b55d8701250cfcd529760658b5382ed2a9a0950f169fd30aa10f4e3964913e18
Deleted: 386e17b22ec0a603d03ab7db8525590dec191c9b0fb233bcf345bb5029c11d8c
Deleted: b89d8404771168dbdb4b031316fd019458ddcc5280ae31cc2646952f8566dff9
Deleted: f867dccbab2907253b974166624504dec1b402984039c82d92cfcf1cbf561507
Deleted: cae28b9f75b3c7c60b1e6b1550d7242cc2f5a1bf723c53e9b41a7a648cc4fa1f
Deleted: fb141d92ba43d958e26989a8eecfc5bc0dc668f5517b3d22215cdcf7a9a3fb00
Deleted: 5ff64665306c27327a15f2ea957dbee6a85f90ea7f043fcb5bebc52681f15595
Deleted: e4d1a2f24e3893adeefd42f646f2487a12cac4835f965a8d771c37b965cf4b52
Deleted: 055ab48eb27426c4962a82db4c65849ea7cddf36a6fa20b4c6c00bfb46cb1733
Deleted: 39d8828a9af7f8c0e285485ae04cc4eff5b27b9e9e66a5e5bef61ee484032e6a
Deleted: a8d04d197cdc76ce5e5ee1fb70ac4d7f63c8a354b701ca27ff19e7e245fce03a
Deleted: b4c9134d6488e1cba93f6e1891080195e14b991d9414a9d4128967e51449b788
Deleted: 7d447149c71fa49f44a4f3f9d9fc05e5c81d1d1095f3bb8db59368c0658f2bb7
Deleted: c67881501d1615b3c9ed5fee792fa3532a4f510bf3891e33da3db5247b46bb83
Deleted: 390a954d18cfe127798c9efef991a80dc258cfce29f9887631069c6259274e19
Deleted: 174b8a897085bd43a4e610fab69e86657f5baf4320faa8712ddeaa905d15a1e5
Deleted: ae9f592366245eea9bf5fc7b8a45b2d51753c0f4d0b73a3ace512d51200c790f
Deleted: a933a6ea3e828ae2febf1083d0d9517cb0962aad8b6b7e0b55dcdf06239bce9f
Deleted: cc36079db3aa4ab0b75e09f5112db6ae8327ea67f166ffd7f76aac91d21c2690
Deleted: bc8a27bf5dc648cca863806bf5eb5fd2551215d1d5b028089863dc5c8662c8d9
Deleted: 598c5304a19680ad114d0ed210c968ddda2e83786c266047da06d07680237a4f
Uploading: root-local.tgz to https://pkgs.devel.redhat.com/lookaside/upload.cgi
File already uploaded: root-local.tgz
Uploading: resources.tgz to https://pkgs.devel.redhat.com/lookaside/upload.cgi
File already uploaded: resources.tgz
All sources were already uploaded.
rm 'resources.tgz'
rm 'root-local.tgz'
