Skip to content

Commit

Permalink
Merge release branch into master branch [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Nubisproject (Mozilla) committed Jul 3, 2018
2 parents 582e92a + 118cc82 commit b588941
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 18 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# Change Log

## [v0.15.0](https://github.com/nubisproject/nubis-docker-deploy/tree/v0.15.0) (2018-07-03)
[Full Changelog](https://github.com/nubisproject/nubis-docker-deploy/compare/v0.14.0...v0.15.0)

**Merged pull requests:**

- Enable tty autodetection [\#78](https://github.com/nubisproject/nubis-docker-deploy/pull/78) ([tinnightcap](https://github.com/tinnightcap))

## [v0.14.0](https://github.com/nubisproject/nubis-docker-deploy/tree/v0.14.0) (2018-06-07)
[Full Changelog](https://github.com/nubisproject/nubis-docker-deploy/compare/v0.13.0...v0.14.0)

**Closed issues:**

- Use json2hcl instead of toml2json [\#71](https://github.com/nubisproject/nubis-docker-deploy/issues/71)
- Tag v0.14.0 release [\#73](https://github.com/nubisproject/nubis-docker-deploy/issues/73)

**Merged pull requests:**

- Update CHANGELOG for v0.14.0 release \[skip ci\] [\#75](https://github.com/nubisproject/nubis-docker-deploy/pull/75) ([nubis-automation](https://github.com/nubis-automation))
- Update CHANGELOG for v0.14.0 release \[skip ci\] [\#74](https://github.com/nubisproject/nubis-docker-deploy/pull/74) ([nubis-automation](https://github.com/nubis-automation))
- \[please test\] Convert to json2hcl [\#72](https://github.com/nubisproject/nubis-docker-deploy/pull/72) ([limed](https://github.com/limed))

## [v0.13.0](https://github.com/nubisproject/nubis-docker-deploy/tree/v0.13.0) (2018-05-02)
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ RUN ["/bin/bash", "-c", "set -o pipefail \
&& rm terraform_${TerraformVersion}_linux_amd64.zip \
&& curl -L https://github.com/Versent/unicreds/releases/download/${UnicredsVersion}/unicreds_${UnicredsVersion}_linux_amd64.tar.gz \
| tar -C /nubis/bin -xzf - \
&& curl -LO --silent --show-error https://github.com/kubernetes/kops/releases/download/${KopsVersion}/kops-linux-amd64 \
&& curl -LO https://github.com/kubernetes/kops/releases/download/${KopsVersion}/kops-linux-amd64 \
&& mv kops-linux-amd64 /usr/local/bin/kops \
&& chmod +x /usr/local/bin/kops \
&& curl -LO --silent --show-error https://github.com/kvz/json2hcl/releases/download/v${Json2HclVersion}/json2hcl_v${Json2HclVersion}_linux_amd64 \
&& curl -LO https://github.com/kvz/json2hcl/releases/download/v${Json2HclVersion}/json2hcl_v${Json2HclVersion}_linux_amd64 \
&& mv json2hcl_v${Json2HclVersion}_linux_amd64 /usr/local/bin/json2hcl \
&& chmod +x /usr/local/bin/json2hcl \
&& curl -LO https://storage.googleapis.com/kubernetes-release/release/v${KubeCtlVersion}/bin/linux/amd64/kubectl \
Expand Down
2 changes: 1 addition & 1 deletion account-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ accounts () {
# Grab and setup called options
while [ "$1" != "" ]; do
case "$1" in
--debug | --setx )
-x | --debug | --setx )
set -x
;;
-h | --help | help )
Expand Down
64 changes: 49 additions & 15 deletions nubis-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ setup-terraform () {

# Test for the existance of state.tf file
if [ ! -f "${MOUNT_TERRAFORM_PATH}/state.tf" ];then
echo -e "\033[1;31mERROR: 'state.tf' file not found in ${MOUNT_TERRAFORM_PATH}\033[0m"
echo -e "\033[1;31mERROR: 'state.tf' file should contain the following lines:\033[0m"
echo -e "\033[1;31mERROR: terraform { backend \"s3\" {} }\033[0m"
exit 1
echo -e "\033[0;32mWARNING: 'state.tf' file not found in ${MOUNT_TERRAFORM_PATH}\033[0m"
echo -e "\033[0;32mWARNING: 'state.tf' file should contain the following lines:\033[0m"
echo -e "\033[0;32mWARNING: terraform { backend \"s3\" {} }\033[0m"
echo -e "\033[0;32mWARNING: Adding temporary state.tf file.\033[0m"

# Workaround for TF bug https://github.com/hashicorp/terraform/issues/15761
TF_CONSUL_WORKAROUND="${MOUNT_TERRAFORM_PATH}/nubis-state-${RANDOM}.tf"
echo 'terraform { backend "s3" { } }' > "${TF_CONSUL_WORKAROUND}"
export TF_CONSUL_WORKAROUND
fi

ACCOUNT=$(json2hcl -reverse < "${MOUNT_TERRAFORM_PATH}/terraform.tfvars" | jq -r .account )
Expand Down Expand Up @@ -116,6 +121,16 @@ setup-terraform () {
echo "Creating directory ${WORKING_PATH}/${SERVICE_NAME}"
mkdir "${WORKING_PATH}/${SERVICE_NAME}"
fi

# Determine if we have a tty and set input accordingly
if ! tty > /dev/null 2>&1 ; then
echo "Info: setting -input=false"
TTY_INPUT='false'
else
echo "Info: setting -input=true"
TTY_INPUT='true'
fi
export TTY_INPUT
}

setup-deploy-dir () {
Expand All @@ -141,11 +156,11 @@ terraform-init () {
fi

if ! terraform init \
-input=true \
-input="${TTY_INPUT}" \
-upgrade=true \
-backend-config="region=${BUCKET_REGION}" \
-backend-config="key=terraform/${SERVICE_NAME}" \
-backend-config="bucket=${STATE_BUCKET}";
-backend-config="bucket=${STATE_BUCKET}"
then
echo -e "\033[1;31mERROR: Could not initialize teraform\033[0m"
exit 1
Expand All @@ -158,27 +173,37 @@ terraform-apply () {
exit 1
fi

if ! terraform plan -out=".terraform/terraform.plan"; then
if ! terraform plan -input="${TTY_INPUT}" -out=".terraform/terraform.plan"; then
echo -e "\033[1;31mERROR: Terraform plan failed. Not applying plan\033[0m"
exit 1
fi

terraform apply ".terraform/terraform.plan"
terraform apply -input="${TTY_INPUT}" ".terraform/terraform.plan"

# Copy Terraform files to the S3 bucket
echo -e "\nUploading Terraform assets to s3"
aws s3 sync --delete --region "${BUCKET_REGION}" --exclude ".terraform*" "${TERRAFORM_PATH}/" "s3://${STATE_BUCKET}/terraform/${SERVICE_NAME}-terraform/"

# Clean up temporary file if we created one
if [ -f "${TF_CONSUL_WORKAROUND}" ];then
rm "${TF_CONSUL_WORKAROUND}"
fi
}

terraform-do () {
declare -a _ACTION; _ACTION=( "${@}" )
cd "${TERRAFORM_PATH}" && terraform "${_ACTION[@]}"

# Clean up temporary file if we created one
if [ -f "${TF_CONSUL_WORKAROUND}" ];then
rm "${TF_CONSUL_WORKAROUND}"
fi
}

# Grab and setup called options
while [ "$1" != "" ]; do
case $1 in
--debug )
-x | --debug )
set -x
;;
-h | --help | help )
Expand All @@ -187,17 +212,26 @@ while [ "$1" != "" ]; do
--skip-init )
SKIP_INIT='1'
;;
-a | --account | --account-name )
NUBIS_ACCOUNT="$2"
shift
;;

account )
shift
account-deploy "${@}"
if [ "${#@}" == 0 ]; then
account-deploy
else
account-deploy --account "${NUBIS_ACCOUNT}" "${@}"
fi
shift "${#@}"
GOT_COMMAND=1
;;
plan )
setup-terraform
setup-deploy-dir
[[ ${SKIP_INIT:-0} == 0 ]] && terraform-init || echo "Skipping terraform-init"
terraform-do plan
terraform-do plan -input="${TTY_INPUT}"
GOT_COMMAND=1
;;
apply )
Expand All @@ -211,30 +245,30 @@ while [ "$1" != "" ]; do
setup-terraform
setup-deploy-dir
[[ ${SKIP_INIT:-0} == 0 ]] && terraform-init || echo "Skipping terraform-init"
terraform-do destroy
terraform-do destroy -input="${TTY_INPUT}"
GOT_COMMAND=1
;;
show )
setup-terraform
setup-deploy-dir
[[ ${SKIP_INIT:-0} == 0 ]] && terraform-init || echo "Skipping terraform-init"
terraform-do show
terraform-do show -input="${TTY_INPUT}"
GOT_COMMAND=1
;;
output )
shift
setup-terraform
setup-deploy-dir
[[ ${SKIP_INIT:-0} == 0 ]] && terraform-init || echo "Skipping terraform-init"
terraform-do output "${@}"
terraform-do output -input="${TTY_INPUT}" "${@}"
GOT_COMMAND=1
;;
state )
shift
setup-terraform
setup-deploy-dir
[[ ${SKIP_INIT:-0} == 0 ]] && terraform-init || echo "Skipping terraform-init"
terraform-do state "${@}"
terraform-do state -input="${TTY_INPUT}" "${@}"
GOT_COMMAND=1
;;
* )
Expand Down

0 comments on commit b588941

Please sign in to comment.