Skip to content

Commit

Permalink
Add build-image Makefile target and build version support
Browse files Browse the repository at this point in the history
* Use the commit for BUILD_VERSION since we do not tag the repo
* Use the commit date rather than build date to provide a bit of ordering
  to the builds

Signed-off-by: Dean Troyer <[email protected]>
  • Loading branch information
dtroyer-salad committed Nov 3, 2023
1 parent 17fdf58 commit 2c6198f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
44 changes: 40 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
# virtual-kubelet-saladcloud

# Standard Development Targets
# build - build the project, binaries go into ./bin
# build-image - build a Docker image with the virtual-kubelet binary
# clean - clean up built binaries and cached Go artifacts
# lint - run golangci-lint (set args in LINT_ARGS)
# tidy - "go mod tidy"

IMAGE_TAG ?= latest
CMDS := bin/virtual-kubelet


# The conventional BUILD_VERSION is not very useful at the moment since we are not tagging the repo
# Use the sha for the build as a version for now.
# BUILD_VERSION ?= $(shell git describe --tags --always --dirty="-dev")
BUILD_VERSION ?= $(shell git rev-parse --short HEAD)

# It seems more useful to have the commit date than the build date for ordering versions
# since commit shas have no order
# BUILD_DATE ?= $(shell date -u '+%Y-%m-%d-%H:%M UTC')
BUILD_DATE ?= $(shell git log -1 --format=%cd --date=format:"%Y%m%d")

VERSION_FLAGS := -ldflags='-X "main.buildVersion=$(BUILD_VERSION)" -X "main.buildTime=$(BUILD_DATE)"'

.PHONY: build
build: CGO_ENABLED=0
build:
go build -o ./bin/virtual-kubelet ./cmd/virtual-kubelet/main.go
build: $(CMDS)

.PHONY: build-image
build-image:
docker build \
--tag ghcr.io/saladtechnologies/virtual-kubelet-saladcloud:$(IMAGE_TAG) \
--file docker/Dockerfile \
--build-arg VERSION_FLAGS=$(VERSION_FLAGS) \
.

.PHONY: clean
clean:
rm -rf ./bin
rm $(CMDS)
go clean

.PHONY: lint
Expand All @@ -16,6 +45,13 @@ lint:

.PHONY: test
test:
go test -v ./...

tidy:
go mod tidy

bin/virtual-kubelet:

bin/%: CGO_ENABLED=0
bin/%:
go build -ldflags '-extldflags "-static"' -o bin/$(*) $(VERSION_FLAGS) ./cmd/$(*)
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a href="https://github.com/SaladTechnologies/virtual-kubelet-saladcloud"><img alt="SaladCloud Virtual Kubelet Provider" src="./images/saladcloud-virtual-kubelet-banner.png" width="100%" /></a>
</center>

Salad's Virtual Kubelet (VK) provider for SaladCloud enables running Kubernetes (K8s) pods as container group deployments.
Salad's Virtual Kubelet (VK) provider for SaladCloud enables running Kubernetes (K8s) pods as SaladCloud Container Group deployments.

## How it Works

Expand Down Expand Up @@ -46,11 +46,27 @@ Follow the steps below to get started with local development.
3. Build the project.

```sh
go build -o ./bin/virtual-kubelet ./cmd/virtual-kubelet/main.go
make build
```

4. Run the project.
4. Run the project in foreground.

```sh
./bin/virtual-kubelet --sce-api-key {apiKey} --sce-project-name {projectName} --sce-organization-name {organizationName}
```

or

4. Run the project in K8s via Helm.

```sh
helm install \
--create-namespace \
--namespace saladcloud \
--set salad.apiKey=${apiKey} \
--set salad.organizationName=${organizationName} \
--set salad.projectName=${projectName} \
--set provider.image.tag=${imageTag} \
saladcloud-node \
./charts/virtual-kubelet
```
3 changes: 2 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

FROM golang:1.21.3-alpine3.18 AS build
WORKDIR /app
ARG VERSION_FLAGS=-ldflags=

COPY go.mod go.sum ./
RUN go mod download && \
go mod verify

COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /app/bin/virtual-kubelet ./cmd/virtual-kubelet/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build "${VERSION_FLAGS}" -o /app/bin/virtual-kubelet ./cmd/virtual-kubelet/main.go

FROM scratch AS final

Expand Down

0 comments on commit 2c6198f

Please sign in to comment.