Skip to content

Commit

Permalink
Merge pull request #672 from danistrebel/feature/ci-improvements
Browse files Browse the repository at this point in the history
ci: pipeline using kaniko builds
  • Loading branch information
danistrebel authored May 24, 2023
2 parents a9ce759 + 9f4011a commit 4d0c496
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 41 deletions.
2 changes: 1 addition & 1 deletion tools/pipeline-runner/cloud-logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Helper utility to publish the pipeline build results as
# log entries in cloud logging

cat | jq -Rsn --arg RUN_TYPE "$_RUN_TYPE" --arg BUILD_ID "$BUILD_ID" '
cat | jq -Rsn --arg RUN_TYPE "$RUN_TYPE" --arg BUILD_ID "$BUILD_ID" '
[inputs
| . / "\n"
| (.[] | select(length > 0) | . / ";") as $input
Expand Down
77 changes: 37 additions & 40 deletions tools/pipeline-runner/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,19 @@ steps:
echo "Pipeline is already running";
exit -1;
fi
- name: 'gcr.io/cloud-builders/docker'
id: 'Pull Image Cache'
entrypoint: 'bash'
args: ['-c', 'docker pull gcr.io/$PROJECT_ID/devrel-pipeline:latest || exit 0']
- name: 'gcr.io/cloud-builders/docker'
id: 'Build Image'
- name: 'gcr.io/kaniko-project/executor:latest'
id: 'Build Pipeline Runner Image'
args:
- 'build'
- '-f'
- './tools/pipeline-runner/Dockerfile'
- '-t'
- 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
- '--cache-from'
- 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
- './tools/pipeline-runner'
- name: 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
- --dockerfile=./tools/pipeline-runner/Dockerfile
- --context=./tools/pipeline-runner
- --destination=${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest
- --cache=true
- --cache-ttl=12h
- name: '${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest'
id: 'Cleanup Org'
entrypoint: "bash"
entrypoint: 'bash'
args:
- "-c"
- '-c'
- |-
if [ "$_CLEAN_ORG" = "true" ]; then
APIGEE_TOKEN=$(gcloud auth print-access-token)
Expand All @@ -57,11 +50,11 @@ steps:
secretEnv:
- 'APIGEE_USER'
- 'APIGEE_PASS'
- name: 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
- name: '${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest'
id: 'Run Pipeline'
entrypoint: "bash"
entrypoint: 'bash'
args:
- "-c"
- '-c'
- |-
max_duration=8760 # cloud build timeout minus 4m
if [ -n "$_PR_NUMBER" ]; then
Expand Down Expand Up @@ -98,20 +91,23 @@ steps:
secretEnv:
- 'APIGEE_USER'
- 'APIGEE_PASS'
- name: 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
- name: '${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest'
id: 'Write pipeline results to cloud logging'
entrypoint: "bash"
entrypoint: 'sh'
args:
- "-c"
- '-c'
- |-
cat ./pipeline-result.txt | cloud-logging.sh
- name: 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
cat ./pipeline-result.txt | ./tools/pipeline-runner/cloud-logging.sh
env:
- 'RUN_TYPE=$_RUN_TYPE'
- 'BUILD_ID=$BUILD_ID'
- name: '${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest'
id: 'Create GH Comment or Issue'
entrypoint: "bash"
entrypoint: 'sh'
args:
- "-c"
- '-c'
- |-
cat ./pipeline-result.txt | github-api.sh
cat ./pipeline-result.txt | ./tools/pipeline-runner/github-api.sh
env:
- 'BUILD_ID=$BUILD_ID'
- 'PROJECT_ID=$PROJECT_ID'
Expand All @@ -122,13 +118,13 @@ steps:
- 'GH_BOT_NAME=$_GH_BOT_NAME'
secretEnv:
- 'GITHUB_TOKEN'
- name: 'gcr.io/$PROJECT_ID/devrel-pipeline:latest'
- name: '${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline:latest'
id: 'Explicitly Fail'
entrypoint: "bash"
entrypoint: 'sh'
args:
- "-c"
- '-c'
- |-
! grep -q "fail" ./pipeline-result.txt
! grep -q 'fail' ./pipeline-result.txt
availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/devrel_apigee_pass/versions/latest
Expand All @@ -141,7 +137,7 @@ options:
machineType: 'E2_HIGHCPU_8'
logging: GCS_ONLY
timeout: 9000s # 120min (needs to be updated with max_duration of pipeline)
images: ['gcr.io/$PROJECT_ID/devrel-pipeline:latest']
images: ['${_REGISTRY_LOCATION}-docker.pkg.dev/$PROJECT_ID/devrel/devrel-pipeline']
substitutions:
_APIGEE_ORG: my-org
_APIGEE_ENV: my-env
Expand All @@ -150,10 +146,11 @@ substitutions:
_APIGEE_X_HOSTNAME: my-hostname
_HYBRID_GCP_PROJECT: my-gcp-project
_X_TRIAL_GCP_PROJECT: my-gcp-project
_CI_PROJECT: "all" # all|[path]
_CLEAN_ORG: "true" # true|false
_CREATE_GH_ISSUE: "false" # true|false
_REPO_GH_ISSUE: "apigee/devrel"
_GH_BOT_NAME: "apigee-devrel-bot"
_RUN_TYPE: "unknown"
#_PR_NUMBER: "" # automatically set for PRs
_CI_PROJECT: all # all|[path]
_CLEAN_ORG: 'true' # true|false
_CREATE_GH_ISSUE: 'false' # true|false
_REPO_GH_ISSUE: 'apigee/devrel'
_GH_BOT_NAME: 'apigee-devrel-bot'
_REGISTRY_LOCATION: europe
_RUN_TYPE: unknown
#_PR_NUMBER: '' # automatically set for PRs

0 comments on commit 4d0c496

Please sign in to comment.