build-deploy-pudl #596
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build-deploy-pudl | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- "v20*" | |
schedule: | |
- cron: "0 6 * * 1-5" # Weekdays at midnight on MST | |
env: | |
GCP_BILLING_PROJECT: ${{ secrets.GCP_BILLING_PROJECT }} | |
BUILD_REF: ${{ github.ref_name }} # This is changed to dev if running on a schedule | |
GCE_INSTANCE: pudl-deployment-tag # This is changed to pudl-deployment-dev if running on a schedule | |
GCE_INSTANCE_ZONE: ${{ secrets.GCE_INSTANCE_ZONE }} | |
GCS_OUTPUT_BUCKET: gs://nightly-build-outputs.catalyst.coop | |
jobs: | |
build_and_deploy_pudl: | |
name: Build Docker image, push to Docker Hub and deploy to a GCE VM | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
id-token: write | |
steps: | |
- name: Use pudl-deployment-dev vm and dev branch if running on a schedule | |
if: ${{ (github.event_name == 'schedule') }} | |
run: | | |
echo "This action was triggered by a schedule." | |
echo "GCE_INSTANCE=pudl-deployment-dev" >> $GITHUB_ENV | |
echo "BUILD_REF=dev" >> $GITHUB_ENV | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.BUILD_REF }} | |
- name: Set action environment variables | |
run: | | |
echo "NIGHTLY_TAG=nightly-$(date +%Y-%m-%d)" >> $GITHUB_ENV | |
echo "BUILD_ID=$(date +%Y-%m-%d-%H%M)-$(git rev-parse --short HEAD)-${BUILD_REF}" >> $GITHUB_ENV | |
- name: Show freshly set envvars | |
run: | | |
echo "GCE_INSTANCE: $GCE_INSTANCE" | |
echo "BUILD_REF: $BUILD_REF" | |
echo "NIGHTLY_TAG: $NIGHTLY_TAG" | |
echo "BUILD_ID: $BUILD_ID" | |
- name: Tag nightly build | |
# TESTING -- SHOULD ONLY RUN ON SCHEDULE | |
if: ${{ (github.event_name == 'schedule') || (github.event_name == 'workflow_dispatch') }} | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "pudlbot" | |
git tag -a -m "$NIGHTLY_TAG" $NIGHTLY_TAG $BUILD_REF | |
git push origin $NIGHTLY_TAG | |
- name: Docker Metadata | |
id: docker_metadata | |
uses: docker/metadata-action@v5 | |
with: | |
images: catalystcoop/pudl-etl | |
flavor: | | |
latest=auto | |
tags: | | |
type=raw,value=${{ env.BUILD_REF}} | |
type=ref,event=tag | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build image and push to Docker Hub | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: docker/Dockerfile | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.docker_metadata.outputs.tags }} | |
labels: ${{ steps.docker_metadata.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- id: "auth" | |
uses: "google-github-actions/auth@v2" | |
with: | |
workload_identity_provider: "projects/345950277072/locations/global/workloadIdentityPools/gh-actions-pool/providers/gh-actions-provider" | |
service_account: "deploy-pudl-github-action@catalyst-cooperative-pudl.iam.gserviceaccount.com" | |
# Setup gcloud CLI | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 |