# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: [
    'build',
    '--tag=${_FLEX_TEMPLATE_IMAGE_TAG}',
    '--build-arg=ARG_PIP_INDEX_URL=${_PIP_INDEX_URL}',
    '.'
    ]
- name: 'gcr.io/cloud-builders/docker'
  args: ['push', '${_FLEX_TEMPLATE_IMAGE_TAG}']
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
  entrypoint: 'gcloud'
  args: [
    'dataflow', 'flex-template', 'build', '${_TEMPLATE_GS_PATH}',
    '--image', '${_FLEX_TEMPLATE_IMAGE_TAG}',
    '--sdk-language', 'PYTHON',
    '--project', '${_PROJECT}',
    '--metadata-file', './metadata.json',
    ]
images: ['${_FLEX_TEMPLATE_IMAGE_TAG}']
substitutions:
  _PROJECT: 'PROJECT'
  _FLEX_TEMPLATE_IMAGE_TAG: 'us-east4-docker.pkg.dev/PROJECT_ID/flex-templates/samples/regional_dlp_flex:latest' # default value
  _TEMPLATE_GS_PATH: 'gs://BUCKET/flex-template-samples/regional_dlp_flex.json'
  _PIP_INDEX_URL: 'https://us-east4-python.pkg.dev/PROJECT_ID/python-modules/simple/'
options:
  logging: CLOUD_LOGGING_ONLY
timeout: 900s
