|
| 1 | +#!/bin/bash |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | +# Script to insert includes files into jenkins-deployment-template.yaml as jenkins-deployment.yaml |
| 19 | + |
| 20 | +set -e |
| 21 | + |
| 22 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 23 | +INPUT="$SCRIPT_DIR/jenkins-deployment-template.yaml" |
| 24 | +OUTPUT="$SCRIPT_DIR/jenkins-deployment.yaml" |
| 25 | + |
| 26 | +clean() { |
| 27 | + sed "/^#/d;" |
| 28 | +} |
| 29 | + |
| 30 | +# Read template files |
| 31 | +POD_TEMPLATE=$(cat "$SCRIPT_DIR/includes/pod-template-base.yaml" | clean ) |
| 32 | +JNLP_CONTAINER=$(cat "$SCRIPT_DIR/includes/jnlp-container-base.yaml" | clean ) |
| 33 | +DIND_CONTAINER=$(cat "$SCRIPT_DIR/includes/dind-container-base.yaml" | clean ) |
| 34 | +VOLUMES=$(cat "$SCRIPT_DIR/includes/volumes-base.yaml" | clean ) |
| 35 | + |
| 36 | +# Replace anchor references |
| 37 | +awk -v pod="$POD_TEMPLATE" -v jnlp="$JNLP_CONTAINER" -v dind="$DIND_CONTAINER" -v vols="$VOLUMES" ' |
| 38 | +{ |
| 39 | + line = $0 |
| 40 | + gsub(/ <<: \*pod-template-base/, pod, line) |
| 41 | + gsub(/ <<: \*jnlp-container-base/, jnlp, line) |
| 42 | + gsub(/ <<: \*dind-container-base/, dind, line) |
| 43 | + gsub(/volumes: \*volumes-base/, "volumes: " vols, line) |
| 44 | + print line |
| 45 | +} |
| 46 | +' "$INPUT" > "$OUTPUT" |
0 commit comments