Merge "cos-gpu-installer: Add release script"
diff --git a/src/cmd/cos_gpu_installer/README.md b/src/cmd/cos_gpu_installer/README.md
new file mode 100644
index 0000000..0672495
--- /dev/null
+++ b/src/cmd/cos_gpu_installer/README.md
@@ -0,0 +1,37 @@
+# COS GPU installer V2
+
+cos\_gpu\_installer is a docker containers that can be used to download,
+compile and install GPU drivers on Container-Optimized OS images.
+
+## Usage
+
+cos\_gpu\_installer should run on COS VM instances. Once you connect to your
+COS VM, run the following command to start a cos\_gpu\_installer container:
+```
+  /usr/bin/docker run --rm \
+    --name="cos-gpu-installer" \
+    --privileged \
+    --net=host \
+    --pid=host \
+    --volume /dev:/dev \
+    --volume /:/root \
+    "gcr.io/cos-cloud/cos-gpu-installer:v2" install
+```
+
+To see all available flags, run the following command:
+
+```
+/usr/bin/docker run --rm "gcr.io/cos-cloud/cos-gpu-installer:v2" help
+```
+
+## Build and Release
+Run the following script to build a cos\_gpu\_installer container image through
+Google Cloud Build and save the image to GCR:
+
+```
+src/cmd/cos_gpu_installer/release/build_and_release.sh <GCR-project> <image-tag>
+```
+
+## Test
+
+Currently only unittest is available. Use `go test` to run unittest.
diff --git a/src/cmd/cos_gpu_installer/release/Dockerfile b/src/cmd/cos_gpu_installer/release/Dockerfile
new file mode 100644
index 0000000..ff50c1f
--- /dev/null
+++ b/src/cmd/cos_gpu_installer/release/Dockerfile
@@ -0,0 +1,15 @@
+# Dockerfile for the COS GPU Installer container.
+
+FROM debian:9
+LABEL maintainer="cos-containers@google.com"
+
+# Install minimal tools needed to build kernel modules.
+RUN apt-get update -qq && \
+    apt-get install -y xz-utils kmod git make bc curl ccache \
+    libc6-dev pciutils gcc libelf-dev libssl-dev bison flex keyutils python2.7-minimal && \
+    rm -rf /var/lib/apt/lists/* && \
+    # x86_64-cros-linux-gnu-clang depends on /usr/bin/python2
+    ln -s /usr/bin/python2.7 /usr/bin/python2
+
+COPY cos-gpu-installer /cos-gpu-installer
+ENTRYPOINT ["/cos-gpu-installer"]
diff --git a/src/cmd/cos_gpu_installer/release/build_and_release.sh b/src/cmd/cos_gpu_installer/release/build_and_release.sh
new file mode 100755
index 0000000..838b513
--- /dev/null
+++ b/src/cmd/cos_gpu_installer/release/build_and_release.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# Script to build and release cos-gpu-installer to GCR.
+#
+# Usage: ./build_and_release.sh <project_id> <tag>
+#
+# Example: ./build_and_release.sh cos-cloud v2.0.1
+
+set -o errexit
+set -o pipefail
+set -o nounset
+
+SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
+
+build() {
+  pushd "$(dirname "${SCRIPTDIR}")"
+  go build -o release/cos-gpu-installer main.go
+  popd
+}
+
+release() {
+  project_id="$1"
+  tag="$2"
+  pushd "${SCRIPTDIR}"
+  gcloud builds submit . --config cloud_build_request.yaml --substitutions _PROJECT_ID="${project_id}",TAG_NAME="${tag}"
+  rm cos-gpu-installer
+  popd
+}
+
+main() {
+  build
+  release "$@"
+}
+
+main "$@"
diff --git a/src/cmd/cos_gpu_installer/release/cloud_build_request.yaml b/src/cmd/cos_gpu_installer/release/cloud_build_request.yaml
new file mode 100644
index 0000000..71432f6
--- /dev/null
+++ b/src/cmd/cos_gpu_installer/release/cloud_build_request.yaml
@@ -0,0 +1,15 @@
+# GCP Cloud Build request in YAML format.
+# See https://cloud.google.com/cloud-build/docs for details.
+
+steps:
+- name: 'gcr.io/cloud-builders/docker'
+  args:
+  - 'build'
+  - '-t'
+  - 'gcr.io/${_PROJECT_ID}/cos-gpu-installer:latest'
+  - '-t'
+  - 'gcr.io/${_PROJECT_ID}/cos-gpu-installer:${TAG_NAME}'
+  - './'
+images:
+- 'gcr.io/${_PROJECT_ID}/cos-gpu-installer:latest'
+- 'gcr.io/${_PROJECT_ID}/cos-gpu-installer:${TAG_NAME}'