Created
April 28, 2023 04:45
-
-
Save coreydaley/34287ccac7a0c42282b3f3393fa9ae59 to your computer and use it in GitHub Desktop.
OpenShift Jenkins image build script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Assumes the following directory structure exists: | |
# ~/projects/github.com/openshift/jenkins | |
# ~/projects/github.com/openshift/jenkins-sync-plugin | |
# ~/projects/github.com/openshift/jenkins-client-plugin | |
# ~/projects/github.com/openshift/jenkins-openshift-login-plugin | |
if [ -z "$QUAY_USER" ]; then | |
printf "You MUST supply a QUAY_USER to push the image to\n" | |
printf "Usage: QUAY_USER=<username> sh build.sh \n" | |
exit 1 | |
fi | |
# Create the directory to copy the plugin artifacts into | |
if [ ! -d jpi ]; then | |
mkdir jpi | |
else | |
rm -rf jpi/* | |
fi | |
# Build the base Jenkins server image and tag it as quay.io/<username>/origin-jenkins:latest | |
pushd ~/projects/github.com/openshift/jenkins || return | |
podman build 2 -f 2/Dockerfile.rhel8 -t "quay.io/${QUAY_USER}/origin-jenkins:latest" | |
popd || return | |
# Directory to name mapping for Jenkins plugins | |
PLUGINS=( | |
"jenkins-sync-plugin:openshift-sync" | |
"jenkins-client-plugin:openshift-client" | |
"jenkins-openshift-login-plugin:openshift-login" | |
) | |
# Build each plugin and copy the artifact to the jpi folder | |
for plugin in "${PLUGINS[@]}"; do | |
DIRECTORY=${plugin%%:*} | |
NAME=${plugin#*:} | |
pushd "${HOME}/projects/github.com/openshift/${DIRECTORY}" || exit | |
mvn clean package | |
popd || exit | |
cp "${HOME}/projects/github.com/openshift/${DIRECTORY}/target/${NAME}.hpi" "./jpi/${NAME}.jpi" | |
done | |
# Create the needed Containerfile | |
cat > Containerfile << EOL | |
FROM quay.io/${QUAY_USER}/origin-jenkins:latest | |
USER root | |
COPY ./jpi /opt/openshift/plugins | |
EOL | |
# Build the quay.io/<username>/jenkins:latest image and push it to quay.io | |
podman build . -f Containerfile -t "quay.io/${QUAY_USER}/jenkins:latest" | |
podman push "quay.io/${QUAY_USER}/jenkins:latest" | |
if [ -z "$NO_CLEANUP" ];then | |
rm -rf jpi | |
rm Containerfile | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment