|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -set -eo pipefail |
| 3 | +set -euo pipefail |
4 | 4 |
|
5 | 5 | function require() { |
6 | 6 | if [ -z "$2" ]; then |
@@ -51,19 +51,78 @@ function k0sbin() { |
51 | 51 | return 0 |
52 | 52 | fi |
53 | 53 |
|
54 | | - # if the override is set, the binary will have been added to the bucket through another process |
| 54 | + # if the override is set, we should download this binary and upload it to the bucket so as not to require end users hit the override url |
55 | 55 | if [ -n "${k0s_override}" ] && [ "${k0s_override}" != '' ]; then |
56 | 56 | echo "K0S_BINARY_SOURCE_OVERRIDE is set to '${k0s_override}', using that source" |
57 | | - curl -L -o "${k0s_version}" "${k0s_override}" |
| 57 | + curl --fail-with-body -L -o "${k0s_version}" "${k0s_override}" |
58 | 58 | else |
59 | 59 | # download the k0s binary from official sources |
60 | | - curl -L -o "${k0s_version}" "https://github.com/k0sproject/k0s/releases/download/${k0s_version}/k0s-${k0s_version}-amd64" |
| 60 | + echo "downloading k0s binary from https://github.com/k0sproject/k0s/releases/download/${k0s_version}/k0s-${k0s_version}-amd64" |
| 61 | + curl --fail-with-body -L -o "${k0s_version}" "https://github.com/k0sproject/k0s/releases/download/${k0s_version}/k0s-${k0s_version}-amd64" |
61 | 62 | fi |
62 | 63 |
|
63 | 64 | # upload the binary to the bucket |
64 | 65 | retry 3 aws s3 cp "${k0s_version}" "s3://${S3_BUCKET}/k0s-binaries/${k0s_version}" |
65 | 66 | } |
66 | 67 |
|
| 68 | +function operatorbin() { |
| 69 | + # first, figure out what version of operator is in the current build |
| 70 | + local operator_version= |
| 71 | + operator_version=$(awk '/^EMBEDDED_OPERATOR_CHART_VERSION/{print $3}' Makefile) |
| 72 | + |
| 73 | + # check if the binary already exists in the bucket |
| 74 | + local operator_binary_exists= |
| 75 | + operator_binary_exists=$(aws s3api head-object --bucket "${S3_BUCKET}" --key "operator-binaries/${operator_version}" || true) |
| 76 | + |
| 77 | + # if the binary already exists, we don't need to upload it again |
| 78 | + if [ -n "${operator_binary_exists}" ]; then |
| 79 | + echo "operator binary ${operator_version} already exists in bucket ${S3_BUCKET}, skipping upload" |
| 80 | + return 0 |
| 81 | + fi |
| 82 | + |
| 83 | + # download the operator binary from github |
| 84 | + echo "downloading embedded cluster operator binary from https://github.com/replicatedhq/embedded-cluster-operator/releases/download/v${operator_version}/manager" |
| 85 | + curl --fail-with-body -L -o "${operator_version}" "https://github.com/replicatedhq/embedded-cluster-operator/releases/download/v${operator_version}/manager" |
| 86 | + |
| 87 | + # upload the binary to the bucket |
| 88 | + retry 3 aws s3 cp "${operator_version}" "s3://${S3_BUCKET}/operator-binaries/${operator_version}" |
| 89 | +} |
| 90 | + |
| 91 | +function kotsbin() { |
| 92 | + # first, figure out what version of kots is in the current build |
| 93 | + local kots_version= |
| 94 | + kots_version=$(awk '/^ADMIN_CONSOLE_CHART_VERSION/{print $3}' Makefile) |
| 95 | + kots_version=$(echo "${kots_version}" | sed 's/\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/') |
| 96 | + |
| 97 | + local kots_override= |
| 98 | + kots_override=$(awk '/^KOTS_BINARY_URL_OVERRIDE/{gsub("\"", "", $3); print $3}' Makefile) |
| 99 | + |
| 100 | + # check if the binary already exists in the bucket |
| 101 | + local kots_binary_exists= |
| 102 | + kots_binary_exists=$(aws s3api head-object --bucket "${S3_BUCKET}" --key "kots-binaries/${kots_version}" || true) |
| 103 | + |
| 104 | + # if the binary already exists, we don't need to upload it again |
| 105 | + if [ -n "${kots_binary_exists}" ]; then |
| 106 | + echo "kots binary ${kots_version} already exists in bucket ${S3_BUCKET}, skipping upload" |
| 107 | + return 0 |
| 108 | + fi |
| 109 | + |
| 110 | + if [ -n "${kots_override}" ] && [ "${kots_override}" != '' ]; then |
| 111 | + echo "KOTS_BINARY_URL_OVERRIDE is set to '${kots_override}', using that source" |
| 112 | + curl --fail-with-body -L -o "kots_linux_amd64.tar.gz" "${kots_override}" |
| 113 | + else |
| 114 | + # download the kots binary from github |
| 115 | + echo "downloading kots binary from https://github.com/replicatedhq/kots/releases/download/v${kots_version}/kots_linux_amd64.tar.gz" |
| 116 | + curl --fail-with-body -L -o "kots_linux_amd64.tar.gz" "https://github.com/replicatedhq/kots/releases/download/v${kots_version}/kots_linux_amd64.tar.gz" |
| 117 | + fi |
| 118 | + |
| 119 | + # decompress the bundle, as we only care about the binary and not the sbom/license/readme |
| 120 | + tar -xvf kots_linux_amd64.tar.gz |
| 121 | + |
| 122 | + # upload the binary to the bucket |
| 123 | + retry 3 aws s3 cp "kots" "s3://${S3_BUCKET}/kots-binaries/${kots_version}" |
| 124 | +} |
| 125 | + |
67 | 126 | function metadata() { |
68 | 127 | if [ -z "${EC_VERSION}" ]; then |
69 | 128 | echo "EC_VERSION unset, not uploading metadata.json" |
@@ -98,6 +157,8 @@ function embeddedcluster() { |
98 | 157 | # the embedded cluster release does not exist for CI builds |
99 | 158 | function main() { |
100 | 159 | k0sbin |
| 160 | + operatorbin |
| 161 | + kotsbin |
101 | 162 | metadata |
102 | 163 | embeddedcluster |
103 | 164 | } |
|
0 commit comments