Skip to content

Commit

Permalink
feat: devcontainers
Browse files Browse the repository at this point in the history
  • Loading branch information
tangowithfoxtrot committed Mar 21, 2024
1 parent 4cd365b commit 05d9942
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
39 changes: 39 additions & 0 deletions src/sm-operator/.devcontainer/common/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "BW k8s Operator",
"image": "mcr.microsoft.com/devcontainers/go:1.21",
"runArgs": ["--network=host"], // needed for kind
"postCreateCommand": "sudo .devcontainer/common/postCreateCommand.sh",
"customizations": {
"vscode": {
"extensions": [
"golang.go",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-docker"
],
"settings": {}
}
},
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"runArgs": [
"--privileged"
]
},
"ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {
"fisher": true
},
"ghcr.io/devcontainers-contrib/features/kind:1": {},
},
"secrets": {
},
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
],
"remoteEnv": {
"BWS_ACCESS_TOKEN": "${localEnv:BWS_ACCESS_TOKEN}",
"BW_API_URL": "${localEnv:BW_API_URL}",
"BW_IDENTITY_API_URL": "${localEnv:BW_IDENTITY_API_URL}",
"BW_SECRETS_MANAGER_REFRESH_INTERVAL": "${localEnv:BW_SECRETS_MANAGER_REFRESH_INTERVAL}",
},
"remoteUser": "root" // needed for kind: https://github.com/kubernetes-sigs/kind/issues/3196#issuecomment-1537260166
}
10 changes: 10 additions & 0 deletions src/sm-operator/.devcontainer/common/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
# WARNING: It is _strongly_ recommended that you keep this the default
# (127.0.0.1) for security reasons. However it is possible to change this.
apiServerAddress: "127.0.0.1"
# By default the API server listens on a random open port.
# You may choose a specific port but probably don't need to in most cases.
# Using a random port makes it easier to spin up multiple clusters.
apiServerPort: 8573
21 changes: 21 additions & 0 deletions src/sm-operator/.devcontainer/common/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
apt-get update
apt-get install -y kubernetes-client musl-tools # kubectl
kind create cluster --config .devcontainer/common/kind-config.yaml
# kind export kubeconfig

PATH="$PATH:/usr/local/go/bin" make setup
PATH="$PATH:/usr/local/go/bin" make install

# shellcheck disable=SC2016
echo '
devcontainer setup complete!
Be sure to set the following environment variables:
export BWS_ACCESS_TOKEN=
export BW_API_URL=
export BW_IDENTITY_API_URL=
And run the following before attempting to set the Bitwarden access token secret:
kubectl create secret generic bw-auth-token -n some-namespace --from-literal=token="$BWS_ACCESS_TOKEN"
'
2 changes: 2 additions & 0 deletions src/sm-operator/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"program": "${workspaceFolder}/cmd/main.go",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"envFile": "${workspaceFolder}/.env",
"env": {
"LD_LIBRARY_PATH": "bw-sdk/internal/cinterface/lib"
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions src/sm-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ ifeq ($(ARCH),arm64)
endif
setup: ## 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 temp.zip -d bw-sdk/internal/cinterface/lib && rm temp.zip
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

##@ Development

Expand Down Expand Up @@ -140,11 +140,11 @@ test: manifests generate fmt vet envtest ## Run tests.

.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 LD_LIBRARY_PATH=bw-sdk/internal/cinterface/lib go build -ldflags '-linkmode external -extldflags "-static"' -o bin/manager cmd/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go
LD_LIBRARY_PATH=bw-sdk/internal/cinterface/lib go run ./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

0 comments on commit 05d9942

Please sign in to comment.