diff --git a/cloudbuild/Dockerfile b/cloudbuild/Dockerfile index e191e8cf5..39ce55ec5 100644 --- a/cloudbuild/Dockerfile +++ b/cloudbuild/Dockerfile @@ -11,6 +11,6 @@ COPY --chown=ia-tests:ia-tests . /init-actions # https://docs.bazel.build/versions/master/install-ubuntu.html RUN echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list RUN curl https://bazel.build/bazel-release.pub.gpg | apt-key add - -RUN apt-get update && apt-get install -y openjdk-8-jdk python3-setuptools bazel +RUN apt-get update && apt-get install -y openjdk-8-jdk python3-setuptools bazel gettext-base USER ia-tests diff --git a/cloudbuild/cloudbuild.yaml b/cloudbuild/cloudbuild.yaml index c3ac41836..e8d671d8b 100644 --- a/cloudbuild/cloudbuild.yaml +++ b/cloudbuild/cloudbuild.yaml @@ -9,39 +9,39 @@ steps: id: 'gcr-push' args: ['push', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID'] - # Run presubmit tests in parallel for 1.5 Debian image - - name: 'gcr.io/cloud-builders/kubectl' - id: 'dataproc-1.5-debian10-tests' - waitFor: ['gcr-push'] - entrypoint: 'bash' - args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '1.5-debian10'] - env: - - 'COMMIT_SHA=$COMMIT_SHA' - - 'CLOUDSDK_COMPUTE_REGION=us-central1' - - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' - - # Run presubmit tests in parallel for 1.5 Rocky Linux image - - name: 'gcr.io/cloud-builders/kubectl' - id: 'dataproc-1.5-rocky8-tests' - waitFor: ['gcr-push'] - entrypoint: 'bash' - args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '1.5-rocky8'] - env: - - 'COMMIT_SHA=$COMMIT_SHA' - - 'CLOUDSDK_COMPUTE_REGION=us-central1' - - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' - - # Run presubmit tests in parallel for 1.5 Ubuntu image - - name: 'gcr.io/cloud-builders/kubectl' - id: 'dataproc-1.5-ubuntu18-tests' - waitFor: ['gcr-push'] - entrypoint: 'bash' - args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '1.5-ubuntu18'] - env: - - 'COMMIT_SHA=$COMMIT_SHA' - - 'CLOUDSDK_COMPUTE_REGION=us-central1' - - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' - +# # Run presubmit tests in parallel for 1.5 Debian image +# - name: 'gcr.io/cloud-builders/kubectl' +# id: 'dataproc-1.5-debian10-tests' +# waitFor: ['gcr-push'] +# entrypoint: 'bash' +# args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '1.5-debian10'] +# env: +# - 'COMMIT_SHA=$COMMIT_SHA' +# - 'CLOUDSDK_COMPUTE_REGION=us-central1' +# - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' +# +# # Run presubmit tests in parallel for 1.5 Rocky Linux image +# - name: 'gcr.io/cloud-builders/kubectl' +# id: 'dataproc-1.5-rocky8-tests' +# waitFor: ['gcr-push'] +# entrypoint: 'bash' +# args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '1.5-rocky8'] +# env: +# - 'COMMIT_SHA=$COMMIT_SHA' +# - 'CLOUDSDK_COMPUTE_REGION=us-central1' +# - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' +# +# # Run presubmit tests in parallel for 1.5 Ubuntu image +# - name: 'gcr.io/cloud-builders/kubectl' +# id: 'dataproc-1.5-ubuntu18-tests' +# waitFor: ['gcr-push'] +# entrypoint: 'bash' +# args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '1.5-ubuntu18'] +# env: +# - 'COMMIT_SHA=$COMMIT_SHA' +# - 'CLOUDSDK_COMPUTE_REGION=us-central1' +# - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' +# # Run presubmit tests in parallel for 2.0 Debian image - name: 'gcr.io/cloud-builders/kubectl' id: 'dataproc-2.0-debian10-tests' @@ -53,60 +53,60 @@ steps: - 'CLOUDSDK_COMPUTE_REGION=us-central1' - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' - # Run presubmit tests in parallel for 2.0 Rocky Linux image - - name: 'gcr.io/cloud-builders/kubectl' - id: 'dataproc-2.0-rocky8-tests' - waitFor: ['gcr-push'] - entrypoint: 'bash' - args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '2.0-rocky8'] - env: - - 'COMMIT_SHA=$COMMIT_SHA' - - 'CLOUDSDK_COMPUTE_REGION=us-central1' - - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' - - # Run presubmit tests in parallel for 2.0 Ubuntu image - - name: 'gcr.io/cloud-builders/kubectl' - id: 'dataproc-2.0-ubuntu18-tests' - waitFor: ['gcr-push'] - entrypoint: 'bash' - args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '2.0-ubuntu18'] - env: - - 'COMMIT_SHA=$COMMIT_SHA' - - 'CLOUDSDK_COMPUTE_REGION=us-central1' - - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' - -# Run presubmit tests in parallel for 2.1 Debian image - - name: 'gcr.io/cloud-builders/kubectl' - id: 'dataproc-2.1-debian11-tests' - waitFor: ['gcr-push'] - entrypoint: 'bash' - args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '2.1-debian11'] - env: - - 'COMMIT_SHA=$COMMIT_SHA' - - 'CLOUDSDK_COMPUTE_REGION=us-central1' - - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' - -# Run presubmit tests in parallel for 2.1 Rocky Linux image - - name: 'gcr.io/cloud-builders/kubectl' - id: 'dataproc-2.1-rocky8-tests' - waitFor: ['gcr-push'] - entrypoint: 'bash' - args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '2.1-rocky8'] - env: - - 'COMMIT_SHA=$COMMIT_SHA' - - 'CLOUDSDK_COMPUTE_REGION=us-central1' - - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' - -# Run presubmit tests in parallel for 2.1 Ubuntu image - - name: 'gcr.io/cloud-builders/kubectl' - id: 'dataproc-2.1-ubuntu20-tests' - waitFor: ['gcr-push'] - entrypoint: 'bash' - args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '2.1-ubuntu20'] - env: - - 'COMMIT_SHA=$COMMIT_SHA' - - 'CLOUDSDK_COMPUTE_REGION=us-central1' - - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' +# # Run presubmit tests in parallel for 2.0 Rocky Linux image +# - name: 'gcr.io/cloud-builders/kubectl' +# id: 'dataproc-2.0-rocky8-tests' +# waitFor: ['gcr-push'] +# entrypoint: 'bash' +# args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '2.0-rocky8'] +# env: +# - 'COMMIT_SHA=$COMMIT_SHA' +# - 'CLOUDSDK_COMPUTE_REGION=us-central1' +# - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' +# +# # Run presubmit tests in parallel for 2.0 Ubuntu image +# - name: 'gcr.io/cloud-builders/kubectl' +# id: 'dataproc-2.0-ubuntu18-tests' +# waitFor: ['gcr-push'] +# entrypoint: 'bash' +# args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '2.0-ubuntu18'] +# env: +# - 'COMMIT_SHA=$COMMIT_SHA' +# - 'CLOUDSDK_COMPUTE_REGION=us-central1' +# - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' +# +## Run presubmit tests in parallel for 2.1 Debian image +# - name: 'gcr.io/cloud-builders/kubectl' +# id: 'dataproc-2.1-debian11-tests' +# waitFor: ['gcr-push'] +# entrypoint: 'bash' +# args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '2.1-debian11'] +# env: +# - 'COMMIT_SHA=$COMMIT_SHA' +# - 'CLOUDSDK_COMPUTE_REGION=us-central1' +# - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' +# +## Run presubmit tests in parallel for 2.1 Rocky Linux image +# - name: 'gcr.io/cloud-builders/kubectl' +# id: 'dataproc-2.1-rocky8-tests' +# waitFor: ['gcr-push'] +# entrypoint: 'bash' +# args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '2.1-rocky8'] +# env: +# - 'COMMIT_SHA=$COMMIT_SHA' +# - 'CLOUDSDK_COMPUTE_REGION=us-central1' +# - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' +# +## Run presubmit tests in parallel for 2.1 Ubuntu image +# - name: 'gcr.io/cloud-builders/kubectl' +# id: 'dataproc-2.1-ubuntu20-tests' +# waitFor: ['gcr-push'] +# entrypoint: 'bash' +# args: ['cloudbuild/run-presubmit-on-k8s.sh', 'gcr.io/$PROJECT_ID/init-actions-image:$BUILD_ID', '$BUILD_ID', '2.1-ubuntu20'] +# env: +# - 'COMMIT_SHA=$COMMIT_SHA' +# - 'CLOUDSDK_COMPUTE_REGION=us-central1' +# - 'CLOUDSDK_CONTAINER_CLUSTER=init-actions-presubmit' # Delete Docker image from GCR - name: 'gcr.io/cloud-builders/gcloud' diff --git a/cloudbuild/deployment.yaml b/cloudbuild/deployment.yaml new file mode 100644 index 000000000..fed57c233 --- /dev/null +++ b/cloudbuild/deployment.yaml @@ -0,0 +1,37 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + run: {{IMAGE_NAME}} + name: {{IMAGE_NAME}} + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: {{IMAGE_NAME}} + template: + metadata: + labels: + app: {{IMAGE_NAME}} + spec: + containers: + - command: + - bash + - /init-actions/cloudbuild/presubmit.sh + env: + - name: COMMIT_SHA + value: {{COMMIT_SHA}} + - name: IMAGE_VERSION + value: {{IMAGE_VERSION}} + name: {{IMAGE_NAME}} + image: {{IMAGE_BUILD_ID}} + resources: + limits: + cpu: 500m + ephemeral-storage: 1Gi + memory: 2Gi + requests: + cpu: 500m + ephemeral-storage: 1Gi + memory: 2Gi \ No newline at end of file diff --git a/cloudbuild/run-presubmit-on-k8s.sh b/cloudbuild/run-presubmit-on-k8s.sh index 26429bb51..9302b3cb9 100644 --- a/cloudbuild/run-presubmit-on-k8s.sh +++ b/cloudbuild/run-presubmit-on-k8s.sh @@ -12,13 +12,22 @@ gcloud container clusters get-credentials "${CLOUDSDK_CONTAINER_CLUSTER}" LOGS_SINCE_TIME=$(date --iso-8601=seconds) -kubectl run "${POD_NAME}" \ - --image="${IMAGE}" \ - --requests='cpu=750m,memory=2Gi,ephemeral-storage=2Gi' \ - --restart=Never \ - --env="COMMIT_SHA=${COMMIT_SHA}" \ - --env="IMAGE_VERSION=${DATAPROC_IMAGE_VERSION}" \ - --command -- bash /init-actions/cloudbuild/presubmit.sh +#kubectl run "${POD_NAME}" \ +# --image="${IMAGE}" \ +# --restart=Never \ +# --env="COMMIT_SHA=${COMMIT_SHA}" \ +# --env="IMAGE_VERSION=${DATAPROC_IMAGE_VERSION}" \ +# --command -- bash /init-actions/cloudbuild/presubmit.sh +export IMAGE_NAME=${POD_NAME} +export COMMIT_SHA=${COMMIT_SHA} +export IMAGE_VERSION=${DATAPROC_IMAGE_VERSION} +export IMAGE_BUILD_ID=${BUILD_ID} +export IMAGE_BUILD_ID=gcr.io/cloud-dataproc-ci/init-actions-image:${BUILD_ID} + +template=`cat cloudbuild/deployment.yaml | sed "s/{{IMAGE_NAME}}/${IMAGE_NAME}/g;s/{{COMMIT_SHA}}/${COMMIT_SHA}/g;s/{{IMAGE_VERSION}}/${IMAGE_VERSION}/g;s|{{IMAGE_BUILD_ID}}|${IMAGE_BUILD_ID}|g" ` +echo "$template" + +echo "$template" | kubectl apply -f - # Delete POD on exit and describe it before deletion if exit was unsuccessful trap '[[ $? != 0 ]] && kubectl describe "pod/${POD_NAME}"; kubectl delete pods "${POD_NAME}"' EXIT @@ -30,6 +39,7 @@ while ! kubectl describe "pod/${POD_NAME}" | grep -q Terminated; do LOGS_SINCE_TIME=$(date --iso-8601=seconds) done + EXIT_CODE=$(kubectl get pod "${POD_NAME}" \ -o go-template="{{range .status.containerStatuses}}{{.state.terminated.exitCode}}{{end}}")