Skip to content

Commit

Permalink
refactor: Redesign project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ipv1337 committed Jul 1, 2023
1 parent fc16634 commit 2b62eb1
Show file tree
Hide file tree
Showing 64 changed files with 160 additions and 123 deletions.
2 changes: 1 addition & 1 deletion CHEATSHEET.md → CHEATSHEET_BAZEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bazel clean --async

```
make dev_go_devops_cli_app
make dev_py_devops_fastapi_app
make dev_devops_fastapi_app
```

## General
Expand Down
58 changes: 31 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ query_libs:
query_projects:
bazel query //projects/...

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

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



Expand All @@ -54,14 +54,14 @@ build_libs:
build_projects:
bazel build //projects/...

build_base_py_fastapi_app:
bazel build //projects/base_py_fastapi_app/...
build_base_fastapi_app:
bazel build //projects/base_fastapi_app/...

build_py_devops_fastapi_app:
bazel build //projects/py_devops_fastapi_app:tarball
build_devops_fastapi_app:
bazel build //projects/devops_fastapi_app:tarball

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



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

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

test_py_devops_fastapi_app:
bazel test //projects/py_devops_fastapi_app/...
test_devops_fastapi_app:
bazel test //projects/devops_fastapi_app/...

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

test_py_calculator:
echo "TODO"
Expand All @@ -97,8 +97,8 @@ test_oci_py_helloworld_v2:



run_py_devops_fastapi_app:
bazel run //projects/py_devops_fastapi_app:run_bin
run_devops_fastapi_app:
bazel run //projects/devops_fastapi_app:run_bin

run_py_calculator:
bazel run //projects/py_calculator_cli_app:app
Expand All @@ -122,8 +122,8 @@ run_oci_py_helloworld_v2:



dev_base_py_fastapi_app:
skaffold dev -m base-py-fastapi-app-config
# dev_base_fastapi_app:
# skaffold dev -m base-fastapi-app-config

dev_go_devops_cli_app:
skaffold dev -m go-devops-cli-app-config
Expand All @@ -133,17 +133,17 @@ dev_go_devops_cli_app_debug:

# See: https://github.com/GoogleContainerTools/skaffold/issues/4033
# TODO: bazel support in the container does not work so we stick with local skaffold
dev_py_devops_fastapi_app:
skaffold dev -m py-devops-fastapi-app-config
# ./tools/scripts/skaffold_container.sh dev -m py-devops-fastapi-app-config
dev_devops_fastapi_app:
skaffold dev -m devops-fastapi-app-config
# ./tools/scripts/skaffold_container.sh dev -m devops-fastapi-app-config



skaffold_build_go_devops_cli_app:
skaffold build --quiet -m go-devops-cli-app-config

skaffold_build_py_devops_fastapi_app:
skaffold build -m py-devops-fastapi-app-config
skaffold_build_devops_fastapi_app:
skaffold build -m devops-fastapi-app-config



Expand All @@ -155,8 +155,8 @@ skaffold_run_go_devops_cli_app:
skaffold_render_go_devops_cli_app:
skaffold render -m go-devops-cli-app-config

skaffold_render_py_devops_fastapi_app:
skaffold render -m py-devops-fastapi-app-config
skaffold_render_devops_fastapi_app:
skaffold render -m devops-fastapi-app-config



Expand All @@ -169,6 +169,10 @@ minikube_eval:
minikube_images:
minikube image ls --format='table'

# See: https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/
minikube_ingress:
minikube addons enable ingress



watch:
Expand Down
4 changes: 2 additions & 2 deletions projects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ Where all project applications are implemented.
| Project Name | Short Description | Upstream | State | CODEOWNER |
|--------------|-------------------|-------|----------|----------|
| Example | My example project | None | Production | [John Doe](mailto://john.doe@email) |
| base_py_fastapi_app | Base project to extend | some_lib | Production | [James Nguyen](mailto://james.nguyen@flyrlabs.com) |
| base_fastapi_app | Base project to extend | some_lib | Production | [James Nguyen](mailto://james.nguyen@flyrlabs.com) |
| go_devops_cli_app | Example golang project with skaffold & bazel | base_go_franework_app | Development | [James Nguyen](mailto://james.nguyen@flyrlabs.com) |
| py_devops_fastapi_app | desc | base_py_fastapi_app | Development | [James Nguyen](mailto://james.nguyen@flyrlabs.com) |
| devops_fastapi_app | desc | base_fastapi_app | Development | [James Nguyen](mailto://james.nguyen@flyrlabs.com) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions projects/base_fastapi_app/CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Overview

Contribution etiquette and rules of the road.

7 changes: 7 additions & 0 deletions projects/base_fastapi_app/MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Overview

Document major changes requiring any migration actions between versions.

## Migrating v1 -> v2

* What manual actions are required...
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ py_library(
deps = [
requirement("other_pypi_libs"), # PyPi libs
"//libs/devops:devops_lib", # Internal libs
"//projects/base_py_fastapi_app:fastapi_lib", # This base project
"//projects/base_fastapi_app:fastapi_lib", # This base project
],
)
```
Expand Down
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ load("@container_structure_test//:defs.bzl", "container_structure_test")


py_library(
name = "main_lib",
name = "base_lib",
srcs = glob(["app/*.py"]),
# srcs_version = "PY3",
deps = [
# requirement("fastapi"),
"//libs/devops:devops_lib",
"//projects/base_py_fastapi_app:fastapi_lib",
"//projects/base_fastapi_app:fastapi_lib",
],
)

Expand All @@ -34,7 +34,7 @@ py_binary(
visibility = ["//visibility:public"],
deps = [
requirement("uvicorn"),
":main_lib",
":base_lib",
],
)

Expand All @@ -46,7 +46,7 @@ py_test(
requirement("requests"),
requirement("httpx"),
requirement("fastapi"),
":main_lib",
":base_lib",
":run_bin",
],
)
Expand Down Expand Up @@ -75,7 +75,7 @@ py_image_layer(
oci_image(
name = "app_image",
base = "@distroless_python",
entrypoint = ["/opt/projects/py_devops_fastapi_app/run_bin"],
entrypoint = ["/opt/projects/devops_fastapi_app/run_bin"],
tars = [":app_layer"],
)

Expand Down Expand Up @@ -104,15 +104,15 @@ platform_transition_filegroup(
}),
)

# $ bazel build //projects/py_devops_fastapi_app:tarball
# $ docker load --input $(bazel cquery --output=files //projects/py_devops_fastapi_app:tarball)
# $ docker run --rm local/py_devops_fastapi_app:latest
# $ bazel build //projects/devops_fastapi_app:tarball
# $ docker load --input $(bazel cquery --output=files //projects/devops_fastapi_app:tarball)
# $ docker run --rm local/devops_fastapi_app:latest
# See: https://github.com/bazel-contrib/rules_oci/blob/main/docs/tarball.md
oci_tarball(
name = "tarball",
image = ":app_image",
repo_tags = [
"flyr.io/bazel/py-devops-fastapi-app:latest",
"flyr.io/bazel/devops-fastapi-app:latest",
],
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from libs.devops.models.devops import DevOps, InfrastructureEngineer, DeveloperExperienceEngineer, DataEngineer, MachineLearningEngineer, WebEngineer, ReliabilityEngineer, PlatformEngineer, PlatformOrganization

from projects.base_py_fastapi_app.app.main import app, logging
from projects.base_fastapi_app.app.main import app, logging

logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
if __name__ == "__main__":
# freeze_support()
uvicorn.run(
"projects.py_devops_fastapi_app.app.main:app",
"projects.devops_fastapi_app.app.main:app",
# "--proxy-headers", # when running behind TLS termination proxy
host="0.0.0.0",
port=5000,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See: https://helm.sh/docs/topics/charts/
apiVersion: v2
name: py-devops-fastapi-app-chart
name: devops-fastapi-app-chart
description: Demo DevOps FastAPI App Helm Chart
keywords:
- FastAPI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ chartManagedNS: true
replicaCount: 1

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

Expand Down Expand Up @@ -48,12 +48,12 @@ ingress:
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: py-devops-fastapi-app.local
- host: devops-fastapi-app.local
paths: []
tls: []
# - secretName: py-devops-fastapi-app-tls
# - secretName: devops-fastapi-app-tls
# hosts:
# - py-devops-fastapi-app.local
# - devops-fastapi-app.local

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
apiVersion: v1
kind: Service
metadata:
name: py-devops-fastapi-app
name: devops-fastapi-app
labels:
app: py-devops-fastapi-app
app: devops-fastapi-app
spec:
clusterIP: None
ports:
- port: 5000
name: py-devops-fastapi-app
name: devops-fastapi-app
selector:
app: py-devops-fastapi-app
app: devops-fastapi-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: py-devops-fastapi-app
name: devops-fastapi-app
labels:
app: py-devops-fastapi-app
app: devops-fastapi-app
spec:
replicas: 1
selector:
matchLabels:
app: py-devops-fastapi-app
app: devops-fastapi-app
template:
metadata:
labels:
app: py-devops-fastapi-app
app: devops-fastapi-app
spec:
containers:
- name: py-devops-fastapi-app
image: flyr.io/bazel/py-devops-fastapi-app
- name: devops-fastapi-app
image: flyr.io/bazel/devops-fastapi-app
ports:
- containerPort: 5000
name: http
3 changes: 3 additions & 0 deletions projects/devops_fastapi_app/kustomize/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Reference

- https://github.com/kubernetes-sigs/kustomize/tree/master/examples
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: py-devops-fastapi-app
name: devops-fastapi-app
labels:
app: py-devops-fastapi-app
app: devops-fastapi-app
spec:
replicas: 1
selector:
matchLabels:
app: py-devops-fastapi-app
app: devops-fastapi-app
template:
metadata:
labels:
app: py-devops-fastapi-app
app: devops-fastapi-app
spec:
containers:
- name: py-devops-fastapi-app
image: flyr.io/bazel/py-devops-fastapi-app
- name: devops-fastapi-app
image: flyr.io/bazel/devops-fastapi-app
ports:
- containerPort: 5000
name: http
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resources:
- deployment.yaml
- service.yaml
configMapGenerator:
- name: py-devops-fastapi-app-configmap
- name: devops-fastapi-app-configmap
# behavior: merge
files:
- application.properties
13 changes: 13 additions & 0 deletions projects/devops_fastapi_app/kustomize/base/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: devops-fastapi-app
labels:
app: devops-fastapi-app
spec:
clusterIP: None
ports:
- port: 5000
name: devops-fastapi-app
selector:
app: devops-fastapi-app
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namePrefix: dev-
# patches:
# - path: patch.yaml
configMapGenerator:
- name: py-devops-fastapi-app-configmap
- name: devops-fastapi-app-configmap
behavior: replace
files:
- application.properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: py-devops-fastapi-app-configmap
name: devops-fastapi-app-configmap
data:
application.properties: |
app.name=Development DevOps FastAPI App Patched
Expand Down
Loading

0 comments on commit 2b62eb1

Please sign in to comment.