From f33fb22842b72cb02b905fadd8e828675931265e Mon Sep 17 00:00:00 2001 From: Rachael Tamakloe Date: Fri, 8 Nov 2024 09:57:20 +0000 Subject: [PATCH 1/6] add dockerfile that downloads ctk and dependencies --- .../cluster-toolkit-dockerfile/Dockerfile | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile diff --git a/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile b/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile new file mode 100644 index 0000000000..c7d15f3ca3 --- /dev/null +++ b/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile @@ -0,0 +1,80 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Use a google-cloud-cli image as the base +ARG BASE_IMAGE=gcr.io/google.com/cloudsdktool/google-cloud-cli:stable +FROM ${BASE_IMAGE} + +# Install necessary tools and libraries +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg \ + lsb-release \ + git \ + make \ + unzip \ + wget \ + python3 \ + python3-pip \ + python3-venv + +# Install Terraform +ARG TERRAFORM_VERSION=1.5.2 +RUN wget -q "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -O terraform.zip && \ + unzip terraform.zip && \ + mv terraform /usr/local/bin/ && \ + rm terraform.zip + +# Install Packer +ARG PACKER_VERSION=1.8.6 +RUN wget -q "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip" -O packer.zip && \ + unzip packer.zip && \ + mv packer /usr/local/bin/ && \ + rm packer.zip + +# Install Go +ARG GO_VERSION=1.21.0 +RUN wget -q "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" -O go.tar.gz && \ + tar -C /usr/local -xzf go.tar.gz && \ + rm go.tar.gz + +# Set GOPATH and add to PATH +ENV GOPATH /go +ENV PATH $PATH:/usr/local/go/bin:$GOPATH/bin + +# Clone the Cluster Toolkit repository +ARG CLUSTER_TOOLKIT_VERSION=main +RUN git clone --branch ${CLUSTER_TOOLKIT_VERSION} https://github.com/GoogleCloudPlatform/cluster-toolkit.git /cluster-toolkit + +# Create and activate the virtual environment within the gcluster folder +WORKDIR /cluster-toolkit +ENV VIRTUAL_ENV /cluster-toolkit/venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH "$VIRTUAL_ENV/bin:$PATH" + +# Build the Cluster Toolkit +RUN make install-dev-deps +RUN make + +# Make gcluster available +RUN cp /cluster-toolkit/gcluster /usr/local/bin/gcluster +RUN echo $PATH + +# Command to execute when running the container (placeholder) +ENTRYPOINT ["gcluster"] +CMD ["--version"] From 12e8c709ff6b7a36f803e349fa49b2c968d880c4 Mon Sep 17 00:00:00 2001 From: Rachael Tamakloe Date: Fri, 8 Nov 2024 10:05:48 +0000 Subject: [PATCH 2/6] add associated readme instructions for dockerfile --- .../cluster-toolkit-dockerfile/README.md | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tools/cloud-build/images/cluster-toolkit-dockerfile/README.md diff --git a/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md b/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md new file mode 100644 index 0000000000..f017226bec --- /dev/null +++ b/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md @@ -0,0 +1,84 @@ +# Cluster Toolkit Dockerfile + +This repository contains a Dockerfile for building a Docker image with Cluster Toolkit and its dependencies installed and the `gcluster` binary readily available for use. + +## System Requirements + +* [Docker Engine](https://docs.docker.com/engine/) needs to be installed. + +## Environment Variables +The following environment variables can be used to customize the build process: +* **`BASE_IMAGE`**: The base image to use for the build. Defaults to `gcr.io/google.com/cloudsdktool/google-cloud-cli:stable`. +* **`TERRAFORM_VERSION`**: The version of Terraform to install. Defaults to `1.5.2`. +* **`PACKER_VERSION`**: The version of Packer to install. Defaults to `1.8.6`. +* **`GO_VERSION`**: The version of Go to install. Defaults to `1.21.0`. +* **`CLUSTER_TOOLKIT_VERSION`**: The version (tag) of the Cluster Toolkit to install. Defaults to the current version associated with the `main` branch of the cluster toolkit repository. + +## Build the Docker Image +To build the Docker image, navigate to the directory the Dockerfile is present in and run the following command: + +```bash +docker build --build-arg BASE_IMAGE= \ + --build-arg TERRAFORM_VERSION= \ + --build-arg PACKER_VERSION= \ + --build-arg GO_VERSION= \ + --build-arg CLUSTER_TOOLKIT_VERSION= \ + -t . +``` + +Example: + +```bash +docker build --build-arg CLUSTER_TOOLKIT_VERSION=v1.40.0 -t my-cluster-toolkit-image . +``` + +The above example builds an image tagged `my-cluster-toolkit-image` and sets the CLUSTER_TOOLKIT_VERSION to v1.40.0 while using the default values for other arguments. + +## Run the Docker Image +To run the Docker image, use the following command: + +```bash +docker run +``` + +Replace the following placeholders: + +* ``: The name of your Docker image. +* ``: The gcluster command you want to execute. + +Because this Dockerfile has an `ENTRYPOINT ["gcluster"]` line, any arguments provided to the docker run command after the `` will be passed as arguments to the `gcluster` command within the container. + +Example: + +```bash +docker run my-cluster-toolkit-image --version +``` + +This command will execute `gcluster --version` within the container. You can use this pattern to run any valid gcluster command within the container. + +## Sharing data between local and container environments +To use gcluster commands that interact with Google Cloud, you need to provide your Google Cloud credentials to the container. You can do this by mounting your gcloud configuration directory: + +```bash +docker run -v ~/.config/gcloud/:/root/.config/gcloud +``` + +This mounts your local `~/.config/gcloud` directory to the `/root/.config/gcloud` directory inside the container, allowing the gcluster binary to access your credentials. + +To pass in a blueprint stored locally to the `glcuster` binary inside of the container, you can also mount the directory containing the blueprint to the container: + +```bash +docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/data +``` + +This mounts your current working directory ($(pwd)) to the `/data` directory inside the container. You can then reference the blueprint file within your using the /data path. + +When using the docker container to run gcluster commands that either deploy or modify cloud resources, it's strongly recommended to save a local copy of the deployment folder that's generated inside of the docker container. This can be done by using the `--out` flag in combination with some `gcluster` sub-commands to set the output directory where the gcluster deployment directory will be created. Ideally, the output directory should be a directory mounted from your local machine to the docker container. This ensures that the deployment folder persists even after the container exits. + +Here's an example of how to use the `--out` flag to save the deployment folder to your current directory (mounted as `/data` in the container) when the `deploy` sub-command is used: + +```bash +docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/data my-cluster-toolkit-image deploy /data/my-blueprint.yaml --out /data --auto-approve +``` + +In this example, the deployment folder will be created in your current directory on your local machine, allowing you to access and manage the deployment artifacts even after the container is removed. The `--auto-approve` flag automatically approves any prompts from gcluster, streamlining the deployment process. From 85f18e66f754c2a29645c0bf26df1bd799583ebb Mon Sep 17 00:00:00 2001 From: Rachael Tamakloe Date: Thu, 14 Nov 2024 19:04:56 +0000 Subject: [PATCH 3/6] updating readme and dockerfile --- .../cluster-toolkit-dockerfile/Dockerfile | 2 +- .../cluster-toolkit-dockerfile/README.md | 55 +++++-------------- 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile b/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile index c7d15f3ca3..e414933f28 100644 --- a/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile +++ b/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile @@ -77,4 +77,4 @@ RUN echo $PATH # Command to execute when running the container (placeholder) ENTRYPOINT ["gcluster"] -CMD ["--version"] +CMD ["--help"] diff --git a/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md b/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md index f017226bec..84004589b3 100644 --- a/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md +++ b/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md @@ -4,18 +4,18 @@ This repository contains a Dockerfile for building a Docker image with Cluster T ## System Requirements -* [Docker Engine](https://docs.docker.com/engine/) needs to be installed. +* [Docker Engine](https://docs.docker.com/engine/) needs to be installed to build a Docker image from this Dockerfile. -## Environment Variables -The following environment variables can be used to customize the build process: +## Build Arguments +The following build arguments can be used to customize the build process: * **`BASE_IMAGE`**: The base image to use for the build. Defaults to `gcr.io/google.com/cloudsdktool/google-cloud-cli:stable`. * **`TERRAFORM_VERSION`**: The version of Terraform to install. Defaults to `1.5.2`. * **`PACKER_VERSION`**: The version of Packer to install. Defaults to `1.8.6`. * **`GO_VERSION`**: The version of Go to install. Defaults to `1.21.0`. * **`CLUSTER_TOOLKIT_VERSION`**: The version (tag) of the Cluster Toolkit to install. Defaults to the current version associated with the `main` branch of the cluster toolkit repository. -## Build the Docker Image -To build the Docker image, navigate to the directory the Dockerfile is present in and run the following command: +## Build the Cluster Toolkit Docker Image +To build the Cluster Toolkit Docker image, navigate to the directory the Dockerfile is present in and run the following command: ```bash docker build --build-arg BASE_IMAGE= \ @@ -34,51 +34,26 @@ docker build --build-arg CLUSTER_TOOLKIT_VERSION=v1.40.0 -t my-cluster-toolkit-i The above example builds an image tagged `my-cluster-toolkit-image` and sets the CLUSTER_TOOLKIT_VERSION to v1.40.0 while using the default values for other arguments. -## Run the Docker Image -To run the Docker image, use the following command: +## Run the Cluster Toolkit Docker Image +To run the Cluster Toolkit Docker image, use the following command: ```bash -docker run +docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/data ``` -Replace the following placeholders: +This command runs the Cluster Toolkit Docker image and allows the `gcluster` binary to access your Google Cloud credentials and local files. Here's a breakdown: -* ``: The name of your Docker image. -* ``: The gcluster command you want to execute. +* `-v ~/.config/gcloud/:/root/.config/gcloud`: This part mounts your local Google Cloud configuration directory `(~/.config/gcloud)` to the `/root/.config/gcloud` directory inside the container. This allows the `gcluster` binary to access your credentials and interact with Google Cloud resources. +* `-v $(pwd):/data`: This part mounts your current working directory `($(pwd))` to the `/data` directory inside the container. This allows you to access any files in your current directory (like blueprint files) from within the container. You can then reference these files in your `` using the `/data` path. +* ``: Replace this with the name of your Docker image. +* ``: Replace this with the `gcluster` command you want to execute. The Cluster Toolkit Docker image has `ENTRYPOINT ["gcluster"]` in its Dockerfile. This means that the `gcluster` command is automatically executed when the container starts, and any arguments provided after `` in the docker run command are passed as arguments to `gcluster`. -Because this Dockerfile has an `ENTRYPOINT ["gcluster"]` line, any arguments provided to the docker run command after the `` will be passed as arguments to the `gcluster` command within the container. +When using the docker container to run `gcluster` commands that either deploy or modify cloud resources, it's strongly recommended to save a local copy of the deployment folder that's generated inside of the docker container. This can be done by using the `--out` flag in combination with some `gcluster` commands to set the output directory where the `gcluster` deployment directory will be created. Ideally, the output directory should be a directory mounted from your local machine to the docker container. This ensures that the deployment folder persists even after the container exits, allowing you to access and manage the deployment artifacts even after the container is removed. Example: -```bash -docker run my-cluster-toolkit-image --version -``` - -This command will execute `gcluster --version` within the container. You can use this pattern to run any valid gcluster command within the container. - -## Sharing data between local and container environments -To use gcluster commands that interact with Google Cloud, you need to provide your Google Cloud credentials to the container. You can do this by mounting your gcloud configuration directory: - -```bash -docker run -v ~/.config/gcloud/:/root/.config/gcloud -``` - -This mounts your local `~/.config/gcloud` directory to the `/root/.config/gcloud` directory inside the container, allowing the gcluster binary to access your credentials. - -To pass in a blueprint stored locally to the `glcuster` binary inside of the container, you can also mount the directory containing the blueprint to the container: - -```bash -docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/data -``` - -This mounts your current working directory ($(pwd)) to the `/data` directory inside the container. You can then reference the blueprint file within your using the /data path. - -When using the docker container to run gcluster commands that either deploy or modify cloud resources, it's strongly recommended to save a local copy of the deployment folder that's generated inside of the docker container. This can be done by using the `--out` flag in combination with some `gcluster` sub-commands to set the output directory where the gcluster deployment directory will be created. Ideally, the output directory should be a directory mounted from your local machine to the docker container. This ensures that the deployment folder persists even after the container exits. - -Here's an example of how to use the `--out` flag to save the deployment folder to your current directory (mounted as `/data` in the container) when the `deploy` sub-command is used: - ```bash docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/data my-cluster-toolkit-image deploy /data/my-blueprint.yaml --out /data --auto-approve ``` -In this example, the deployment folder will be created in your current directory on your local machine, allowing you to access and manage the deployment artifacts even after the container is removed. The `--auto-approve` flag automatically approves any prompts from gcluster, streamlining the deployment process. +This example runs the `deploy` command with the blueprint file `my-blueprint.yaml` located in your current directory. The `--out /data` flag saves the deployment folder to your current directory, and `--auto-approve` automatically approves any prompts from `gcluster`, streamlining the deployment process. From 2023fa33b223cb551416d80e26ad8d417849c00d Mon Sep 17 00:00:00 2001 From: Rachael Tamakloe Date: Fri, 15 Nov 2024 18:52:23 +0000 Subject: [PATCH 4/6] updating readme and dockerfile --- .../images/cluster-toolkit-dockerfile/Dockerfile | 4 ++-- .../images/cluster-toolkit-dockerfile/README.md | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile b/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile index e414933f28..3d8b1b95c8 100644 --- a/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile +++ b/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile @@ -58,8 +58,8 @@ ENV GOPATH /go ENV PATH $PATH:/usr/local/go/bin:$GOPATH/bin # Clone the Cluster Toolkit repository -ARG CLUSTER_TOOLKIT_VERSION=main -RUN git clone --branch ${CLUSTER_TOOLKIT_VERSION} https://github.com/GoogleCloudPlatform/cluster-toolkit.git /cluster-toolkit +ARG CLUSTER_TOOLKIT_REF=main +RUN git clone --branch ${CLUSTER_TOOLKIT_REF} https://github.com/GoogleCloudPlatform/cluster-toolkit.git /cluster-toolkit # Create and activate the virtual environment within the gcluster folder WORKDIR /cluster-toolkit diff --git a/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md b/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md index 84004589b3..f6eb02b0eb 100644 --- a/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md +++ b/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md @@ -12,7 +12,7 @@ The following build arguments can be used to customize the build process: * **`TERRAFORM_VERSION`**: The version of Terraform to install. Defaults to `1.5.2`. * **`PACKER_VERSION`**: The version of Packer to install. Defaults to `1.8.6`. * **`GO_VERSION`**: The version of Go to install. Defaults to `1.21.0`. -* **`CLUSTER_TOOLKIT_VERSION`**: The version (tag) of the Cluster Toolkit to install. Defaults to the current version associated with the `main` branch of the cluster toolkit repository. +* **`CLUSTER_TOOLKIT_REF`**: The [Cluster Toolkit repository's](https://github.com/GoogleCloudPlatform/cluster-toolkit/releases) branch or tag from which to build Cluster Toolkit. Defaults to the `main` branch. ## Build the Cluster Toolkit Docker Image To build the Cluster Toolkit Docker image, navigate to the directory the Dockerfile is present in and run the following command: @@ -22,17 +22,17 @@ docker build --build-arg BASE_IMAGE= \ --build-arg TERRAFORM_VERSION= \ --build-arg PACKER_VERSION= \ --build-arg GO_VERSION= \ - --build-arg CLUSTER_TOOLKIT_VERSION= \ + --build-arg CLUSTER_TOOLKIT_REF= \ -t . ``` Example: ```bash -docker build --build-arg CLUSTER_TOOLKIT_VERSION=v1.40.0 -t my-cluster-toolkit-image . +docker build --build-arg CLUSTER_TOOLKIT_REF=v1.40.0 -t my-cluster-toolkit-image . ``` -The above example builds an image tagged `my-cluster-toolkit-image` and sets the CLUSTER_TOOLKIT_VERSION to v1.40.0 while using the default values for other arguments. +The above example builds an image tagged `my-cluster-toolkit-image` and sets the CLUSTER_TOOLKIT_REF to v1.40.0 while using the default values for other arguments. ## Run the Cluster Toolkit Docker Image To run the Cluster Toolkit Docker image, use the following command: @@ -43,12 +43,12 @@ docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/data ` using the `/data` path. +* `-v ~/.config/gcloud/:/root/.config/gcloud`: This argument mounts your local Google Cloud configuration directory `(~/.config/gcloud)` to the `/root/.config/gcloud` directory inside the container. This allows the `gcluster` binary to access your credentials and interact with Google Cloud resources. +* `-v $(pwd):/data`: This argument mounts your current working directory `($(pwd))` to the `/data` directory inside the container. This allows you to access any files in your current directory (like blueprint files) from within the container. You can then reference these files in your `` using the `/data` path. * ``: Replace this with the name of your Docker image. -* ``: Replace this with the `gcluster` command you want to execute. The Cluster Toolkit Docker image has `ENTRYPOINT ["gcluster"]` in its Dockerfile. This means that the `gcluster` command is automatically executed when the container starts, and any arguments provided after `` in the docker run command are passed as arguments to `gcluster`. +* ``: Replace this with the `gcluster` command you want to execute. The Cluster Toolkit Docker image has `ENTRYPOINT ["gcluster"]` in its Dockerfile. This means that the `gcluster` command is automatically executed when the container starts, and any arguments provided after `` in the `docker run` command are passed as arguments to `gcluster`. -When using the docker container to run `gcluster` commands that either deploy or modify cloud resources, it's strongly recommended to save a local copy of the deployment folder that's generated inside of the docker container. This can be done by using the `--out` flag in combination with some `gcluster` commands to set the output directory where the `gcluster` deployment directory will be created. Ideally, the output directory should be a directory mounted from your local machine to the docker container. This ensures that the deployment folder persists even after the container exits, allowing you to access and manage the deployment artifacts even after the container is removed. +When using the Docker container to run `gcluster` commands that either deploy or modify cloud resources, it's strongly recommended to save a local copy of the deployment folder that's generated inside of the Docker container. This can be done by using the `--out` flag in combination with some `gcluster` commands to set the output directory where the `gcluster` deployment directory will be created. Ideally, the output directory should be a directory mounted from your local machine to the Docker container. This ensures that the deployment folder persists even after the container exits, allowing you to access and manage the deployment artifacts even after the container is removed. Example: From 3a4e0b1adb3aaccc7abee65be4a455e7180381a4 Mon Sep 17 00:00:00 2001 From: Rachael Tamakloe Date: Mon, 18 Nov 2024 17:09:06 +0000 Subject: [PATCH 5/6] modifications to Dockerfile and readme --- .../cluster-toolkit-dockerfile/Dockerfile | 17 ++++++----------- .../images/cluster-toolkit-dockerfile/README.md | 12 +++++------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile b/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile index 3d8b1b95c8..5507de6489 100644 --- a/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile +++ b/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile @@ -28,10 +28,7 @@ RUN apt-get update && \ git \ make \ unzip \ - wget \ - python3 \ - python3-pip \ - python3-venv + wget # Install Terraform ARG TERRAFORM_VERSION=1.5.2 @@ -61,20 +58,18 @@ ENV PATH $PATH:/usr/local/go/bin:$GOPATH/bin ARG CLUSTER_TOOLKIT_REF=main RUN git clone --branch ${CLUSTER_TOOLKIT_REF} https://github.com/GoogleCloudPlatform/cluster-toolkit.git /cluster-toolkit -# Create and activate the virtual environment within the gcluster folder +# Build the gcluster binary WORKDIR /cluster-toolkit -ENV VIRTUAL_ENV /cluster-toolkit/venv -RUN python3 -m venv $VIRTUAL_ENV -ENV PATH "$VIRTUAL_ENV/bin:$PATH" - -# Build the Cluster Toolkit -RUN make install-dev-deps RUN make # Make gcluster available RUN cp /cluster-toolkit/gcluster /usr/local/bin/gcluster RUN echo $PATH +# Create /out directory +RUN mkdir /out +WORKDIR /out + # Command to execute when running the container (placeholder) ENTRYPOINT ["gcluster"] CMD ["--help"] diff --git a/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md b/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md index f6eb02b0eb..899437c23b 100644 --- a/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md +++ b/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md @@ -38,22 +38,20 @@ The above example builds an image tagged `my-cluster-toolkit-image` and sets the To run the Cluster Toolkit Docker image, use the following command: ```bash -docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/data +docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/out ``` This command runs the Cluster Toolkit Docker image and allows the `gcluster` binary to access your Google Cloud credentials and local files. Here's a breakdown: -* `-v ~/.config/gcloud/:/root/.config/gcloud`: This argument mounts your local Google Cloud configuration directory `(~/.config/gcloud)` to the `/root/.config/gcloud` directory inside the container. This allows the `gcluster` binary to access your credentials and interact with Google Cloud resources. -* `-v $(pwd):/data`: This argument mounts your current working directory `($(pwd))` to the `/data` directory inside the container. This allows you to access any files in your current directory (like blueprint files) from within the container. You can then reference these files in your `` using the `/data` path. +* `-v ~/.config/gcloud/:/root/.config/gcloud`: This argument mounts your local Google Cloud configuration directory `(~/.config/gcloud)` to the `/root/.config/gcloud` directory inside the container. This allows the `gcluster` binary to access your credentials and interact with Google Cloud resources when needed. +* `-v $(pwd):/out`: This argument mounts your current working directory `($(pwd))` to the `/out` directory inside the container. This is important because the Cluster Toolkit Dockerfile is designed to automatically output deployment folders to the `/out` directory. Due to this automatic output behavior, you should not provide the `--out` argument to the `create` and `deploy` gcluster subcommands when using this Dockerfile. Instead, mount a local directory (as shown in the example above with $(pwd)) to the `/out` directory within the container. This ensures that the deployment folder persists even after the container exits, allowing you to access and manage the deployment artifacts even after the container is removed. Additionally, this allows the container to access any files in your current directory (like blueprint files) from within the container. You can then reference these files in your `` using the `/out` path. * ``: Replace this with the name of your Docker image. * ``: Replace this with the `gcluster` command you want to execute. The Cluster Toolkit Docker image has `ENTRYPOINT ["gcluster"]` in its Dockerfile. This means that the `gcluster` command is automatically executed when the container starts, and any arguments provided after `` in the `docker run` command are passed as arguments to `gcluster`. -When using the Docker container to run `gcluster` commands that either deploy or modify cloud resources, it's strongly recommended to save a local copy of the deployment folder that's generated inside of the Docker container. This can be done by using the `--out` flag in combination with some `gcluster` commands to set the output directory where the `gcluster` deployment directory will be created. Ideally, the output directory should be a directory mounted from your local machine to the Docker container. This ensures that the deployment folder persists even after the container exits, allowing you to access and manage the deployment artifacts even after the container is removed. - Example: ```bash -docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/data my-cluster-toolkit-image deploy /data/my-blueprint.yaml --out /data --auto-approve +docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/out my-cluster-toolkit-image deploy /out/my-blueprint.yaml --auto-approve ``` -This example runs the `deploy` command with the blueprint file `my-blueprint.yaml` located in your current directory. The `--out /data` flag saves the deployment folder to your current directory, and `--auto-approve` automatically approves any prompts from `gcluster`, streamlining the deployment process. +This example runs the `deploy` command with the blueprint file `my-blueprint.yaml` located in your current directory. The deployment folder generated by `gcluster deploy` will be saved to your current directory (which is mounted to `/out`). `--auto-approve` automatically approves any prompts from `gcluster`, streamlining the deployment process. From 7a7e04b4dd8bea3d730fe57a5668da5a2a1c7497 Mon Sep 17 00:00:00 2001 From: Rachael Tamakloe Date: Mon, 18 Nov 2024 18:08:49 +0000 Subject: [PATCH 6/6] updating readme and dockerfile --- .../images/cluster-toolkit-dockerfile/Dockerfile | 2 +- .../images/cluster-toolkit-dockerfile/README.md | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile b/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile index 5507de6489..2b34e78128 100644 --- a/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile +++ b/tools/cloud-build/images/cluster-toolkit-dockerfile/Dockerfile @@ -63,7 +63,7 @@ WORKDIR /cluster-toolkit RUN make # Make gcluster available -RUN cp /cluster-toolkit/gcluster /usr/local/bin/gcluster +RUN cp /cluster-toolkit/gcluster /usr/local/bin/gcluster RUN echo $PATH # Create /out directory diff --git a/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md b/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md index 899437c23b..afa45c713d 100644 --- a/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md +++ b/tools/cloud-build/images/cluster-toolkit-dockerfile/README.md @@ -12,7 +12,7 @@ The following build arguments can be used to customize the build process: * **`TERRAFORM_VERSION`**: The version of Terraform to install. Defaults to `1.5.2`. * **`PACKER_VERSION`**: The version of Packer to install. Defaults to `1.8.6`. * **`GO_VERSION`**: The version of Go to install. Defaults to `1.21.0`. -* **`CLUSTER_TOOLKIT_REF`**: The [Cluster Toolkit repository's](https://github.com/GoogleCloudPlatform/cluster-toolkit/releases) branch or tag from which to build Cluster Toolkit. Defaults to the `main` branch. +* **`CLUSTER_TOOLKIT_REF`**: The [Cluster Toolkit repository's](https://github.com/GoogleCloudPlatform/cluster-toolkit/releases) branch or tag from which to build Cluster Toolkit. Defaults to the `main` branch, which is the latest official release. ## Build the Cluster Toolkit Docker Image To build the Cluster Toolkit Docker image, navigate to the directory the Dockerfile is present in and run the following command: @@ -29,10 +29,10 @@ docker build --build-arg BASE_IMAGE= \ Example: ```bash -docker build --build-arg CLUSTER_TOOLKIT_REF=v1.40.0 -t my-cluster-toolkit-image . +docker build --build-arg CLUSTER_TOOLKIT_REF=v1.40.0 -t gcluster -t ghpc . ``` -The above example builds an image tagged `my-cluster-toolkit-image` and sets the CLUSTER_TOOLKIT_REF to v1.40.0 while using the default values for other arguments. +The above example builds an image tagged `gcluster` and sets the `CLUSTER_TOOLKIT_REF` to the Git tag `v1.40.0` while using the default values for other arguments. ## Run the Cluster Toolkit Docker Image To run the Cluster Toolkit Docker image, use the following command: @@ -44,14 +44,14 @@ docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/out This command runs the Cluster Toolkit Docker image and allows the `gcluster` binary to access your Google Cloud credentials and local files. Here's a breakdown: * `-v ~/.config/gcloud/:/root/.config/gcloud`: This argument mounts your local Google Cloud configuration directory `(~/.config/gcloud)` to the `/root/.config/gcloud` directory inside the container. This allows the `gcluster` binary to access your credentials and interact with Google Cloud resources when needed. -* `-v $(pwd):/out`: This argument mounts your current working directory `($(pwd))` to the `/out` directory inside the container. This is important because the Cluster Toolkit Dockerfile is designed to automatically output deployment folders to the `/out` directory. Due to this automatic output behavior, you should not provide the `--out` argument to the `create` and `deploy` gcluster subcommands when using this Dockerfile. Instead, mount a local directory (as shown in the example above with $(pwd)) to the `/out` directory within the container. This ensures that the deployment folder persists even after the container exits, allowing you to access and manage the deployment artifacts even after the container is removed. Additionally, this allows the container to access any files in your current directory (like blueprint files) from within the container. You can then reference these files in your `` using the `/out` path. +* `-v $(pwd):/out`: This argument mounts your current working directory `$(pwd)` to the `/out` directory inside the container. This is important because the Cluster Toolkit Dockerfile is designed to automatically output deployment folders to the `/out` directory. Due to this automatic output behavior, you should not provide the `--out` argument to the `create` and `deploy` gcluster subcommands when using this Dockerfile. Instead, mount a local directory (as shown in the example above with $(pwd)) to the `/out` directory within the container. This ensures that the deployment folder persists even after the container exits, allowing you to access and manage the deployment artifacts even after the container is removed. Additionally, this allows the container to access any files in your current directory (like blueprint files) from within the container. You can then reference these files in your `` using the `/out` path. * ``: Replace this with the name of your Docker image. * ``: Replace this with the `gcluster` command you want to execute. The Cluster Toolkit Docker image has `ENTRYPOINT ["gcluster"]` in its Dockerfile. This means that the `gcluster` command is automatically executed when the container starts, and any arguments provided after `` in the `docker run` command are passed as arguments to `gcluster`. Example: ```bash -docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/out my-cluster-toolkit-image deploy /out/my-blueprint.yaml --auto-approve +docker run -v ~/.config/gcloud/:/root/.config/gcloud -v $(pwd):/out gcluster deploy /out/my-blueprint.yaml --auto-approve ``` This example runs the `deploy` command with the blueprint file `my-blueprint.yaml` located in your current directory. The deployment folder generated by `gcluster deploy` will be saved to your current directory (which is mounted to `/out`). `--auto-approve` automatically approves any prompts from `gcluster`, streamlining the deployment process.