Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build-image Makefile target and build version support #34

Merged
merged 1 commit into from
Nov 3, 2023
Merged
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
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