Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dockertools #1868

Merged
merged 28 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fae778c
Add dockertools
Matt-Jns Aug 3, 2022
0c38a54
Delete unnecessary vendor
Matt-Jns Aug 3, 2022
575795e
Modify Dockerfile
Matt-Jns Aug 3, 2022
20b3686
Modify Dockerfile
Matt-Jns Aug 3, 2022
9abba79
Modify Dockerfile
Matt-Jns Aug 3, 2022
8734b18
Modify Dockerfile
Matt-Jns Aug 8, 2022
40f027d
Modify Dockerfile
Matt-Jns Aug 10, 2022
a066b33
Modify Dockerfile
Matt-Jns Aug 10, 2022
c8ef08d
Modify Dockerfile
Matt-Jns Aug 10, 2022
7a1bd1c
Modify Dockerfile for docker solutions
Matt-Jns Aug 18, 2022
16467ab
Update docker.Dockerfile
Matt-Jns Aug 18, 2022
7a0faea
Test CI/CD for Docker solutions
Matt-Jns Aug 18, 2022
805f315
Merge branch 'mjanas-dockertools' of https://github.com/GoogleCloudPl…
Matt-Jns Aug 18, 2022
b7b7cc7
CI/CD for dockertools
Matt-Jns Aug 22, 2022
6a8bf53
Merge branch 'master' into mjanas-dockertools
Matt-Jns Aug 22, 2022
bbf9e44
CI/CD for dockertools
Matt-Jns Aug 23, 2022
24ebd55
Merge branch 'mjanas-dockertools' of https://github.com/GoogleCloudPl…
Matt-Jns Aug 23, 2022
2b40b28
Merge branch 'master' into mjanas-dockertools
Matt-Jns Aug 23, 2022
4c0a458
Merge branch 'master' into mjanas-dockertools
Matt-Jns Aug 23, 2022
9f64543
CI/CD for dockertools
Matt-Jns Aug 24, 2022
3e55022
Merge branch 'mjanas-dockertools' of https://github.com/GoogleCloudPl…
Matt-Jns Aug 24, 2022
8bd47d8
Merge branch 'master' into mjanas-dockertools
Matt-Jns Aug 24, 2022
e34e64f
CI/CD for dockertools
Matt-Jns Aug 24, 2022
00590f5
Merge branch 'mjanas-dockertools' of https://github.com/GoogleCloudPl…
Matt-Jns Aug 24, 2022
a5ec716
CI/CD for dockertools
Matt-Jns Aug 24, 2022
3f7a039
Use Go modules
Matt-Jns Aug 25, 2022
871c251
Update README.md
Matt-Jns Aug 25, 2022
3b1daf4
Update README.md
Matt-Jns Aug 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions docker.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM marketplace.gcr.io/google/debian9 AS build
FROM marketplace.gcr.io/google/debian11

ENV BAZEL_VERSION 0.19.2
ENV BAZEL_ARCH linux_amd64_stripped
ENV DOCKER_TOOLS_TAG v1.0.0

RUN set -eux \
&& apt-get update \
&& apt-get install git wget unzip python g++ -y
&& apt-get install wget -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

RUN set -eux \
&& git clone https://github.com/GoogleCloudPlatform/runtimes-common.git --depth=1 \
&& cd runtimes-common \
&& bazel run //:gazelle \
&& bazel build versioning/scripts/dockerfiles:dockerfiles versioning/scripts/cloudbuild:cloudbuild \
&& cp bazel-bin/versioning/scripts/dockerfiles/${BAZEL_ARCH}/dockerfiles /bin/dockerfiles \
&& cp bazel-bin/versioning/scripts/cloudbuild/${BAZEL_ARCH}/cloudbuild /bin/cloudbuild

FROM marketplace.gcr.io/google/debian9

COPY --from=build /bin/dockerfiles /bin/dockerfiles
COPY --from=build /bin/cloudbuild /bin/cloudbuild
&& wget https://github.com/GoogleCloudPlatform/click-to-deploy/releases/download/${DOCKER_TOOLS_TAG}/cloudbuild -O /bin/cloudbuild \
&& wget https://github.com/GoogleCloudPlatform/click-to-deploy/releases/download/${DOCKER_TOOLS_TAG}/dockerfiles -O /bin/dockerfiles \
&& chmod +x /bin/cloudbuild \
&& chmod +x /bin/dockerfiles
48 changes: 48 additions & 0 deletions tools/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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_rules_dependencies", "go_register_toolchains")

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()
40 changes: 40 additions & 0 deletions tools/cloudbuild-dockertools.yaml
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'
42 changes: 42 additions & 0 deletions tools/dockertools.Dockerfile
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
70 changes: 70 additions & 0 deletions tools/dockerversioning/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Description

Versioning tools for Dockerfile source repos.

- `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 .
```
15 changes: 15 additions & 0 deletions tools/dockerversioning/scripts/cloudbuild/BUILD.bazel
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"],
)
Loading