Add easier-to-use docker_image target.

PiperOrigin-RevId: 337415009
This commit is contained in:
Adin Scannell
2020-10-15 17:21:24 -07:00
committed by gVisor bot
parent 0d54b41e55
commit 0a7e32bd17
4 changed files with 40 additions and 38 deletions
+4 -4
View File
@@ -94,9 +94,9 @@ endef
rebuild-...: ## Rebuild the given image. Also may use 'rebuild-all-images'.
$(eval $(call images,rebuild))
push-...: ## Push the given image. Also may use 'push-all-images'.
$(eval $(call images,pull))
pull-...: ## Pull the given image. Also may use 'pull-all-images'.
$(eval $(call images,push))
pull-...: ## Pull the given image. Also may use 'pull-all-images'.
$(eval $(call images,pull))
load-...: ## Load (pull or rebuild) the given image. Also may use 'load-all-images'.
$(eval $(call images,load))
list-images: ## List all available images.
@@ -258,7 +258,7 @@ WEBSITE_PROJECT := gvisordev
WEBSITE_REGION := us-central1
website-build: load-jekyll ## Build the site image locally.
@$(call submake,run TARGETS="//website:website")
@$(call submake,run TARGETS="//website:website" ARGS="$(WEBSITE_IMAGE)")
.PHONY: website-build
website-server: website-build ## Run a local server for development.
@@ -266,7 +266,7 @@ website-server: website-build ## Run a local server for development.
.PHONY: website-server
website-push: website-build ## Push a new image and update the service.
@docker tag gvisor.dev/images/website $(WEBSITE_IMAGE) && docker push $(WEBSITE_IMAGE)
@docker push $(WEBSITE_IMAGE)
.PHONY: website-push
website-deploy: website-push ## Deploy a new version of the website.
+31
View File
@@ -0,0 +1,31 @@
"""Helpers for Docker image generation."""
def _docker_image_impl(ctx):
importer = ctx.actions.declare_file(ctx.label.name)
importer_content = [
"#!/bin/bash",
"set -euo pipefail",
"exec docker import " + " ".join([
"-c '%s'" % attr
for attr in ctx.attr.statements
]) + " " + " ".join([
"'%s'" % f.path
for f in ctx.files.data
]) + " $1",
"",
]
ctx.actions.write(importer, "\n".join(importer_content), is_executable = True)
return [DefaultInfo(
runfiles = ctx.runfiles(ctx.files.data),
executable = importer,
)]
docker_image = rule(
implementation = _docker_image_impl,
doc = "Tool to load a Docker image; takes a single parameter (image name).",
attrs = {
"statements": attr.string_list(doc = "Extra Dockerfile directives."),
"data": attr.label_list(doc = "All image data."),
},
executable = True,
)
+5 -7
View File
@@ -1,17 +1,15 @@
load("//tools:defs.bzl", "bzl_library", "pkg_tar")
load("//website:defs.bzl", "doc", "docs")
load("//images:defs.bzl", "docker_image")
package(licenses = ["notice"])
# website is the full container image. Note that this actually just collects
# other dependendcies and runs Docker locally to import and tag the image.
sh_binary(
docker_image(
name = "website",
srcs = ["import.sh"],
data = [":files"],
tags = [
"local",
"manual",
statements = [
"EXPOSE 8080/tcp",
'ENTRYPOINT ["/server"]',
],
)
-27
View File
@@ -1,27 +0,0 @@
#!/bin/bash
# Copyright 2018 The gVisor Authors.
#
# 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.
set -xeuo pipefail
if [[ -d $0.runfiles ]]; then
cd $0.runfiles
fi
exec docker import \
-c "EXPOSE 8080/tcp" \
-c "ENTRYPOINT [\"/server\"]" \
$(find . -name files.tgz) \
gvisor.dev/images/website