From 6bce047d31eca61f5d20e38adad3514a45aff104 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Wed, 4 Dec 2024 14:04:05 +0000 Subject: [PATCH] Just publish image for now --- ...ockerfile => build_and_publish.Dockerfile} | 0 .github/build_and_publish/cloudbuild.yaml | 70 ------------------- .github/workflows/pull_request.yaml | 19 +++-- 3 files changed, 9 insertions(+), 80 deletions(-) rename .github/{build_and_publish/Dockerfile => build_and_publish.Dockerfile} (100%) delete mode 100644 .github/build_and_publish/cloudbuild.yaml diff --git a/.github/build_and_publish/Dockerfile b/.github/build_and_publish.Dockerfile similarity index 100% rename from .github/build_and_publish/Dockerfile rename to .github/build_and_publish.Dockerfile diff --git a/.github/build_and_publish/cloudbuild.yaml b/.github/build_and_publish/cloudbuild.yaml deleted file mode 100644 index 2decca2..0000000 --- a/.github/build_and_publish/cloudbuild.yaml +++ /dev/null @@ -1,70 +0,0 @@ -steps: -# Build the Docker image -- name: 'gcr.io/cloud-builders/docker' - args: [ - 'build', - '-t', '${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_REPOSITORY_NAME}/${_IMAGE_NAME}:${_TAG}', - '-f', '.github/build_and_publish/Dockerfile', - '.' - ] - -# Push the image to Artifact Registry -- name: 'gcr.io/cloud-builders/docker' - args: [ - 'push', - '${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_REPOSITORY_NAME}/${_IMAGE_NAME}:${_TAG}' - ] - -# Deploy to Cloud Run jobs -- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' - entrypoint: 'gcloud' - args: [ - 'beta', 'run', 'jobs', 'update', '${_JOB_NAME}', - '--image', '${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_REPOSITORY_NAME}/${_IMAGE_NAME}:${_TAG}', - '--region', '${_REGION}', - '--cpu', '${_CPU}', - '--memory', '${_MEMORY}', - '--tasks', '1', - '--max-retries', '3', - '--set-env-vars', 'FOO=bar', # Add your environment variables here - '--service-account', '${_SERVICE_ACCOUNT}' - ] - -# If the job doesn't exist, create it -- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' - entrypoint: 'bash' - args: - - '-c' - - | - if ! gcloud beta run jobs describe ${_JOB_NAME} --region ${_REGION} > /dev/null 2>&1; then - gcloud beta run jobs create ${_JOB_NAME} \ - --image ${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_REPOSITORY_NAME}/${_IMAGE_NAME}:${_TAG} \ - --region ${_REGION} \ - --cpu ${_CPU} \ - --memory ${_MEMORY} \ - --tasks 1 \ - --max-retries 3 \ - --set-env-vars FOO=bar \ - --service-account ${_SERVICE_ACCOUNT} - fi - -# Optional: Execute the job immediately after deployment -- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' - entrypoint: 'gcloud' - args: [ - 'beta', 'run', 'jobs', 'execute', '${_JOB_NAME}', - '--region', '${_REGION}' - ] - -substitutions: - _REGION: 'us-central1' # Default region - _REPOSITORY_NAME: 'policyengine-research' # Your Artifact Registry repository name - _IMAGE_NAME: 'build-and-publish' # Your image name - _TAG: 'latest' # Image tag - _JOB_NAME: 'build-and-publish-us-data' # Cloud Run job name - _CPU: '1' # Number of CPUs - _MEMORY: '2Gi' # Memory allocation - _SERVICE_ACCOUNT: 'policyengine-research@policyengine-research.iam.gserviceaccount.com' - -options: - logging: CLOUD_LOGGING_ONLY \ No newline at end of file diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 9a12308..9c8febd 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -42,19 +42,18 @@ jobs: fetch-depth: 0 repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.event.pull_request.head.ref }} + + # Build dockerfile in .github/build_and_publish.Dockerfile and publish to ghcr + - name: Build and push deployment image + uses: docker/build-push-action@v2 + with: + context: .github + file: .github/build_and_publish.Dockerfile + push: true + tags: ghcr.io/policyengine/policyengine-us-data/build-and-publish:latest - name: GCP authentication uses: "google-github-actions/auth@v2" with: credentials_json: "${{ secrets.GCP_POLICYENGINE_RESEARCH_SA_TOKEN }}" project_id: policyengine-research - - - name: Set up Cloud SDK - uses: google-github-actions/setup-gcloud@v2 - - - name: Build and push to Cloud Build - run: | - gcloud builds submit \ - --config=.github/build_and_publish/cloudbuild.yaml - env: - PROJECT_ID: policyengine-research