Skip to content

Production Deployment #186

Production Deployment

Production Deployment #186

Workflow file for this run

# This workflow deploys any branch, tag, or commit hash to the production environment.
name: Production Deployment
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
tag:
description: The branch, tag, or commit hash to deploy
required: false
default: master
type: string
jobs:
deploy:
# Allow the job to fetch a GitHub ID token
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
env:
TAG: ${{ github.event.inputs.tag }}
steps:
- uses: actions/checkout@v4
- name: Add SSH key
run: |
mkdir -p /home/runner/.ssh
echo "${{ secrets.GCLOUD_SSH_KEY }}" > /home/runner/.ssh/google_compute_engine
echo "${{ secrets.GCLOUD_SSH_KEY_PUB }}" > /home/runner/.ssh/google_compute_engine.pub
chmod 600 /home/runner/.ssh/google_compute_engine
chmod 600 /home/runner/.ssh/google_compute_engine.pub
- name: Authenticate with Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
create_credentials_file: true
cleanup_credentials: true
export_environment_variables: true
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
skip_install: true
- name: Run deploy script
run: |
gsutil cp gs://openreview-general/conf/deployment.conf ./deployment.conf
sed -i "s/WEB_TAG=.*/WEB_TAG=\"$TAG\"/" ./deployment.conf
gsutil cp ./deployment.conf gs://openreview-general/conf/deployment.conf
instance_prefix='openreview-web-'
instances=$(gcloud compute instances list | grep "$instance_prefix" | grep RUNNING | tr -s ' ' | cut -d' ' -f1,2)
instances_arr=(${instances// / })
instance_names=()
zones=()
for i in ${!instances_arr[@]}; do
if echo "${instances_arr[$i]}" | grep -q "$instance_prefix"; then
instance_names+=(${instances_arr[$i]})
else
zones+=(${instances_arr[$i]})
fi
done
gcloud compute ssh --zone ${zones[0]} openreview@${instance_names[0]} --command "bash bin/build-web.sh ${TAG}"
for i in ${!instance_names[@]}; do
echo Deploying to ${instance_names[$i]}
gcloud compute ssh --zone ${zones[$i]} openreview@${instance_names[$i]} --command "bash bin/deploy-web.sh ${TAG}"
done
nginx='nginx'
nvm='export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" &&'
nginx=$(gcloud compute instances list | grep "$nginx" | grep RUNNING | tr -s ' ' | cut -d' ' -f1,2)
nginx_arr=(${nginx// / })
nginx_name=${nginx_arr[0]}
nginx_zone=${nginx_arr[1]}
gcloud compute --project "sunlit-realm-131518" ssh --zone $nginx_zone openreview@$nginx_name --command "${nvm} bash bin/deploy-web.sh ${TAG}" --quiet