Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deploy script. #24

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ The SECRET_KEY_BASE below is just a filler one for the purpose of testing locall

Run Docker Image: `docker run -t -p 4000:4000 -e DATABASE_URL='ecto://postgres:@host.docker.internal:5434/database' -e SECRET_KEY_BASE='B8rwzeX3DFLveiJ4cP28lRGc0PWdEr8ZF/hDoPRucw95Nzf2IPnu7lhEB+Yldx6Z' dpul-collections`

## Deployment

1. Connect to VPN
1. `BRANCH=<branch> ./bin/deploy staging`

## Learn more

* Official website: https://www.phoenixframework.org/
Expand Down
22 changes: 22 additions & 0 deletions bin/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
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 [email protected] << EOF
hackartisan marked this conversation as resolved.
Show resolved Hide resolved
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"
hackartisan marked this conversation as resolved.
Show resolved Hide resolved
hackartisan marked this conversation as resolved.
Show resolved Hide resolved

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) }')" -

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

Loading