-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Start implementing skaffold (#18)
- Loading branch information
Showing
26 changed files
with
601 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
WORKSPACE.bazel |
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,5 @@ | ||
DO NOT USE THIS CONVENTION | ||
|
||
Use kubernetes manifests per application instead! | ||
|
||
This is only a placeholder to warn anyone attempting to use the approach. |
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 @@ | ||
BUILD.bazel-oci_image |
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,22 @@ | ||
# See: https://bazel.build/concepts/build-files | ||
# TODO: | ||
# - Migrate to rules_oci (https://github.com/bazel-contrib/rules_oci/blob/main/docs/go.md) | ||
# - https://github.com/aspect-build/bazel-examples/tree/main/oci_go_image | ||
|
||
# | ||
# Golang (rules_docker - go_image) | ||
# | ||
|
||
load("@io_bazel_rules_docker//go:image.bzl", "go_image") | ||
|
||
go_image( | ||
name = "go_devops_cli_app_image", | ||
srcs = [ | ||
"src/main.go", | ||
"src/go.mod", | ||
"src/go.sum", | ||
], | ||
goos = "linux", | ||
goarch = "amd64", | ||
static = "on", | ||
) |
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,86 @@ | ||
# See: https://bazel.build/concepts/build-files | ||
# TODO: | ||
# - Migrate to rules_oci (https://github.com/bazel-contrib/rules_oci/blob/main/docs/go.md) | ||
# - https://github.com/aspect-build/bazel-examples/tree/main/oci_go_image | ||
|
||
# | ||
# Golang (rules_oci - oci_go_image) | ||
# | ||
|
||
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup") | ||
load("@rules_go//go:def.bzl", "go_binary", "go_library") | ||
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball") | ||
load("@rules_pkg//:pkg.bzl", "pkg_tar") | ||
load("@container_structure_test//:defs.bzl", "container_structure_test") | ||
|
||
go_library( | ||
name = "app_lib", | ||
srcs = ["src/main.go"], | ||
importpath = "example.com/custom_registry/app", | ||
visibility = ["//visibility:private"], | ||
deps = ["@com_github_google_go_cmp//cmp"], | ||
) | ||
|
||
go_binary( | ||
name = "app", | ||
embed = [":app_lib"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
# Put app go_binary into a tar layer. | ||
pkg_tar( | ||
name = "app_layer", | ||
srcs = [":app"], | ||
# If the binary depends on RUNFILES, uncomment the attribute below. | ||
# include_runfiles = True | ||
) | ||
|
||
oci_image( | ||
name = "image", | ||
base = "@distroless_base", | ||
entrypoint = ["/app"], | ||
tars = [":app_layer"], | ||
) | ||
|
||
# This is the target that should be released to the target platform | ||
platform_transition_filegroup( | ||
name = "transitioned_image", | ||
srcs = [":image"], | ||
target_platform = select({ | ||
"@platforms//cpu:arm64": "@rules_go//go/toolchain:linux_arm64", | ||
"@platforms//cpu:x86_64": "@rules_go//go/toolchain:linux_amd64", | ||
}), | ||
) | ||
|
||
# $ bazel build projects/go_devops_cli_app:tarball | ||
# $ docker load --input $(bazel cquery --output=files projects/go_devops_cli_app:tarball) | ||
# $ docker run --rm flyr.io/go-devops-cli-app:latest | ||
# string( | ||
# - "Hello World", | ||
# + "Hello Go", | ||
# ) | ||
oci_tarball( | ||
name = "tarball", | ||
# Use the image built for the exec platform rather than the target platform | ||
image = ":image", | ||
repo_tags = [ | ||
"flyr.io/go-devops-cli-app:latest", | ||
], | ||
) | ||
|
||
# Skaffold needs a target ending with .tar | ||
oci_tarball( | ||
name = "tarball.tar", | ||
# Use the image built for the exec platform rather than the target platform | ||
image = ":image", | ||
repo_tags = ["go-devops-cli-app"], | ||
) | ||
|
||
# See: https://github.com/GoogleContainerTools/container-structure-test#running-structure-tests-through-bazel | ||
container_structure_test( | ||
name = "test", | ||
configs = ["tests/test.yaml"], | ||
# Use the image built for the exec platform rather than the target platform | ||
image = ":image", | ||
timeout = "short" | ||
) |
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 @@ | ||
# Overview | ||
|
||
Template for creating FastAPI projects. | ||
|
||
## Roadmap | ||
|
||
- [ ] Setup basic templating | ||
- [ ] Research Cookiecutter | ||
- [ ] Bake-in everything including best practices | ||
- [ ] Test and validate framework | ||
- [ ] Gather feedback from beta testers | ||
|
||
## Known issues | ||
|
||
- [ ] None yet |
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,8 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: bazel | ||
spec: | ||
containers: | ||
- name: bazel | ||
image: go-devops-cli-app |
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,19 @@ | ||
# See: | ||
# - https://github.com/GoogleContainerTools/skaffold/blob/main/examples/multi-config-microservices/skaffold.yaml | ||
# - https://github.com/GoogleContainerTools/skaffold/blob/main/examples/structure-tests/skaffold.yaml | ||
|
||
apiVersion: skaffold/v4beta5 | ||
kind: Config | ||
metadata: | ||
# skaffold dev -m go-devops-cli-app-config | ||
name: go-devops-cli-app-config | ||
build: | ||
artifacts: | ||
- image: go-devops-cli-app | ||
context: . | ||
bazel: | ||
# target: //projects/go_devops_cli_app:go_devops_cli_app_image.tar | ||
target: //projects/go_devops_cli_app:tarball.tar | ||
manifests: | ||
rawYaml: | ||
- kubernetes/* |
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,5 @@ | ||
module example.com/mod | ||
|
||
go 1.17 | ||
|
||
require github.com/google/go-cmp v0.5.9 |
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,2 @@ | ||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= | ||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= |
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,10 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func main() { | ||
fmt.Println(cmp.Diff("Hello World", "Hello Go")) | ||
} |
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,5 @@ | ||
schemaVersion: 2.0.0 | ||
commandTests: | ||
- name: 'test' | ||
command: '/app' | ||
expectedOutput: ['"Hello World"'] |
Oops, something went wrong.