Allow CI to run concurrent builds in master (#4001)

* Allow CI to run concurrent builds in master

Fixes #3911

Refactors the `cloud_integration` test to run in separate GKE clusters
that are created and torn down on the fly.
It leverages a new "gcloud" github action that is also used to set up
gcloud in other build steps (`docker_deploy` and `chart_deploy`).

The action also generates unique names for those clusters, based on the
git commit SHA and `run_id`, a recently introduced variable that is
unique per CI run and available to all the jobs.
This fixes part of #3635 in that CI runs on the same SHA don't interfere
with one another (in the `cloud_integration` test; still to do for
`kind_integration`).

The "gcloud" GH action is hosted under its own repo in https://github.com/linkerd/linkerd2-action-gcloud
This commit is contained in:
Alejandro Pedraza 2020-02-07 16:23:36 -05:00 committed by GitHub
parent ae7d98b4fe
commit 1e8223e143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 142 deletions

View File

@ -34,7 +34,6 @@ on:
#
# -> docker_deploy
# -> cloud_integration
# -> cloud_cleanup
jobs:
@ -435,28 +434,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Configure gcloud
env:
CLOUDSDK_CORE_DISABLE_PROMPTS: "1"
CLOUD_SDK_SERVICE_ACCOUNT_KEY: ${{ secrets.CLOUD_SDK_SERVICE_ACCOUNT_KEY }}
GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
GCP_ZONE: ${{ secrets.GCP_ZONE }}
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }}
run: |
# Install gcloud and kubectl.
echo "$CLOUD_SDK_SERVICE_ACCOUNT_KEY" > .gcp.json
dir="${CLOUDSDK_INSTALL_DIR:-${HOME}}/google-cloud-sdk"
(
. bin/_gcp.sh ;
install_gcloud "$dir"
gcloud components install kubectl
# Configure gcloud with a service account.
set_gcloud_config "$GCP_PROJECT" "$GCP_ZONE" "$GKE_CLUSTER"
# Get a kubernetes context.
get_k8s_ctx "$GCP_PROJECT" "$GCP_ZONE" "$GKE_CLUSTER"
)
. "$dir/path.bash.inc"
gcloud auth configure-docker
bin/kubectl version --short
uses: linkerd/linkerd2-action-gcloud@v1.0.0
with:
cloud_sdk_service_account_key: ${{ secrets.CLOUD_SDK_SERVICE_ACCOUNT_KEY }}
gcp_project: ${{ secrets.GCP_PROJECT }}
gcp_zone: ${{ secrets.GCP_ZONE }}
- name: Docker SSH setup
run: |
mkdir -p ~/.ssh/
@ -484,30 +466,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Configure gcloud
env:
CLOUDSDK_CORE_DISABLE_PROMPTS: "1"
CLOUD_SDK_SERVICE_ACCOUNT_KEY: ${{ secrets.CLOUD_SDK_SERVICE_ACCOUNT_KEY }}
GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
GCP_ZONE: ${{ secrets.GCP_ZONE }}
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }}
run: |
# Install gcloud and kubectl.
echo "$CLOUD_SDK_SERVICE_ACCOUNT_KEY" > .gcp.json
dir="${CLOUDSDK_INSTALL_DIR:-${HOME}}/google-cloud-sdk"
(
. bin/_gcp.sh ;
install_gcloud "$dir"
gcloud components install kubectl
# Configure gcloud with a service account.
set_gcloud_config "$GCP_PROJECT" "$GCP_ZONE" "$GKE_CLUSTER"
# Get a kubernetes context.
get_k8s_ctx "$GCP_PROJECT" "$GCP_ZONE" "$GKE_CLUSTER"
)
. "$dir/path.bash.inc"
gcloud auth configure-docker
bin/kubectl version --short
- name: Install linkerd CLI
id: install_cli
run: |
TAG="$(CI_FORCE_CLEAN=1 bin/root-tag)"
image="gcr.io/linkerd-io/cli-bin:$TAG"
@ -517,6 +477,15 @@ jobs:
# validate CLI version matches the repo
[[ "$TAG" == "$($HOME/.linkerd version --short --client)" ]]
echo "Installed Linkerd CLI version: $TAG"
echo "::set-output name=tag::$TAG"
- name: Create GKE cluster
uses: linkerd/linkerd2-action-gcloud@v1.0.0
with:
cloud_sdk_service_account_key: ${{ secrets.CLOUD_SDK_SERVICE_ACCOUNT_KEY }}
gcp_project: ${{ secrets.GCP_PROJECT }}
gcp_zone: ${{ secrets.GCP_ZONE }}
create: true
name: testing-${{ steps.install_cli.outputs.tag }}-${{ github.run_id }}
- name: Run integration tests
env:
GITCOOKIE_SH: ${{ secrets.GITCOOKIE_SH }}
@ -530,42 +499,6 @@ jobs:
export TAG="$($HOME/.linkerd version --client --short)"
go test -cover -race -v -mod=readonly ./cni-plugin/test -integration-tests
cloud_cleanup:
if: always() && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags'))
name: Cloud cleanup
runs-on: ubuntu-18.04
needs: [cloud_integration]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Configure gcloud
env:
CLOUDSDK_CORE_DISABLE_PROMPTS: "1"
CLOUD_SDK_SERVICE_ACCOUNT_KEY: ${{ secrets.CLOUD_SDK_SERVICE_ACCOUNT_KEY }}
GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
GCP_ZONE: ${{ secrets.GCP_ZONE }}
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }}
run: |
# Install gcloud and kubectl.
echo "$CLOUD_SDK_SERVICE_ACCOUNT_KEY" > .gcp.json
dir="${CLOUDSDK_INSTALL_DIR:-${HOME}}/google-cloud-sdk"
(. bin/_gcp.sh ;
install_gcloud "$dir"
gcloud components install kubectl
# Configure gcloud with a service account.
set_gcloud_config "$GCP_PROJECT" "$GCP_ZONE" "$GKE_CLUSTER"
# Get a kubernetes context.
get_k8s_ctx "$GCP_PROJECT" "$GCP_ZONE" "$GKE_CLUSTER"
)
. "$dir/path.bash.inc"
gcloud auth configure-docker
bin/kubectl version --short
- name: Cleanup
run: |
export PATH="`pwd`/bin:$PATH"
bin/test-cleanup
#
# Helm chart artifact deploy run for:
# - every tag push
#
@ -579,34 +512,22 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Configure gsutils
env:
CLOUDSDK_CORE_DISABLE_PROMPTS: "1"
CLOUD_SDK_SERVICE_ACCOUNT_KEY: ${{ secrets.LINKERD_SITE_TOKEN }}
GCP_PROJECT: ${{ secrets.LINKERD_SITE_PROJECT }}
GCP_ZONE: ${{ secrets.LINKERD_SITE_ZONE }}
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }}
run: |
# Install gcloud and gsutil.
echo "$CLOUD_SDK_SERVICE_ACCOUNT_KEY" > .gcp.json
dir="${CLOUDSDK_INSTALL_DIR:-${HOME}}/google-cloud-sdk"
(
. bin/_gcp.sh ;
install_gcloud "$dir"
gcloud components install gsutil
# Configure gcloud with a service account.
set_gcloud_config "$GCP_PROJECT" "$GCP_ZONE" "$GKE_CLUSTER"
)
. "$dir/path.bash.inc"
mkdir -p target/helm
uses: linkerd/linkerd2-action-gcloud@v1.0.0
with:
cloud_sdk_service_account_key: ${{ secrets.CLOUD_SDK_SERVICE_ACCOUNT_KEY }}
gcp_project: ${{ secrets.GCP_PROJECT }}
gcp_zone: ${{ secrets.GCP_ZONE }}
- name: Edge Helm chart creation and upload
if: startsWith(github.ref, 'refs/tags/edge')
run: |
mkdir -p target/helm
gsutil cp gs://helm.linkerd.io/edge/index.yaml target/helm/index-pre.yaml
bin/helm-build package
gsutil rsync target/helm gs://helm.linkerd.io/edge
- name: Stable Helm chart creation and upload
if: startsWith(github.ref, 'refs/tags/stable')
run: |
mkdir -p target/helm
gsutil cp gs://helm.linkerd.io/stable/index.yaml target/helm/index-pre.yaml
bin/helm-build package
gsutil rsync target/helm gs://helm.linkerd.io/stable

2
.gitignore vendored
View File

@ -6,7 +6,7 @@ tmp.discovery
**/CMakeLists.txt
*.iml
web/web
web/app/node_modules
**/node_modules
web/app/dist
web/app/yarn-error.log
.gorun

View File

@ -1,40 +0,0 @@
set -eu
install_gcloud() {
dir="$1"
export CLOUDSDK_CORE_DISABLE_PROMPTS=1
if [ -d "$dir/bin" ]; then
. "$dir/path.bash.inc"
gcloud components update
else
rm -rf "$dir"
curl https://sdk.cloud.google.com | bash
. "$dir/path.bash.inc"
fi
}
set_gcloud_config() {
project="$1"
zone="$2"
cluster="$3"
gcloud auth activate-service-account --key-file .gcp.json
gcloud config set core/project "$project"
gcloud config set compute/zone "$zone"
gcloud config set container/cluster "$cluster"
}
get_k8s_ctx() {
project="$1"
zone="$2"
cluster="$3"
for c in $(kubectl config get-clusters |sed 1d) ; do
if [ "$c" = "gke_${project}_${zone}_${cluster}" ]; then
return 0
fi
done
gcloud container clusters get-credentials "$cluster"
}