Skip to content

Commit

Permalink
Updates to move from static SDK files to "go get" SDK module. (#24)
Browse files Browse the repository at this point in the history
* Setting up for prebuilt go get SM SDK with binaries

* Updates from testing with temporary "go get" module

* Replacing the temporary module with the final SDK module
  • Loading branch information
jhbeskow authored Jun 4, 2024
1 parent 5b1c1c1 commit a307886
Show file tree
Hide file tree
Showing 24 changed files with 84 additions and 1,632 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
# Ignore build and test binaries.
bin/
!bin/libbitwarden_c.so
bw-sdk/internal/cinterface/lib/*
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Dockerfile.cross
*~

sm-operator.tar
bw-sdk/internal/cinterface/lib/*
**/__debug_bin*
**/temp.zip
**/.env
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"mode": "debug",
"program": "${workspaceFolder}/cmd/main.go",
"cwd": "${workspaceFolder}",
"buildFlags": ["-ldflags='-linkmode external -extldflags \"-static\"'"],
"buildFlags": ["-ldflags='-linkmode external -extldflags \"-static -Wl,-unresolved-symbols=ignore-all\"'"],
"envFile": "${workspaceFolder}/.env",
"env": {
"CC": "musl-gcc"
Expand All @@ -24,7 +24,7 @@
"mode": "test",
"program": "${relativeFileDirname}",
"cwd": "${relativeFileDirname}",
"buildFlags": ["-ldflags='-linkmode external -extldflags \"-static\"'"],
"buildFlags": ["-ldflags='-linkmode external -extldflags \"-static -Wl,-unresolved-symbols=ignore-all\"'"],
"env": {
"CC": "musl-gcc"
}
Expand Down
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ WORKDIR /workspace

COPY go.mod go.mod
COPY go.sum go.sum
COPY bw-sdk/ bw-sdk/

RUN go mod download

Expand All @@ -18,11 +17,9 @@ COPY Makefile Makefile

RUN apt update && apt install unzip musl-tools -y

RUN GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} make binaries

RUN mkdir state

RUN CC=musl-gcc CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags '-linkmode external -extldflags "-static"' -o manager cmd/main.go
RUN CC=musl-gcc CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags '-linkmode external -extldflags "-static -Wl,-unresolved-symbols=ignore-all"' -o manager cmd/main.go

FROM gcr.io/distroless/base-debian12:nonroot
WORKDIR /
Expand Down
27 changes: 5 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,8 @@ all: build
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: binaries
OS=$(shell go env GOOS)
ARCH=$(shell go env GOARCH)
OS_STRING=unknown-linux-gnu
ARCH_STRING=x86_64
ifeq ($(OS),windows)
OS_STRING=pc-windows-msvc
endif
ifeq ($(OS),darwin)
OS_STRING=apple-darwin
endif
ifeq ($(ARCH),arm64)
ARCH_STRING=aarch64
endif
binaries: ## Setting up the SDK binaries. The URL in use is temporary.
mkdir -p bw-sdk/internal/cinterface/lib
curl -sSLo temp.zip --url https://github.com/coltonhurst/go-module-test/releases/download/test-release/libbitwarden_c_files-$(ARCH_STRING)-$(OS_STRING)-$(SDKBINARYVERSION).zip && unzip -o -q temp.zip -d bw-sdk/internal/cinterface/lib && rm temp.zip

.PHONY: setup
setup: binaries ## Setting up the SDK binaries and setting up the sample .env file for use. The URL in use is temporary.
setup: ## Setting up the sample .env file for use.
ifeq ("$(wildcard .env)","")
cp .env.example .env
endif
Expand All @@ -140,17 +122,17 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
CC=musl-gcc KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -ldflags '-linkmode external -extldflags "-static"' ./... -coverprofile cover.out
CC=musl-gcc KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -ldflags '-linkmode external -extldflags "-static -Wl,-unresolved-symbols=ignore-all"' ./... -coverprofile cover.out

##@ Build

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
CC=musl-gcc go build -ldflags '-linkmode external -extldflags "-static"' -o bin/manager cmd/main.go
CC=musl-gcc go build -ldflags '-linkmode external -extldflags "-static -Wl,-unresolved-symbols=ignore-all"' -o bin/manager cmd/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
CC=musl-gcc go run -ldflags '-linkmode external -extldflags "-static"' ./cmd/main.go
CC=musl-gcc go run -ldflags '-linkmode external -extldflags "-static -Wl,-unresolved-symbols=ignore-all"' ./cmd/main.go

# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
Expand Down Expand Up @@ -246,6 +228,7 @@ $(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

## This has been locked down to an older version of envtest that supports 1.21. When Operator-SDK supports 1.22, we can move back to using latest
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ You will need a Kubernetes cluster to run against. We recommend [KIND](https://s

**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).

This project uses the Secrets Manager golang SDK. This SDK requires some binaries exist inside the project. Run `make setup` to download the appropriate binaries into the project. If you are using the Dev Container, this step has already been completed for you.
Run `make setup` to generate an example `.env` file. If you are using the Dev Container, this step has already been completed for you.

### Pre-requisites

Expand All @@ -35,7 +35,6 @@ For manual Linux setups:
* [Visual Studio Code Go Extension](https://marketplace.visualstudio.com/items?itemName=golang.go)
* [kubectl](https://kubernetes.io/docs/tasks/tools/)
* [Docker](https://www.docker.com/) or [Podman](https://podman.io/) or another container engine
* [Download the appropriate libbitwarden_c binary](https://github.com/bitwarden/sdk) for your OS and architecture to [bw-sdk/internal/cinterface/lib](bw-sdk/internal/cinterface/lib). This can be done using `make setup`
* A [Bitwarden Organization with Secrets Manager](https://bitwarden.com/help/sign-up-for-secrets-manager/). You will need the organization ID GUID for your organization.
* An [access token](https://bitwarden.com/help/access-tokens/) for a Secrets Manager machine account tied to the projects you want to pull.
* A [Kind Cluster](https://kind.sigs.k8s.io/docs/user/quick-start/) or other local Kubernetes environment with Kubectl pointed to it as the current context for local development.
Expand Down
115 changes: 0 additions & 115 deletions bw-sdk/README.md

This file was deleted.

78 changes: 0 additions & 78 deletions bw-sdk/bitwarden_client.go

This file was deleted.

37 changes: 0 additions & 37 deletions bw-sdk/command_runner.go

This file was deleted.

5 changes: 0 additions & 5 deletions bw-sdk/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions bw-sdk/go.sum

This file was deleted.

Loading

0 comments on commit a307886

Please sign in to comment.