-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add script to build the ingress controller image using terraform * Update terraform to 0.12.9
- Loading branch information
Showing
11 changed files
with
476 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
if [ -n "$DEBUG" ]; then | ||
set -x | ||
fi | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P) | ||
|
||
AWS_FILE="${DIR}/images/nginx/aws.tfvars" | ||
ENV_FILE="${DIR}/images/nginx/env.tfvars" | ||
|
||
if [ ! -f "${AWS_FILE}" ]; then | ||
echo "File $AWS_FILE does not exist. Please create this file with keys access_key an secret_key" | ||
exit 1 | ||
fi | ||
|
||
if [ ! -f "${ENV_FILE}" ]; then | ||
echo "File $ENV_FILE does not exist. Please create this file with keys docker_username and docker_password" | ||
exit 1 | ||
fi | ||
|
||
# build local terraform image to build nginx | ||
docker build -t build-ingress-controller-terraform $DIR/images/ingress-controller | ||
|
||
# build nginx and publish docker images to quay.io. | ||
# this can take up to two hours. | ||
docker run --rm -it \ | ||
--volume $DIR/images/ingress-controller:/tf \ | ||
-w /tf \ | ||
-v ${AWS_FILE}:/root/aws.tfvars:ro \ | ||
-v ${ENV_FILE}:/root/env.tfvars:ro \ | ||
build-ingress-controller-terraform | ||
|
||
docker rmi -f build-ingress-controller-terraform |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.tfvars |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.terraform* | ||
terraform* | ||
*.tfstate | ||
*.tfstate.backup | ||
id_rsa* | ||
aws.tfvars | ||
env.tfvars |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM quay.io/kubernetes-ingress-controller/debian-base-amd64:0.1 | ||
|
||
ENV TERRAFORM_VERSION 0.12.9 | ||
|
||
RUN clean-install \ | ||
bash \ | ||
curl \ | ||
ca-certificates \ | ||
unzip \ | ||
git \ | ||
openssh-client | ||
|
||
RUN curl -sSL -o /terraform.zip "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" \ | ||
&& unzip /terraform.zip -d /usr/bin \ | ||
&& rm -rf /terraform.zip | ||
|
||
COPY entrypoint.sh / | ||
|
||
CMD [ "/entrypoint.sh" ] |
93 changes: 93 additions & 0 deletions
93
build/images/ingress-controller/build-ingress-controller.sh
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
function source_tfvars() { | ||
eval "$( | ||
awk 'BEGIN {FS=OFS="="} | ||
!/^(#| *$)/ && /^.+=.+$/ { | ||
gsub(/^[ \t]+|[ \t]+$/, "", $1); | ||
gsub(/\./, "_", $1); | ||
gsub(/^[ \t]+|[ \t]+$/, "", $2); | ||
if ($1 && $2) print $0 | ||
}' "$@" | ||
)" | ||
} | ||
|
||
source_tfvars /tmp/env | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
apt -q=3 update | ||
|
||
apt -q=3 dist-upgrade --yes | ||
|
||
add-apt-repository universe --yes | ||
add-apt-repository multiverse --yes | ||
|
||
apt -q=3 update | ||
|
||
apt -q=3 install \ | ||
apt-transport-https \ | ||
ca-certificates \ | ||
curl \ | ||
make \ | ||
htop \ | ||
software-properties-common --yes | ||
|
||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | ||
|
||
add-apt-repository \ | ||
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \ | ||
$(lsb_release -cs) \ | ||
stable" --yes | ||
|
||
apt -q=3 update | ||
|
||
apt -q=3 install docker-ce --yes | ||
|
||
echo ${docker_password} | docker login -u ${docker_username} --password-stdin quay.io | ||
|
||
curl -sL -o /usr/local/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | ||
chmod +x /usr/local/bin/gimme | ||
|
||
eval "$(gimme 1.13.1)" | ||
|
||
export GOPATH="/tmp/go" | ||
|
||
INGRESS_DIRECTORY="${GOPATH}/src/k8s.io" | ||
|
||
mkdir -p ${INGRESS_DIRECTORY} | ||
cd ${INGRESS_DIRECTORY} | ||
|
||
git clone https://github.com/kubernetes/ingress-nginx | ||
|
||
cd ingress-nginx | ||
|
||
make register-qemu | ||
|
||
echo "Building NGINX image..." | ||
make all-container | ||
|
||
echo "Publishing NGINX images..." | ||
make all-push | ||
|
||
# Requires https://github.com/kubernetes/ingress-nginx/pull/4271 | ||
#echo "Creating multi-arch images..." | ||
#make push-manifest |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
catch() { | ||
if [ "$1" == "0" ]; then | ||
exit 0 | ||
fi | ||
|
||
echo "Error $1 occurred on $2" | ||
|
||
echo "Removing temporal resources..." | ||
terraform destroy -auto-approve \ | ||
-var-file /root/aws.tfvars \ | ||
-var-file /root/env.tfvars \ | ||
-var valid_until="${EC2_VALID_UNTIL}" | ||
} | ||
trap 'catch $? $LINENO' ERR | ||
|
||
terraform init | ||
|
||
# destroy spot instance after two hours | ||
EC2_VALID_UNTIL=$(date -d "+2 hours" +%Y-%m-%dT%H:%M:%SZ) | ||
|
||
terraform plan \ | ||
-var-file /root/aws.tfvars \ | ||
-var-file /root/env.tfvars \ | ||
-var valid_until="${EC2_VALID_UNTIL}" | ||
|
||
terraform apply -auto-approve \ | ||
-var-file /root/aws.tfvars \ | ||
-var-file /root/env.tfvars \ | ||
-var valid_until="${EC2_VALID_UNTIL}" | ||
|
||
terraform destroy -auto-approve \ | ||
-var-file /root/aws.tfvars \ | ||
-var-file /root/env.tfvars \ | ||
-var valid_until="${EC2_VALID_UNTIL}" |
Oops, something went wrong.