Skip to content

Commit

Permalink
Merge pull request #6018 from shaneknapp/more-workflow-tweaking
Browse files Browse the repository at this point in the history
[DH-301] combine staging/prod deploy to one workflow, skip if we need to deploy all hubs
  • Loading branch information
shaneknapp authored Aug 26, 2024
2 parents 6f0bdf0 + ec636c3 commit 522bb9e
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 207 deletions.
202 changes: 202 additions & 0 deletions .github/workflows/deploy-hubs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# this workflow re-deploys SPECIFIC hubs to staging or prod if the single-user
# server image or config has changed based on the PR labels "hub: <hubname>".
#
# however, this workflow will be not run if the PR labels of "hub-images" or
# "jupyterhub-deployment" are present, as these labels will trigger the
# "deploy-jupyterhub-base-images.yaml" workflow which re-deploys every hub.
#
name: Deploy staging and prod hubs
on:
workflow_dispatch:
push:
branches:
- staging
- prod

jobs:
deploy-hubs-to-staging:
if: github.event_name == 'push' && github.ref == 'refs/heads/staging'
runs-on: ubuntu-latest
steps:
- name: Get PR labels
id: pr-labels
uses: irby/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Pull out any hubs that need deploying from the labels on the merge commit to staging
run: |
echo "PR labels: ${{ steps.pr-labels.outputs.labels }}"
HUBS=()
for label in $(echo -e "${{ steps.pr-labels.outputs.labels }}"); do
if [[ "$label" == hub-* ]]; then
label=$(echo $label | awk -F'-' '{print $2}')
HUBS+="$label"
echo "DEPLOY=1" >> $GITHUB_ENV
fi
done
# If the PR labels "hub-images" or "jupyterhub-deployment" are present, this
# means the base hub image has changed, and all hubs (staging or prod) need to
# be redeployed. This workflow will not run in that case.
if [ -n $GITHUB_PR_LABEL_HUB_IMAGES ] || [ -n $GITHUB_PR_LABEL_JUPYTERHUB_DEPLOYMENT ]; then
echo "Base hub image has changed, not deploying individual hubs to staging"
echo "DEPLOY=0" >> $GITHUB_ENV
fi
echo "DEPLOY_HUBS=${HUBS[@]}" >> $GITHUB_ENV
- name: Check out the image repo
if: ${{ env.DEPLOY }}
uses: actions/checkout@v4
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.

- name: Setup python
if: ${{ env.DEPLOY }}
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
if: ${{ env.DEPLOY }}
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install --force-reinstall git+https://github.com/shaneknapp/hubploy.git@major-refactor
- name: Auth to gcloud
if: ${{ env.DEPLOY }}
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GKE_KEY }}
project_id: ${{ secrets.GCP_PROJECT_ID }}

- name: Install Google Cloud SDK
if: ${{ env.DEPLOY }}
uses: google-github-actions/setup-gcloud@v2
with:
install_components: 'gke-gcloud-auth-plugin'

- name: Install SOPS
if: ${{ env.DEPLOY }}
run: |
mkdir -p ${HOME}/bin
curl -sSL https://github.com/getsops/sops/releases/download/v3.9.0/sops-v3.9.0.linux.amd64 -o ${HOME}/bin/sops
chmod 755 ${HOME}/bin/sops
echo "${HOME}/bin" >> $GITHUB_PATH
- name: Store SOPS secret in a file
if: ${{ env.DEPLOY }}
run: |
cat << EOF > ${HOME}/sops.key
${{ secrets.SOPS_KEY }}
EOF
echo "GOOGLE_APPLICATION_CREDENTIALS=${HOME}/sops.key" >> $GITHUB_ENV
- name: Install Helm
if: ${{ env.DEPLOY }}
run: |
curl -L https://get.helm.sh/helm-v3.13.3-linux-amd64.tar.gz | tar -xzf -
mv linux-amd64/helm /usr/local/bin
helm repo add jupyterhub https://jupyterhub.github.io/helm-chart/
helm repo update
- name: Deploy hubs to staging
if: ${{ env.DEPLOY }}
run: |
for hub in $(echo -e "${{ env.DEPLOY_HUBS }}"); do
echo "Deploying $hub to staging"
echo "hubploy --debug deploy $hub hub staging"
done
deploy-hubs-to-prod:
if: github.event_name == 'push' && github.ref == 'refs/heads/prod'
runs-on: ubuntu-latest
steps:
- name: Get PR labels
id: pr-labels
uses: irby/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check out the image repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.

- name: Pull out any hubs that need deploying from the labels on the merge commit to prod
run: |
echo "PR labels: ${{ steps.pr-labels.outputs.labels }}"
HUBS=()
for label in $(echo -e "${{ steps.pr-labels.outputs.labels }}"); do
if [[ "$label" == hub-* ]]; then
label=$(echo $label | awk -F'-' '{print $2}')
HUBS+="$label"
echo "DEPLOY=1" >> $GITHUB_ENV
fi
done
# If the PR labels "hub-images" or "jupyterhub-deployment" are present, this
# means the base hub image has changed, and all hubs (staging or prod) need to
# be redeployed. This workflow will not run in that case.
if [ -n $GITHUB_PR_LABEL_HUB_IMAGES ] || [ -n $GITHUB_PR_LABEL_JUPYTERHUB_DEPLOYMENT ]; then
echo "Base hub image has changed, not deploying individual hubs to prod"
echo "DEPLOY=0" >> $GITHUB_ENV
fi
echo "DEPLOY_HUBS=${HUBS[@]}" >> $GITHUB_ENV
- name: Setup python
if: ${{ env.DEPLOY }}
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
if: ${{ env.DEPLOY }}
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install --force-reinstall git+https://github.com/shaneknapp/hubploy.git@major-refactor
- name: Auth to gcloud
if: ${{ env.DEPLOY }}
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GKE_KEY }}
project_id: ${{ secrets.GCP_PROJECT_ID }}

- name: Install Google Cloud SDK
if: ${{ env.DEPLOY }}
uses: google-github-actions/setup-gcloud@v2
with:
install_components: 'gke-gcloud-auth-plugin'

- name: Install SOPS
if: ${{ env.DEPLOY }}
run: |
mkdir -p ${HOME}/bin
curl -sSL https://github.com/getsops/sops/releases/download/v3.9.0/sops-v3.9.0.linux.amd64 -o ${HOME}/bin/sops
chmod 755 ${HOME}/bin/sops
echo "${HOME}/bin" >> $GITHUB_PATH
- name: Store SOPS secret in a file
if: ${{ env.DEPLOY }}
run: |
cat << EOF > ${HOME}/sops.key
${{ secrets.SOPS_KEY }}
EOF
echo "GOOGLE_APPLICATION_CREDENTIALS=${HOME}/sops.key" >> $GITHUB_ENV
- name: Install Helm
if: ${{ env.DEPLOY }}
run: |
curl -L https://get.helm.sh/helm-v3.13.3-linux-amd64.tar.gz | tar -xzf -
mv linux-amd64/helm /usr/local/bin
helm repo add jupyterhub https://jupyterhub.github.io/helm-chart/
helm repo update
- name: Deploy hubs to prod
if: ${{ env.DEPLOY }}
run: |
for hub in $(echo -e "${{ env.DEPLOY_HUBS }}"); do
echo "Deploying $hub to prod"
echo "hubploy --debug deploy $hub hub prod"
done
41 changes: 23 additions & 18 deletions .github/workflows/deploy-jupyterhub-base-images.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: Deploy base hub images to staging
# if the PR labels "hub-images" or "jupyterhub-deployment" are present, this
# means the base hub image has changed, and all hubs (staging or prod) need to
# be redeployed.
#
name: Deploy base hub images to all hubs in staging and prod
on:
workflow_dispatch:
push:
Expand All @@ -17,11 +21,6 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check out the image repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.

- name: Pull out any hubs that need deploying from the labels on the merge commit to staging
run: |
echo "PR labels: ${{ steps.pr-labels.outputs.labels }}"
Expand All @@ -30,12 +29,18 @@ jobs:
echo "DEPLOY=1" >> $GITHUB_ENV
fi
done
if [[ -n "${DEPLOY}" ]]; then
echo "Deploying base hub images to all deployments"
if [[ -n "${{ env.DEPLOY }}" ]]; then
echo "Deploying base hub images to all deployments on staging"
else
echo "No hub images to deploy"
echo "No hub images to deploy to staging"
fi
- name: Check out the image repo
if: ${{ env.DEPLOY }}
uses: actions/checkout@v4
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.

- name: Setup python
if: ${{ env.DEPLOY }}
uses: actions/setup-python@v5
Expand Down Expand Up @@ -89,7 +94,7 @@ jobs:
- name: Deploy base hub images to staging
if: ${{ env.DEPLOY }}
run: |
ignored_directories=("template") # these are directories that we never want to deploy to
ignored_directories=("template") # these are directories that we never want to deploy
while read deployment; do
for ignored in "${ignored_directories[@]}"; do
if [[ "${deployment}" == "${ignored}" ]]; then
Expand All @@ -110,11 +115,6 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check out the image repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.

- name: Pull out any hubs that need deploying from the labels on the merge commit to prod
run: |
echo "PR labels: ${{ steps.pr-labels.outputs.labels }}"
Expand All @@ -123,12 +123,17 @@ jobs:
echo "DEPLOY=1" >> $GITHUB_ENV
fi
done
if [[ -n "${DEPLOY}" ]]; then
echo "Deploying base hub images to all deployments"
if [[ -n "${{ env.DEPLOY }}" ]]; then
echo "Deploying base hub images to all deployments to prod"
else
echo "No hub images to deploy"
fi
- name: Check out the image repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.

- name: Setup python
if: ${{ env.DEPLOY }}
uses: actions/setup-python@v5
Expand Down Expand Up @@ -182,7 +187,7 @@ jobs:
- name: Deploy base hub images to prod
if: ${{ env.DEPLOY }}
run: |
ignored_directories=("template") # these are directories that we never want to deploy to
ignored_directories=("template") # these are directories that we never want to deploy
while read deployment; do
for ignored in "${ignored_directories[@]}"; do
if [[ "${deployment}" == "${ignored}" ]]; then
Expand Down
94 changes: 0 additions & 94 deletions .github/workflows/deploy-to-prod.yaml.disabled

This file was deleted.

Loading

0 comments on commit 522bb9e

Please sign in to comment.