Created
February 8, 2019 17:19
-
-
Save poy/63abaa5c2b710c84dbfb03be440c319e to your computer and use it in GitHub Desktop.
Push source code to GCS bucket and have knative build and deploy it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright 2019 Google LLC. | |
# SPDX-License-Identifier: Apache-2.0 | |
if [[ $# -ne 2 ]]; then | |
echo "Usage: $0 <Service Name> <Path>" | |
exit 1 | |
fi | |
service_name=$1 | |
path=$2 | |
docker_username=${DOCKER_USERNAME:?required} | |
bucket_name=source_code_$(date +%s)_$RANDOM | |
echo "Bucket Name: $bucket_name" | |
gsutil mb gs://$bucket_name | |
gsutil rsync $path gs://$bucket_name/ | |
gsutil acl ch -u AllUsers:R gs://$bucket_name | |
tmp_dir=$(mktemp -d) | |
trap "rm -rf $tmp_dir" EXIT | |
cat <<EOF > $tmp_dir/service.yaml | |
apiVersion: serving.knative.dev/v1alpha1 | |
kind: Service | |
metadata: | |
name: $service_name | |
namespace: default | |
spec: | |
runLatest: | |
configuration: | |
build: | |
apiVersion: build.knative.dev/v1alpha1 | |
kind: Build | |
spec: | |
serviceAccountName: build-bot | |
source: | |
custom: | |
image: gcr.io/cloud-builders/gsutil | |
args: ["rsync", "gs://$bucket_name/", "."] | |
template: | |
name: kaniko | |
arguments: | |
- name: IMAGE | |
value: docker.io/$docker_username/$service_name:latest | |
revisionTemplate: | |
spec: | |
container: | |
image: docker.io/$docker_username/$service_name:latest | |
imagePullPolicy: Always | |
env: | |
- name: SIMPLE_MSG | |
value: "Hello from the sample app!" | |
EOF | |
kubectl apply --filename $tmp_dir/service.yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment