Skip to content

Commit

Permalink
Add helm support along with remote builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ipv1337 committed Jun 26, 2023
1 parent 3b95f1c commit cfb5418
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import %workspace%/.aspect/bazelrc/debug.bazelrc
import %workspace%/.aspect/bazelrc/javascript.bazelrc
import %workspace%/.aspect/bazelrc/performance.bazelrc

# See: https://app.buildbuddy.io/docs/setup
# Buildbuddy support for remote builds
import %workspace%/.buildbuddy/remote.bazelrc

### YOUR PROJECT SPECIFIC OPTIONS GO HERE ###

coverage --java_runtime_version=remotejdk_11
Expand Down
24 changes: 24 additions & 0 deletions .buildbuddy/remote.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See:
# - https://app.buildbuddy.io/docs/setup
# - https://www.buildbuddy.io/docs/rbe-setup
# - https://www.buildbuddy.io/docs/rbe-github-actions

build:remote --host_platform=@buildbuddy_toolchain//:platform
build:remote --platforms=@buildbuddy_toolchain//:platform
build:remote --extra_execution_platforms=@buildbuddy_toolchain//:platform
build:remote --crosstool_top=@buildbuddy_toolchain//:toolchain
build:remote --extra_toolchains=@buildbuddy_toolchain//:cc_toolchain
build:remote --bes_results_url=https://app.buildbuddy.io/invocation/
build:remote --bes_backend=grpcs://remote.buildbuddy.io
build:remote --remote_executor=grpcs://remote.buildbuddy.io
build:remote --remote_cache=grpcs://remote.buildbuddy.io
build:remote --remote_timeout=3600
build:remote --remote_header=x-buildbuddy-api-key=M6xoyCQXGmbU7SyJx6GO
build:remote --jobs=50
build:remote --define=EXECUTOR=remote


build:ci --build_metadata=ROLE=CI
build:ci --bes_results_url=https://app.buildbuddy.io/invocation/
build:ci --bes_backend=grpcs://remote.buildbuddy.io
# build:ci --build_metadata=VISIBILITY=PUBLIC
24 changes: 19 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: CI
on: [push]

jobs:
test:
build:
# virtual environments: https://github.com/actions/virtual-environments
runs-on: ubuntu-20.04

Expand All @@ -21,12 +21,26 @@ jobs:

# Checks-out your repository under $GITHUB_WORKSPACE, which is the CWD for
# the rest of the steps
- uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v3

- name: Run the test
run: bazel test //...
# See: https://www.buildbuddy.io/docs/rbe-github-actions
# Use remote build (BuildBuddy)
- name: Build the code
run: bazel build //...
run: |
bazel build \
--config=ci \
--remote_header=x-buildbuddy-api-key=${{ secrets.BUILDBUDDY_ORG_API_KEY }} \
//...
# See: https://www.buildbuddy.io/docs/rbe-github-actions
# Use remote build (BuildBuddy)
- name: Run the test
run: |
bazel test \
--config=ci \
--remote_header=x-buildbuddy-api-key=${{ secrets.BUILDBUDDY_ORG_API_KEY }} \
//...
# name: CI

Expand Down
6 changes: 6 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ bazel_dep(name = "rules_go", version = "0.39.1")
# bazel_dep(name = "gazelle", version = "0.31.0", repo_name = "bazel_gazelle")
bazel_dep(name = "gazelle", version = "0.31.0")



################################################################################
# rules_oci
################################################################################

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")

oci.toolchains(crane_version = "v0.14.0")
Expand Down
31 changes: 27 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test:
bazel test //...

.PHONY: clean
clean: clean_docker_images
clean:
bazel clean --async

.PHONY: update
Expand All @@ -29,8 +29,22 @@ update_python_requirements:



clean_docker_images:
./tools/scripts/docker_images_rmi.sh
clean_docker:
./tools/scripts/docker_cleanup.sh



query_libs:
bazel query //libs/...

query_projects:
bazel query //projects/...

query_base_py_fastapi_app:
bazel query //projects/base_py_fastapi_app/...

query_py_devops_fastapi_app:
bazel query //projects/py_devops_fastapi_app/...



Expand All @@ -46,6 +60,9 @@ build_base_py_fastapi_app:
build_py_devops_fastapi_app:
bazel build //projects/py_devops_fastapi_app:tarball

build_py_devops_fastapi_app_remote:
bazel build //projects/py_devops_fastapi_app/... --config=remote



test_libs:
Expand All @@ -54,8 +71,14 @@ test_libs:
test_projects:
bazel test //projects/...

test_base_py_fastapi_app:
bazel test //projects/base_py_fastapi_app/...

test_py_devops_fastapi_app:
bazel test //projects/py_devops_fastapi_app:web_app_test
bazel test //projects/py_devops_fastapi_app/...

test_py_devops_fastapi_app_remote:
bazel test //projects/py_devops_fastapi_app/... --config=remote

test_py_calculator:
echo "TODO"
Expand Down
23 changes: 23 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ install_deps()



#
# BuildBuddy
#

# See: https://github.com/buildbuddy-io/buildbuddy-toolchain

http_archive(
name = "io_buildbuddy_buildbuddy_toolchain",
sha256 = "e899f235b36cb901b678bd6f55c1229df23fcbc7921ac7a3585d29bff2bf9cfd",
strip_prefix = "buildbuddy-toolchain-fd351ca8f152d66fc97f9d98009e0ae000854e8f",
urls = ["https://github.com/buildbuddy-io/buildbuddy-toolchain/archive/fd351ca8f152d66fc97f9d98009e0ae000854e8f.tar.gz"],
)

load("@io_buildbuddy_buildbuddy_toolchain//:deps.bzl", "buildbuddy_deps")

buildbuddy_deps()

load("@io_buildbuddy_buildbuddy_toolchain//:rules.bzl", "buildbuddy", "UBUNTU20_04_IMAGE")

buildbuddy(name = "buildbuddy_toolchain", container_image = UBUNTU20_04_IMAGE)



#
# rules_docker
#
Expand Down
3 changes: 3 additions & 0 deletions libs/calculator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

Simple calculator library example.

## Roadmap

- [ ] Expand this example using [this](https://github.com/GoogleCloudPlatform/professional-services/tree/main/examples/python-cicd-with-cloudbuilder)
29 changes: 14 additions & 15 deletions projects/py_devops_fastapi_app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ load("@container_structure_test//:defs.bzl", "container_structure_test")

py_library(
name = "main_lib",
srcs = ["app/main.py"],
srcs = glob(["app/*.py"]),
# srcs_version = "PY3",
deps = [
# requirement("fastapi"),
Expand All @@ -38,23 +38,9 @@ py_binary(
],
)

# pytest_test(
# name = "webapp_test",
# srcs = glob(["tests/*.py"]),
# timeout = "short",
# deps = [
# requirement("requests"),
# requirement("httpx"),
# requirement("fastapi"),
# ":webapp",
# ":run",
# ],
# )

py_test(
name = "main_test",
srcs = glob(["tests/*.py"]),
# srcs = ["tests/webapp_test.py"],
timeout = "short",
deps = [
requirement("requests"),
Expand All @@ -65,6 +51,19 @@ py_test(
],
)

# pytest_test(
# name = "webapp_test",
# srcs = glob(["tests/*.py"]),
# timeout = "short",
# deps = [
# requirement("requests"),
# requirement("httpx"),
# requirement("fastapi"),
# ":webapp",
# ":run",
# ],
# )

py_image_layer(
name = "app_layer",
binary = ":run_bin",
Expand Down
31 changes: 31 additions & 0 deletions projects/py_devops_fastapi_app/helm-charts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# See: https://helm.sh/docs/topics/charts/
apiVersion: v2
name: py-devops-fastapi-app-chart
version: 1.0.1
description: Demo DevOps FastAPI APP
type: application
appVersion: "0.1.1"
keywords:
- FastAPI
- Demo
# home: The URL of this projects home page (optional)
# sources:
# - A list of URLs to source code for this project (optional)
# dependencies: # A list of the chart requirements (optional)
# - name: The name of the chart (nginx)
# version: The version of the chart ("1.2.3")
# repository: (optional) The repository URL ("https://example.com/charts") or alias ("@repo-name")
# condition: (optional) A yaml path that resolves to a boolean, used for enabling/disabling charts (e.g. subchart1.enabled )
# tags: # (optional)
# - Tags can be used to group charts for enabling/disabling together
# import-values: # (optional)
# - ImportValues holds the mapping of source values to parent key to be imported. Each item can be a string or pair of child/parent sublist items.
# alias: (optional) Alias to be used for the chart. Useful when you have to add the same chart multiple times
# maintainers: # (optional)
# - name: The maintainers name (required for each maintainer)
# email: The maintainers email (optional for each maintainer)
# url: A URL for the maintainer (optional for each maintainer)
# icon: A URL to an SVG or PNG image to be used as an icon (optional).
# deprecated: Whether this chart is deprecated (optional, boolean)
# annotations:
# example: A list of annotations keyed by name (optional).
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Chart.Name }}
labels:
app: {{ .Chart.Name }}
spec:
selector:
matchLabels:
app: {{ .Chart.Name }}
replicas: {{ .Values.replicaCount }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: {{ .Values.image }}
13 changes: 13 additions & 0 deletions projects/py_devops_fastapi_app/helm-charts/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Chart.Name }}
labels:
app: {{ .Chart.Name }}
spec:
clusterIP: None
ports:
- port: 5000
name: {{ .Chart.Name }}
selector:
app: {{ .Chart.Name }}
16 changes: 16 additions & 0 deletions projects/py_devops_fastapi_app/helm-charts/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Default values for acp-client-remake.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

chartManagedNS: true

image:
repository: flyr.io/bazel/py-devops-fastapi-app
pullPolicy: IfNotPresent
tag: "latest" # appset override

service:
type: ClusterIP
port: 5000

replicaCount: 1
23 changes: 18 additions & 5 deletions projects/py_devops_fastapi_app/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# See: https://skaffold.dev/docs/references/yaml/
apiVersion: skaffold/v4beta5
kind: Config
metadata:
Expand All @@ -18,22 +19,34 @@ build:
- bin/**
- tests/**
- kubernetes/**
- helm-charts/**
- ./BUILD.bazel
- ./build.sh
- ./skaffold.yaml
ignore:
- ./**.md
- tmp/**

manifests:
rawYaml:
- kubernetes/*
# manifests:
# rawYaml:
# - kubernetes/*

deploy:
helm:
releases:
- name: py-devops-fastapi-app-chart
chartPath: ./helm-charts
overrides:
image: flyr.io/bazel/py-devops-fastapi-app

portForward:
- resourceType: deployment
resourceName: py-devops-fastapi-app
port: http
resourceName: py-devops-fastapi-app-chart
port: 5000
localPort: 5000



# - image: my-app:latest
# bazel:
# target: //my-app:image
Expand Down
9 changes: 9 additions & 0 deletions tools/scripts/docker_cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

# See: https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes

# Remove all container "flyr" images
docker images -a | grep "flyr" | awk '{print $3}' | xargs docker rmi -f

# Remove all exited containers
docker rm $(docker ps -a -f status=exited -q)
3 changes: 0 additions & 3 deletions tools/scripts/docker_images_rmi.sh

This file was deleted.

0 comments on commit cfb5418

Please sign in to comment.