-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add dockertools * Delete unnecessary vendor * Modify Dockerfile * Modify Dockerfile * Modify Dockerfile * Modify Dockerfile * Modify Dockerfile * Modify Dockerfile * Modify Dockerfile * Modify Dockerfile for docker solutions * Update docker.Dockerfile * Test CI/CD for Docker solutions * CI/CD for dockertools * CI/CD for dockertools * CI/CD for dockertools * CI/CD for dockertools * CI/CD for dockertools * Use Go modules * Update README.md * Update README.md
- Loading branch information
Showing
11 changed files
with
1,027 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
http_archive( | ||
name = "io_bazel_rules_go", | ||
sha256 = "1868ff68d6079e31b2f09b828b58d62e57ca8e9636edff699247c9108518570b", | ||
url = "https://github.com/bazelbuild/rules_go/releases/download/0.11.1/rules_go-0.11.1.tar.gz", | ||
) | ||
|
||
http_archive( | ||
name = "bazel_gazelle", | ||
sha256 = "92a3c59734dad2ef85dc731dbcb2bc23c4568cded79d4b87ebccd787eb89e8d0", | ||
url = "https://github.com/bazelbuild/bazel-gazelle/releases/download/0.11.0/bazel-gazelle-0.11.0.tar.gz", | ||
) | ||
|
||
load("@io_bazel_rules_go//go:def.bzl", "go_repository", "go_rules_dependencies", "go_register_toolchains") | ||
|
||
# Declare Go direct dependencies. | ||
go_repository( | ||
name = "com_github_gopkg_v2", | ||
importpath = "gopkg.in/yaml.v2", | ||
tag = "v2.3.0", | ||
) | ||
|
||
go_rules_dependencies() | ||
|
||
go_register_toolchains() | ||
|
||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") | ||
|
||
gazelle_dependencies() | ||
|
||
git_repository( | ||
name = "io_bazel_rules_docker", | ||
commit = "8bbe2a8abd382641e65ff7127a3700a8530f02ce", | ||
remote = "https://github.com/bazelbuild/rules_docker.git", | ||
) | ||
|
||
git_repository( | ||
name = "containerregistry", | ||
commit = "6b250f0bae8cce028df939010ee3118c8f2977ba", | ||
remote = "https://github.com/google/containerregistry", | ||
) | ||
|
||
load( | ||
"@io_bazel_rules_docker//docker:docker.bzl", | ||
"docker_repositories", | ||
"docker_pull", | ||
) | ||
|
||
docker_repositories() | ||
|
||
load( | ||
"@io_bazel_rules_docker//container:container.bzl", | ||
"repositories", | ||
) | ||
|
||
repositories() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
steps: | ||
- id: Build Dockertools Docker Image | ||
name: gcr.io/cloud-builders/docker | ||
args: | ||
- build | ||
- --tag | ||
- dockertools | ||
- --file | ||
- tools/dockertools.Dockerfile | ||
- tools | ||
|
||
- id: Share dockertools using workspaces | ||
name: dockertools | ||
entrypoint: bash | ||
args: | ||
- -c | ||
- | | ||
cp /bin/cloudbuild /workspace/cloudbuild && | ||
cp /bin/dockerfiles /workspace/dockerfiles && | ||
cp /bin/cloudbuild /workspace/cloudbuild_$TAG_NAME && | ||
cp /bin/dockerfiles /workspace/dockerfiles_$TAG_NAME | ||
- id: Create a new GitHub Release. | ||
name: dockertools | ||
entrypoint: bash | ||
args: | ||
- -c | ||
- | | ||
gh release create $TAG_NAME --notes "Dockertools" /workspace/{cloudbuild,dockerfiles} | ||
secretEnv: ['GH_TOKEN'] | ||
|
||
artifacts: | ||
objects: | ||
location: 'gs://$PROJECT_ID-c2d/' | ||
paths: ['/workspace/cloudbuild', '/workspace/dockerfiles', '/workspace/cloudbuild_$TAG_NAME', '/workspace/dockerfiles_$TAG_NAME'] | ||
|
||
availableSecrets: | ||
secretManager: | ||
- versionName: projects/$PROJECT_ID/secrets/GH_TOKEN/versions/1 | ||
env: 'GH_TOKEN' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2022 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. | ||
|
||
FROM marketplace.gcr.io/google/debian11 | ||
|
||
ENV BAZEL_VERSION 0.19.2 | ||
ENV BAZEL_ARCH linux_amd64_stripped | ||
|
||
RUN set -eux \ | ||
&& apt-get update \ | ||
&& apt-get install git wget unzip python g++ curl -y | ||
|
||
# Install Bazel | ||
RUN set -eux \ | ||
&& wget -q -O /bazel-installer.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh" \ | ||
&& chmod +x /bazel-installer.sh \ | ||
&& /bazel-installer.sh | ||
|
||
# Install gh CLI | ||
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ | ||
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ | ||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ | ||
&& apt update \ | ||
&& apt install gh | ||
|
||
RUN set -eux \ | ||
&& git clone https://github.com/GoogleCloudPlatform/click-to-deploy.git \ | ||
&& cd click-to-deploy/tools \ | ||
&& bazel build dockerversioning/scripts/dockerfiles:dockerfiles dockerversioning/scripts/cloudbuild:cloudbuild \ | ||
&& cp bazel-bin/dockerversioning/scripts/dockerfiles/${BAZEL_ARCH}/dockerfiles /bin/dockerfiles \ | ||
&& cp bazel-bin/dockerversioning/scripts/cloudbuild/${BAZEL_ARCH}/cloudbuild /bin/cloudbuild |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Description | ||
|
||
Versioning tools for Dockerfile source repos. Previously, these tools were in [runtimes-common](https://github.com/GoogleCloudPlatform/runtimes-common/tree/b39744e5a8588beba847a271e379b864a6ac2939), but have been moved to [click-to-deploy](https://github.com/GoogleCloudPlatform/click-to-deploy) for further development. | ||
|
||
- `dockerfiles` generates versionsed Dockerfiles from a common template. | ||
- `cloudbuild` generates a configuration file to build these Dockerfiles using | ||
[Google Container Builder](https://cloud.google.com/container-builder/docs/). | ||
|
||
# Installation | ||
|
||
- Install [Bazel, version 0.19.2](https://bazel.build) as the build tool. | ||
|
||
- Clone this repo: | ||
|
||
``` shell | ||
git clone https://github.com/GoogleCloudPlatform/click-to-deploy.git | ||
cd click-to-deploy/tools | ||
``` | ||
|
||
- Build: | ||
|
||
``` shell | ||
bazel run //:gazelle | ||
bazel build dockerversioning/scripts/dockerfiles:dockerfiles | ||
bazel build dockerversioning/scripts/cloudbuild:cloudbuild | ||
``` | ||
|
||
- Set the path to the built scripts: | ||
|
||
``` shell | ||
BAZEL_ARCH=linux_amd64_stripped | ||
export PATH=$PATH:$PWD/bazel-bin/dockerversioning/scripts/dockerfiles/${BAZEL_ARCH}/ | ||
export PATH=$PATH:$PWD/bazel-bin/dockerversioning/scripts/cloudbuild/${BAZEL_ARCH}/ | ||
``` | ||
|
||
# Create `versions.yaml` | ||
|
||
At root of the Dockerfile source repo, add a file called `versions.yaml`. | ||
Follow the format defined in `versions.go`. See an example on | ||
[github](https://github.com/GoogleCloudPlatform/mysql-docker). | ||
|
||
Primary folders in the Dockerfile source repo: | ||
|
||
- `templates` contains `Dockerfile.template`, which is a Go template for | ||
generating `Dockerfile`s. | ||
- `tests` contains any tests that should be included in the generated cloud | ||
build configuration. | ||
- Version folders as defined in `versions.yaml`. The `Dockerfile`s are | ||
generated into these folders. The folders should also contain all | ||
supporting files for each version, for example `docker-entrypoint.sh` files. | ||
|
||
# Usage of `dockerfiles` command | ||
|
||
``` shell | ||
cd path/to/dockerfile/repo | ||
dockerfiles | ||
``` | ||
|
||
# Usage of `cloudbuild` command | ||
|
||
``` shell | ||
cd path/to/dockerfile/repo | ||
cloudbuild > cloudbuild.yaml | ||
``` | ||
|
||
You can use the generated `cloudbuild.yaml` file as followed: | ||
|
||
``` shell | ||
gcloud container builds submit --config=cloudbuild.yaml . | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["main.go"], | ||
importpath = "github.com/GoogleCloudPlatform/click-to-deploy/tools/dockerversioning/scripts/cloudbuild", | ||
visibility = ["//visibility:private"], | ||
deps = ["//dockerversioning/versions:go_default_library"], | ||
) | ||
|
||
go_binary( | ||
name = "cloudbuild", | ||
embed = [":go_default_library"], | ||
visibility = ["//visibility:public"], | ||
) |
Oops, something went wrong.