-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into isolated-change
- Loading branch information
Showing
40 changed files
with
600 additions
and
89 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
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
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
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,115 @@ | ||
# Serving Static Content | ||
|
||
This is useful for creating an image to serve static content, such as the output of building your | ||
frontend javascript. | ||
|
||
In this example we'll use the [docker nginx image](https://hub.docker.com/_/nginx), but you could | ||
use any other static content webserver the same way. | ||
|
||
## Example | ||
|
||
Pull our base image. | ||
|
||
**./WORKSPACE** | ||
|
||
```python | ||
load("@rules_oci//oci:pull.bzl", "oci_pull") | ||
oci_pull( | ||
name = "nginx_debian_slim", | ||
digest = "sha256:6b06964cdbbc517102ce5e0cef95152f3c6a7ef703e4057cb574539de91f72e6", | ||
image = "docker.io/library/nginx", | ||
) | ||
``` | ||
|
||
Next lets create our static content files. | ||
|
||
**./frontend/index.html** | ||
|
||
```html | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<h1>Our Homepage</h1> | ||
|
||
<p>Hello from index.html</p> | ||
|
||
</body> | ||
</html> | ||
``` | ||
|
||
**./frontend/textfile.txt** | ||
|
||
```txt | ||
This is text file. | ||
``` | ||
|
||
And finally the build rules for our image. | ||
|
||
**./frontend/BUILD** | ||
|
||
```python | ||
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball") | ||
load("@rules_pkg//:pkg.bzl", "pkg_tar") | ||
filegroup( | ||
name = "static", | ||
srcs = ["index.html", "textfile.txt"], | ||
) | ||
|
||
pkg_tar( | ||
name = "static_tar", | ||
srcs = [":static"], | ||
package_dir = "/usr/share/nginx/html" | ||
) | ||
|
||
oci_image( | ||
name = "frontend_image", | ||
base = "@nginx_debian_slim", | ||
tars = [ | ||
":static_tar", | ||
], | ||
# Intentionally omit cmd/entrypoint to default to the base nginx container's cmd/entrypoint. | ||
# entrypoint = [], | ||
# cmd = [], | ||
) | ||
oci_tarball( | ||
name = "frontend_tarball", | ||
image = ":frontend_image", | ||
repo_tags = ["ourfrontend:latest"], | ||
) | ||
|
||
|
||
``` | ||
|
||
If you want to customize the nginx.conf you could create `./frontend/nginx.conf` and add this to | ||
`./frontend/BUILD`. | ||
|
||
```python | ||
|
||
pkg_tar( | ||
name = "nginx_conf_tar", | ||
srcs = [":nginx.conf"], | ||
package_dir = "/etc/nginx", | ||
) | ||
|
||
# ... | ||
oci_image( | ||
#... | ||
tars = [ | ||
":static_tar", | ||
":nginx_conf_tar | ||
], | ||
# ... | ||
) | ||
|
||
``` | ||
|
||
## Try running the container with docker | ||
|
||
```bash | ||
bazel run :frontend_tarball | ||
docker run --rm -p 8080:80 "ourfrontend:latest" | ||
``` | ||
|
||
Wait for nginx to start in your container, and then go to `localhost:8080` and `localhost:8080/example.txt` to see your static content. |
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
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
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 |
---|---|---|
@@ -1,14 +1,34 @@ | ||
load("//oci:defs.bzl", "oci_image") | ||
load("//oci:defs.bzl", "oci_image", "oci_tarball") | ||
|
||
_ARCH = [ | ||
"amd64", | ||
"arm64", | ||
] | ||
|
||
# Workaround: crane doesn't do the right thing with .tar.xz compression | ||
# so we simply decompress explicitly first. | ||
[ | ||
genrule( | ||
name = "decompress_" + architecture, | ||
srcs = ["@bash_{}//:layer".format(architecture)], | ||
outs = ["_{}.tar".format(architecture)], | ||
cmd = "xz --decompress --stdout $< >$@", | ||
) | ||
for architecture in _ARCH | ||
] | ||
|
||
[ | ||
oci_image( | ||
name = "image_" + architecture, | ||
architecture = architecture, | ||
os = "linux", | ||
tars = ["@bash_{}//:layer".format(architecture)], | ||
tars = ["_{}.tar".format(architecture)], | ||
) | ||
for architecture in [ | ||
"amd64", | ||
"arm64", | ||
] | ||
for architecture in _ARCH | ||
] | ||
|
||
oci_tarball( | ||
name = "tarball", | ||
image = ":image_amd64", | ||
repo_tags = ["test:test"], | ||
) |
Oops, something went wrong.