diff --git a/bin/deploy b/bin/deploy index 6d7bc3de..d5880324 100755 --- a/bin/deploy +++ b/bin/deploy @@ -2,12 +2,21 @@ ENV=$1 BRANCH_NAME="${BRANCH:-main}" REPOSITORY="${REPO:-dpul-collections}" +JOB_NAME="${JOBNAME:-dpulc}" if [[ -z ${ENV} ]]; then echo "Missing Environment. Command: BRANCH=main ./bin/deploy staging" exit fi +# Notify Github of Starting Deploy, Deploy, Notify Github of Ending Deploy ssh -qtt deploy@nomad-host-prod1.lib.princeton.edu << EOF + DEPLOY_ID=\$(curl -X POST -H "Accept: application/vnd.github+json-H" -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Bearer \$GITHUB_TOKEN" --data "{\"ref\":\"${BRANCH_NAME}\",\"description\":\"Deploy from Nomad script\", \"auto_merge\": false, \"environment\": \"${ENV}\", \"required_contexts\": [] }" "https://api.github.com/repos/pulibrary/${REPOSITORY}/deployments" | jq .id) + curl -s -X POST -H "Accept: application/vnd.github+json-H" -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Bearer \$GITHUB_TOKEN" --data "{\"environment\":\"${ENV}\",\"state\":\"in_progress\",\"log_url\": \"https://nomad.lib.princeton.edu/ui/jobs/${JOB_NAME}-${ENV}\", \"description\":\"Deployment finished successfully.\"}" "https://api.github.com/repos/pulibrary/${REPOSITORY}/deployments/\$DEPLOY_ID/statuses" + clear - curl -s "https://raw.githubusercontent.com/pulibrary/${REPOSITORY}/${BRANCH_NAME}/config/deploy/${ENV}.hcl" | nomad job run -var "branch_or_sha=sha-$(git ls-remote https://github.com/pulibrary/${REPOSITORY}.git ${BRANCH_NAME} | awk '{ print substr($1,1,7) }')" - && logout + + curl -s "https://raw.githubusercontent.com/pulibrary/${REPOSITORY}/${BRANCH_NAME}/config/deploy/${ENV}.hcl" | nomad job run -var "branch_or_sha=sha-$(git ls-remote https://github.com/pulibrary/${REPOSITORY}.git ${BRANCH_NAME} | awk '{ print substr($1,1,7) }')" - + + curl -s -X POST -H "Accept: application/vnd.github+json-H" -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Bearer \$GITHUB_TOKEN" --data "{\"environment\":\"${ENV}\",\"state\":\"success\",\"log_url\": \"https://nomad.lib.princeton.edu/ui/jobs/${JOB_NAME}-${ENV}\", \"description\":\"Deployment finished successfully.\"}" "https://api.github.com/repos/pulibrary/${REPOSITORY}/deployments/\$DEPLOY_ID/statuses" && logout EOF +