Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,20 @@ compiler/report.json
compiler/cmd/debug
compiler/coverage.json
compiler/report.json
compiler/cmd/validate
artifacts/
node_modules
TAG

# api datamodel build artifacts
api/build/*

# api-gw artifacts
api-gw/api-gw
api-gw/bin/*

# k0s artifacts
nexus-runtime-manifests/k0s/.kubeconfig

# playgound app directory
sock-shop-saas-app/*
162 changes: 162 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
DOCKER_GO_PATH ?= /go
DOCKER_BUILD_MOUNT_DIR ?= ${DOCKER_GO_PATH}/src/github.com/vmware-tanzu/graph-framework-for-microservices
API_GW_COMPONENT_NAME ?= api-gw
CLI_DIR ?= cli
HOST_KUBECONFIG ?= ${HOME}/.kube/config
MOUNTED_KUBECONFIG ?= /etc/config/kubeconfig
RUNTIME_NAMESPACE ?= default
UNAME_S ?= $(shell uname -s)
DATAMODEL_NAME ?= $(shell grep groupName ${DATAMODEL_DIR}/nexus.yaml | cut -f 2 -d" " | tr -d '"')
DATAMODEL_IMAGE_NAME ?= $(shell grep dockerRepo ${DATAMODEL_DIR}/nexus.yaml | cut -f 2 -d" ")
TAG ?= $(shell cat TAG | awk '{ print $1 }')

.PHONY: cli.build.darwin
cli.build.darwin:
docker run \
--pull=missing \
--volume $(realpath .):${DOCKER_BUILD_MOUNT_DIR} \
-w ${DOCKER_BUILD_MOUNT_DIR}/${CLI_DIR} \
golang:1.19.8 \
/bin/bash -c "go mod download && make build.darwin";

.PHONY: cli.build.linux
cli.build.linux:
docker run \
--pull=missing \
--volume $(realpath .):${DOCKER_BUILD_MOUNT_DIR} \
-w ${DOCKER_BUILD_MOUNT_DIR}/${CLI_DIR} \
golang:1.19.8 \
/bin/bash -c "go mod download && make build.linux";

.PHONY: cli.install.darwin
cli.install.darwin:
cd cli; make install.darwin

.PHONY: cli.install.linux
cli.install.linux:
cd cli; make install.linux

.PHONY: compiler.build
compiler.build:
cd compiler; BUILDER_TAG=${TAG} make docker.builder
cd compiler; BUILDER_TAG=${TAG} TAG=${TAG} make docker

.PHONY: api-gw.docker
api-gw.docker:
docker run \
--pull=missing \
--volume $(realpath .):${DOCKER_BUILD_MOUNT_DIR} \
-w ${DOCKER_BUILD_MOUNT_DIR}/${API_GW_COMPONENT_NAME} \
golang:1.19.8 \
/bin/bash -c "go mod download && GOOS=linux GOARCH=amd64 go build -buildvcs=false -o bin/${API_GW_COMPONENT_NAME}";
docker build -t ${API_GW_COMPONENT_NAME}:${TAG} -f api-gw/Dockerfile .

.PHONY: k0s.install
k0s.install:
$(realpath .)/nexus-runtime-manifests/k0s/run_k0s.sh

.PHONY: k0s.uninstall
k0s.uninstall:
$(realpath .)/nexus-runtime-manifests/k0s/stop_k0s.sh

.PHONY: dm.install_init
dm.install_init: HOST_KUBECONFIG=$(realpath .)/nexus-runtime-manifests/k0s/.kubeconfig
dm.install_init:
docker run \
--net host \
--pull=missing \
--volume $(realpath .):${DOCKER_BUILD_MOUNT_DIR} \
-w ${DOCKER_BUILD_MOUNT_DIR}/nexus-runtime-manifests/datamodel-install \
--mount type=bind,source=${HOST_KUBECONFIG},target=${MOUNTED_KUBECONFIG},readonly \
alpine/helm \
upgrade --install datamodel-install-scripts . --set global.namespace=${RUNTIME_NAMESPACE} --kubeconfig ${MOUNTED_KUBECONFIG}

.PHONY: api.build
api.build:
cd api; TAG=${TAG} VERSION=${TAG} make datamodel_build

.PHONY: api.install
api.install:
docker run \
--entrypoint /datamodel_installer.sh \
--net host \
--pull=missing \
--volume $(realpath .)/api/build/crds:/crds \
--mount type=bind,source=${HOST_KUBECONFIG},target=${MOUNTED_KUBECONFIG},readonly \
--mount type=bind,source=$(realpath .)/nexus-runtime-manifests/datamodel-install/datamodel_installer.sh,target=/datamodel_installer.sh,readonly \
-e KUBECONFIG=${MOUNTED_KUBECONFIG} \
-e NAME=nexus.vmware.com \
-e IMAGE=gcr.io/nsx-sm/nexus/nexus-api \
bitnami/kubectl

.PHONY: api-gw.run
api-gw.run: HOST_KUBECONFIG=$(realpath .)/nexus-runtime-manifests/k0s/.kubeconfig
api-gw.run: api-gw.stop
ifeq (${UNAME_S}, Linux)
docker run -d \
--name=nexus-api-gw \
--rm \
--network host \
--pull=missing \
--mount type=bind,source=${HOST_KUBECONFIG},target=${MOUNTED_KUBECONFIG},readonly \
--mount type=bind,source=$(realpath .)/${API_GW_COMPONENT_NAME}/deploy/config/api-gw-config.yaml,target=/api-gw-config.yaml,readonly \
-e APIGWCONFIG=/api-gw-config.yaml \
-e KUBECONFIG=${MOUNTED_KUBECONFIG} \
-e KUBEAPI_ENDPOINT="127.0.0.1:8001" \
${API_GW_COMPONENT_NAME}:${TAG}
else
APIGWCONFIG=$(realpath .)/${API_GW_COMPONENT_NAME}/deploy/config/api-gw-config.yaml KUBECONFIG=${HOST_KUBECONFIG} $(realpath .)/${API_GW_COMPONENT_NAME}/bin/${API_GW_COMPONENT_NAME}
endif

.PHONY: api-gw.stop
api-gw.stop:
docker rm -f nexus-api-gw > /dev/null || true

.PHONY: runtime.build
runtime.build: compiler.build api.build api-gw.docker

.PHONY: clean.runtime
clean.runtime:
rm -rf api/build/*

.PHONY: runtime.install.k0s
runtime.install.k0s: HOST_KUBECONFIG=$(realpath .)/nexus-runtime-manifests/k0s/.kubeconfig
runtime.install.k0s: k0s.install dm.install_init api.install api-gw.run
$(info )
$(info ====================================================)
$(info To access runtime, you can execute kubectl as:)
$(info kubectl -s localhost:8082 ...)
$(info )
$(info )
$(info To access nexus aip gateway using kubeconfig, export:)
$(info export HOST_KUBECONFIG=${HOST_KUBECONFIG})
$(info )
$(info ====================================================)

.PHONY: runtime.uninstall.k0s
runtime.uninstall.k0s: k0s.uninstall
$(info )
$(info ====================================================)
$(info Runtime is now uninstalled)
$(info ====================================================)

.PHONY: dm.check-datamodel-dir
dm.check-datamodel-dir:
ifndef DATAMODEL_DIR
$(error DATAMODEL_DIR is mandatory)
endif

.PHONY: dm.install
dm.install: dm.check-datamodel-dir
docker run \
--net host \
--pull=missing \
--volume ${DATAMODEL_DIR}/build/crds:/crds \
--mount type=bind,source=${HOST_KUBECONFIG},target=${MOUNTED_KUBECONFIG},readonly \
--mount type=bind,source=$(realpath .)/nexus-runtime-manifests/datamodel-install/datamodel_installer.sh,target=/datamodel_installer.sh,readonly \
--entrypoint /datamodel_installer.sh \
-e KUBECONFIG=${MOUNTED_KUBECONFIG} \
-e NAME=${DATAMODEL_NAME} \
-e IMAGE=${DATAMODEL_IMAGE_NAME} \
bitnami/kubectl

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ https://user-images.githubusercontent.com/49454273/236900473-216421d5-c9da-456c-
<br>

## [Playground](docs/getting_started/Playground.md)
## [Playground Lite](docs/getting_started/Playground-Lite.md)

<br>

Expand Down
49 changes: 1 addition & 48 deletions api-gw/Dockerfile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,53 +1,6 @@
# syntax = harbor-repo.vmware.com/dockerhub-proxy-cache/docker/dockerfile:1.3
FROM harbor-repo.vmware.com/nexus/golang:1.19.8 AS builder
ARG GIT_TAG
ARG GIT_HEAD
ARG CICD_TOKEN
ARG APP_NAME
ARG USE_SSH
RUN mkdir -p /root/.ssh && \
chmod 0700 /root/.ssh
COPY .ssh/ /root/.ssh/
WORKDIR /api-gw
ENV GOPRIVATE *.eng.vmware.com
ENV GOINSECURE *.eng.vmware.com
ENV CGO_ENABLED=0
COPY go.* .
# Required for access to GO artifactory
RUN git config --global credential.helper store
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
COPY docs docs
# Copy the go source
COPY main.go main.go
COPY controllers/ controllers/
COPY internal/ internal/
COPY pkg/ pkg/
COPY test/ test/
COPY nexus/ nexus/
#Intialize go deps
RUN \
if [ "x$USE_SSH" = "xTRUE" ] || [ "x$USE_SSH" = "xtrue" ] ;\
then \
tdnf --refresh install -y openssh && \
chmod -R 0600 /root/.ssh/* && \
git config --global --add url."git@gitlab.eng.vmware.com:".insteadOf "https://gitlab.eng.vmware.com/" &&\
go mod download ;\
else \
echo "https://gitlab-ci-token:${CICD_TOKEN}@gitlab.eng.vmware.com" >> ~/.git-credentials && \
git config --global credential.helper store && \
go mod download ;\
fi

# Build
RUN --mount=type=cache,target=/root/.cache/go-build \
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X gitlab.eng.vmware.com/nsx-allspark_users/lib-go/allspark/health.Sha=$GIT_HEAD -X gitlab.eng.vmware.com/nsx-allspark_users/lib-go/allspark/health.Tag=$GIT_TAG" -o bin/api-gw main.go

FROM gcr.io/nsx-sm/photon:4.0
WORKDIR /bin
ARG APP_NAME
COPY --from=builder /api-gw/bin/api-gw .
COPY /api-gw/bin/api-gw .
USER 65532:65532
ENTRYPOINT "/bin/api-gw"

4 changes: 2 additions & 2 deletions api-gw/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ build: lint ## Build manager binary.
--build-arg GIT_HEAD=${GIT_HEAD} \
--build-arg GIT_TAG=${CI_COMMIT} \
--build-arg CICD_TOKEN=${CICD_TOKEN} \
-t ${IMAGE_REGISTRY}:${IMAGE_TAG} . ;\
-t ${IMAGE_REGISTRY}:${IMAGE_TAG} --progress=plain --no-cache -f Dockerfile.build;\
else \
test -s ~/.ssh || { echo "Please provide CICD_TOKEN if ssh not available."; exit 1; }; \
cp -rf ~/.ssh/* .ssh ;\
DOCKER_BUILDKIT=1 docker build --build-arg APP_NAME=${APP_NAME} \
--build-arg GIT_HEAD=${GIT_HEAD} \
--build-arg GIT_TAG=${CI_COMMIT} \
--build-arg USE_SSH="true" \
-t ${IMAGE_REGISTRY}:${IMAGE_TAG} . ;\
-t ${IMAGE_REGISTRY}:${IMAGE_TAG} --progress=plain --no-cache -f Dockerfile.build;\
fi

##@ Test
Expand Down
2 changes: 1 addition & 1 deletion api-gw/controllers/cors_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"

log "github.com/sirupsen/logrus"
domain_nexus_org "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/domain.nexus.vmware.com/v1"
domain_nexus_org "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/domain.nexus.vmware.com/v1"
"k8s.io/apimachinery/pkg/runtime"

ctrl "sigs.k8s.io/controller-runtime"
Expand Down
2 changes: 1 addition & 1 deletion api-gw/controllers/cors_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
yamlv1 "github.com/ghodss/yaml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
domain_nexus_org "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/domain.nexus.vmware.com/v1"
domain_nexus_org "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/domain.nexus.vmware.com/v1"
)

var _ = Describe("OidcConfig controller", func() {
Expand Down
2 changes: 1 addition & 1 deletion api-gw/controllers/oidcconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"

log "github.com/sirupsen/logrus"
authnexusv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/authentication.nexus.vmware.com/v1"
authnexusv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/authentication.nexus.vmware.com/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down
2 changes: 1 addition & 1 deletion api-gw/controllers/oidcconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
yamlv1 "github.com/ghodss/yaml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
authenticationnexusv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/authentication.nexus.vmware.com/v1"
authenticationnexusv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/authentication.nexus.vmware.com/v1"
)

var _ = Describe("OidcConfig controller", func() {
Expand Down
2 changes: 1 addition & 1 deletion api-gw/controllers/proxyrule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"fmt"

log "github.com/sirupsen/logrus"
adminnexusorgv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/admin.nexus.vmware.com/v1"
adminnexusorgv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/admin.nexus.vmware.com/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down
2 changes: 1 addition & 1 deletion api-gw/controllers/proxyrule_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
adminv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/admin.nexus.vmware.com/v1"
adminv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/admin.nexus.vmware.com/v1"
)

var _ = Describe("ProxyRule controller", func() {
Expand Down
2 changes: 1 addition & 1 deletion api-gw/controllers/route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

routenexusorgv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/route.nexus.vmware.com/v1"
routenexusorgv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/route.nexus.vmware.com/v1"
)

// RouteReconciler reconciles a Route object
Expand Down
6 changes: 3 additions & 3 deletions api-gw/controllers/route_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
yamlv1 "github.com/ghodss/yaml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
apiv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/api.nexus.vmware.com/v1"
configv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/config.nexus.vmware.com/v1"
routev1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/route.nexus.vmware.com/v1"
apiv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/api.nexus.vmware.com/v1"
configv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/config.nexus.vmware.com/v1"
routev1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/route.nexus.vmware.com/v1"
)

var _ = Describe("Route controller", func() {
Expand Down
21 changes: 9 additions & 12 deletions api-gw/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (
"testing"
"time"

adminnexusv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/admin.nexus.vmware.com/v1"
apinexusv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/api.nexus.vmware.com/v1"
authenticationnexusv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/authentication.nexus.vmware.com/v1"
confignexusv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/config.nexus.vmware.com/v1"
domain_nexus_org_v1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/domain.nexus.vmware.com/v1"
routenexusv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/route.nexus.vmware.com/v1"
tenantv1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/tenantconfig.nexus.vmware.com/v1"
tenantruntimev1 "golang-appnet.eng.vmware.com/nexus-sdk/api/build/apis/tenantruntime.nexus.vmware.com/v1"
adminnexusv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/admin.nexus.vmware.com/v1"
apinexusv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/api.nexus.vmware.com/v1"
authenticationnexusv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/authentication.nexus.vmware.com/v1"
confignexusv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/config.nexus.vmware.com/v1"
domain_nexus_org_v1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/domain.nexus.vmware.com/v1"
routenexusv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/route.nexus.vmware.com/v1"
tenantv1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/tenantconfig.nexus.vmware.com/v1"
tenantruntimev1 "github.com/vmware-tanzu/graph-framework-for-microservices/api/build/apis/tenantruntime.nexus.vmware.com/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes/scheme"
Expand All @@ -43,7 +43,6 @@ import (
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
//+kubebuilder:scaffold:imports
Expand All @@ -64,9 +63,7 @@ var (
func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

RunSpecsWithDefaultAndCustomReporters(t,
"Controller Suite",
[]Reporter{printer.NewlineReporter{}})
RunSpecs(t, "Controller Suite")
}

var _ = BeforeSuite(func() {
Expand Down
Loading