|
| 1 | +# Copyright (c) 2023 Oracle and/or its affiliates. |
| 2 | +# |
| 3 | +# The Universal Permissive License (UPL), Version 1.0 |
| 4 | +# |
| 5 | +# Subject to the condition set forth below, permission is hereby granted to any |
| 6 | +# person obtaining a copy of this software, associated documentation and/or data |
| 7 | +# (collectively the "Software"), free of charge and under any and all copyright |
| 8 | +# rights in the Software, and any and all patent rights owned or freely |
| 9 | +# licensable by each licensor hereunder covering either (i) the unmodified |
| 10 | +# Software as contributed to or provided by such licensor, or (ii) the Larger |
| 11 | +# Works (as defined below), to deal in both |
| 12 | +# |
| 13 | +# (a) the Software, and |
| 14 | +# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if |
| 15 | +# one is included with the Software (each a "Larger Work" to which the Software |
| 16 | +# is contributed by such licensors), |
| 17 | +# without restriction, including without limitation the rights to copy, create |
| 18 | +# derivative works of, display, perform, and distribute the Software and make, |
| 19 | +# use, sell, offer for sale, import, export, have made, and have sold the |
| 20 | +# Software and the Larger Work(s), and to sublicense the foregoing rights on |
| 21 | +# either these or other terms. |
| 22 | +# |
| 23 | +# This license is subject to the following condition: |
| 24 | +# The above copyright notice and either this complete permission notice or at |
| 25 | +# a minimum a reference to the UPL must be included in all copies or |
| 26 | +# substantial portions of the Software. |
| 27 | +# |
| 28 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 29 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 30 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 31 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 32 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 33 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 34 | +# SOFTWARE. |
| 35 | +version: 0.1 |
| 36 | +component: build |
| 37 | +timeoutInSeconds: 6000 |
| 38 | +runAs: root |
| 39 | +shell: bash |
| 40 | + |
| 41 | +env: |
| 42 | + # these are local variables to the build config, we need to declare them here so thet will follow on in subsequent build stages |
| 43 | + # Note that PATH seems to be automatically added to the list of variables who's value is preserved across commands |
| 44 | + variables: |
| 45 | + # Software versions to install, this will work, but relies on the |
| 46 | + # download sources of the software retaining the same URL formats |
| 47 | + GRAALVM_JAVA_VERSION: "17" |
| 48 | + MVN_VERSION: "3.9.3" |
| 49 | + # some times the actuall code isn't in the root of the git repo |
| 50 | + # set this to any sub path or to . if you do want to build in the root of the repo |
| 51 | + PROJECT_PATH_TO_BUILD: "getting-started" |
| 52 | + # where any downloaded software used by the build will be installed, |
| 53 | + # unless you have a specific need there is no benefit to changing this |
| 54 | + SW_PATH: "installedsw" |
| 55 | + # Settings needed for the docker container |
| 56 | + DOCKER_BASE_IMAGE: "oraclelinux:8" |
| 57 | + # where in the resulting docker container the application will be placed |
| 58 | + # this path will be created is needed |
| 59 | + DOCKER_APPLICATION_DIR: "/application" |
| 60 | + # the following are determined during the various processing stages |
| 61 | + # and used to pass usefull around between the stages |
| 62 | + # You don't need to set them |
| 63 | + GRAALVM_HOME: "Not yet set" |
| 64 | + JAVA_HOME: "Not yet set" |
| 65 | + WORKING_PATH: "Not yet set" |
| 66 | + EXTRACTED_ARTIFACT_ID: "Not set" |
| 67 | + EXTRACTED_VERSION: "Not set" |
| 68 | + MVN_HOME: "Not yet set" |
| 69 | + APPLICATION_COMPILED_PATH: "Not yet set" |
| 70 | + APPLICATION_COMPILED_NAME: "Not yet set" |
| 71 | + |
| 72 | + exportedVariables: |
| 73 | + - EXTRACTED_ARTIFACT_ID |
| 74 | + - EXTRACTED_VERSION |
| 75 | + |
| 76 | +steps: |
| 77 | + - type: Command |
| 78 | + name: "Check local environment before starting work" |
| 79 | + command: | |
| 80 | + echo "Current working directory is "`pwd` |
| 81 | + echo "It's contents are " |
| 82 | + ls -l . |
| 83 | + echo "Source is in ${OCI_PRIMARY_SOURCE_DIR} it's contents are" |
| 84 | + cd ${OCI_PRIMARY_SOURCE_DIR} |
| 85 | + ls -l . |
| 86 | + export WORKING_PATH="/${OCI_PRIMARY_SOURCE_DIR}/${PROJECT_PATH_TO_BUILD}" |
| 87 | + echo "Project working path is ${WORKING_PATH}" |
| 88 | + cd ${WORKING_PATH} |
| 89 | + echo "Top level contents of working path via cwd " |
| 90 | + ls -l . |
| 91 | + - type: Command |
| 92 | + name: "Setup for software install" |
| 93 | + command: | |
| 94 | + echo "Configuring home directory for the upcomming sw installs" |
| 95 | + mkdir -p $HOME/${SW_PATH} |
| 96 | + # This uses YUM to install graalvm |
| 97 | + #- type: Command |
| 98 | + #name: "Install GraalVM Enterprise 22 Native Image for Java 17" |
| 99 | + #command: | |
| 100 | + #echo "Installing graal vm using yum" |
| 101 | + #yum -y install graalvm22-ee-17-native-image |
| 102 | + #echo "Java version is " |
| 103 | + #java -version |
| 104 | + # This used curl to download and then we unpack the graalvm. it give us control over the instalation location |
| 105 | + - type: Command |
| 106 | + name: "Install GraalVM" |
| 107 | + command: | |
| 108 | + echo "Installing graal vm for Java ${GRAALVM_JAVA_VERSION} into $HOME/${SW_PATH}" |
| 109 | + cd $HOME/${SW_PATH} |
| 110 | + echo "Download command is" |
| 111 | + echo curl https://download.oracle.com/graalvm/${GRAALVM_JAVA_VERSION}/latest/graalvm-jdk-${GRAALVM_JAVA_VERSION}_linux-x64_bin.tar.gz -o graalvm.tar.gz |
| 112 | + echo "Downloading" |
| 113 | + curl https://download.oracle.com/graalvm/${GRAALVM_JAVA_VERSION}/latest/graalvm-jdk-${GRAALVM_JAVA_VERSION}_linux-x64_bin.tar.gz -o graalvm.tar.gz |
| 114 | + echo "Download file details are" |
| 115 | + ls -l graalvm.tar.gz |
| 116 | + echo "Unpacking" |
| 117 | + tar xf graalvm.tar.gz |
| 118 | + echo "Removing download file" |
| 119 | + rm -f *tar.gz |
| 120 | + echo "Files after removing download are" |
| 121 | + ls -l |
| 122 | + echo "Relocating" |
| 123 | + mv graalvm-jdk-* graalvm |
| 124 | + echo "files after relocation" |
| 125 | + ls -l |
| 126 | + echo "Setting environment variables" |
| 127 | + export JAVA_HOME=$HOME/${SW_PATH}/graalvm |
| 128 | + export GRAALVM_HOME=${JAVA_HOME} |
| 129 | + echo "JAVA_HOME and GRAALVM_HOME both set to ${JAVA_HOME}" |
| 130 | + echo "Testing download version" |
| 131 | + ${GRAALVM_HOME}/bin/java -version |
| 132 | + - type: Command |
| 133 | + name: "Install Maven" |
| 134 | + command: | |
| 135 | + echo "Download maven ${MVN_VERSION} and install in $HOME/${SW_PATH}" |
| 136 | + cd $HOME/${SW_PATH} |
| 137 | + echo "Current $HOME/$SW_PATH before download contents are" |
| 138 | + ls -l . |
| 139 | + echo "Using curl co download maven, command is " |
| 140 | + echo curl https://dlcdn.apache.org/maven/maven-3/${MVN_VERSION}/binaries/apache-maven-${MVN_VERSION}-bin.tar.gz -o maven.tar.gz |
| 141 | + curl https://dlcdn.apache.org/maven/maven-3/${MVN_VERSION}/binaries/apache-maven-${MVN_VERSION}-bin.tar.gz -o maven.tar.gz |
| 142 | + echo "unpack maven" |
| 143 | + tar xf maven.tar.gz |
| 144 | + echo "Move maven in to place" |
| 145 | + mv apache-maven-* maven |
| 146 | + echo "Remove doanload file" |
| 147 | + rm *.tar.gz |
| 148 | + echo "Configuring MVN_PATH" |
| 149 | + export MVN_HOME=$HOME/${SW_PATH}/maven |
| 150 | + echo "Installed maven version in ${MVN_PATH} is" |
| 151 | + ${MVN_HOME}/bin/mvn --version |
| 152 | + - type: Command |
| 153 | + name: "Configure PATH for installed software" |
| 154 | + command: | |
| 155 | + echo "Using software in system locations and $SW_PATH" |
| 156 | + echo "Before updates PATH is $PATH" |
| 157 | + PATH=PATH=${JAVA_HOME}/bin:${MVN_HOME}/bin:$PATH |
| 158 | + echo "After updates PATH is $PATH" |
| 159 | + - type: Command |
| 160 | + name: "Validating software versions" |
| 161 | + command: | |
| 162 | + echo "Confirming downloaded software versions using PATH" |
| 163 | + echo "java -version" |
| 164 | + java -version |
| 165 | + echo "mvn --version" |
| 166 | + mvn --version |
| 167 | + - type: Command |
| 168 | + name: "Extracting the artifact id and version information" |
| 169 | + command: | |
| 170 | + echo "Extracting artifact ID and version from the pom.xml in ${WORKING_PATH}" |
| 171 | + cd ${WORKING_PATH} |
| 172 | + export EXTRACTED_ARTIFACT_ID=`xmllint --xpath '/*[local-name()="project"]/*[local-name()="artifactId"]/text()' pom.xml` |
| 173 | + export EXTRACTED_VERSION=`xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml` |
| 174 | + echo "Extracted artifact ID is ${EXTRACTED_ARTIFACT_ID}" |
| 175 | + echo "Extracted version is ${EXTRACTED_VERSION}" |
| 176 | + - type: Command |
| 177 | + name: "Compile and build the application" |
| 178 | + command: | |
| 179 | + echo "Compiling in ${WORKING_PATH}" |
| 180 | + cd ${WORKING_PATH} |
| 181 | + echo "Starting compile and native imge process, this may take a while" |
| 182 | + ./mvnw package -Dnative |
| 183 | + - type: Command |
| 184 | + name: "Locating resulting output" |
| 185 | + command: | |
| 186 | + cd ${WORKING_PATH} |
| 187 | + export APPLICATION_COMPILED_NAME=${EXTRACTED_ARTIFACT_ID}-${EXTRACTED_VERSION}-runner |
| 188 | + export APPLICATION_COMPILED_PATH=./target/${APPLICATION_COMPILED_NAME} |
| 189 | + echo "Application compiled path = ${APPLICATION_COMPILED_PATH}" |
| 190 | + echo "Details are :" |
| 191 | + ls -l ${APPLICATION_COMPILED_PATH} |
| 192 | + - type: Command |
| 193 | + name: "Build docker image" |
| 194 | + command: | |
| 195 | + echo "Building docker image in ${WORKING_PATH} contents are" |
| 196 | + cd ${WORKING_PATH} |
| 197 | + ls -l |
| 198 | + echo "Using ${APPLICATION_COMPILED_PATH} as the appSource" |
| 199 | + echo "Docker command to execute is :" |
| 200 | + echo docker build --build-arg BASE_IMAGE=${DOCKER_BASE_IMAGE} --build-arg APP_DIR=${DOCKER_APPLICATION_DIR} --build-arg APP_SOURCE=${APPLICATION_COMPILED_PATH} --build-arg APP_NAME=${APPLICATION_COMPILED_NAME} --file Dockerfile --tag ${EXTRACTED_ARTIFACT_ID}:${EXTRACTED_VERSION} . |
| 201 | + docker build --build-arg BASE_IMAGE=${DOCKER_BASE_IMAGE} --build-arg APP_DIR=${DOCKER_APPLICATION_DIR} --build-arg APP_SOURCE=${APPLICATION_COMPILED_PATH} --build-arg APP_NAME=${APPLICATION_COMPILED_NAME} --file Dockerfile --tag ${EXTRACTED_ARTIFACT_ID}:${EXTRACTED_VERSION} . |
| 202 | +
|
| 203 | +outputArtifacts: |
| 204 | + - name: application-container-image |
| 205 | + type: DOCKER_IMAGE |
| 206 | + location: ${EXTRACTED_ARTIFACT_ID}:${EXTRACTED_VERSION} |
0 commit comments