Skip to content

Commit 60655f3

Browse files
authored
feat: use makefile for ci/cd (#141)
Updated the CI/CD workflow to use the `Makefile` for its commands.
1 parent 4ef89eb commit 60655f3

File tree

3 files changed

+63
-27
lines changed

3 files changed

+63
-27
lines changed

.github/workflows/build-test.yaml

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,15 @@ on:
66
name: Build & Test
77

88
jobs:
9-
10-
build:
11-
name: Build
12-
runs-on: ubuntu-latest
13-
steps:
14-
- name: Checkout Code
15-
uses: actions/checkout@v5
16-
17-
- name: Install Go
18-
uses: actions/setup-go@v6
19-
with:
20-
go-version-file: "go.mod"
21-
22-
- name: Run Build
23-
run: go build .
24-
25-
test:
26-
name: Test
9+
build-test:
10+
name: Build & Test
2711
runs-on: ubuntu-latest
2812
steps:
2913
- name: Checkout Code
3014
uses: actions/checkout@v5
3115

32-
- name: Install Go
33-
uses: actions/setup-go@v6
34-
with:
35-
go-version-file: "go.mod"
16+
- name: Build Container Image
17+
run: make image-build
3618

3719
- name: Run Tests
38-
run: go test -v ./...
20+
run: make test

Containerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
ARG GO_VERSION=1.25.3
2-
FROM docker.io/golang:${GO_VERSION} AS builder
1+
ARG GO_CONTAINER_IMAGE
2+
3+
# Stage 1: Build the binary.
4+
FROM ${GO_CONTAINER_IMAGE} AS builder
5+
6+
ARG VERSION
37

48
WORKDIR /app
5-
COPY . .
9+
COPY go.mod go.sum ./
10+
RUN go mod download
611

7-
RUN CGO_ENABLED=0 go build .
12+
COPY . .
13+
RUN CGO_ENABLED=0 go build \
14+
-ldflags "-s -w -X k8s.io/component-base/version.gitVersion=${VERSION}" \
15+
.
816

17+
# Stage 2: Minimal container image.
918
FROM gcr.io/distroless/static-debian12:nonroot
1019

1120
COPY --from=builder /app/oxide-cloud-controller-manager /usr/bin/oxide-cloud-controller-manager

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
VERSION ?= 0.1.0-$(GIT_COMMIT_SHORT)
2+
GO_CONTAINER_IMAGE ?= docker.io/golang:1.25.3
3+
4+
CONTAINER_RUNTIME ?= $(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null)
5+
ifeq ($(CONTAINER_RUNTIME),)
6+
$(error No container runtime found. Please install podman or docker)
7+
endif
8+
9+
GIT_COMMIT_SHORT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
10+
11+
# Container image configuration.
12+
IMAGE_REGISTRY ?= ghcr.io/oxidecomputer
13+
IMAGE_NAME ?= oxide-cloud-controller-manager
14+
IMAGE_TAG ?= $(VERSION)
15+
IMAGE_FULL ?= $(if $(IMAGE_REGISTRY),$(IMAGE_REGISTRY)/)$(IMAGE_NAME):$(IMAGE_TAG)
16+
17+
.PHONY: test
18+
test:
19+
@echo "Running tests in container..."
20+
$(CONTAINER_RUNTIME) build \
21+
--build-arg GO_CONTAINER_IMAGE=$(GO_CONTAINER_IMAGE) \
22+
--build-arg VERSION=$(VERSION) \
23+
--target builder \
24+
-t $(IMAGE_NAME)-builder:$(IMAGE_TAG) \
25+
.
26+
$(CONTAINER_RUNTIME) run --rm $(IMAGE_NAME)-builder:$(IMAGE_TAG) go test -v ./...
27+
28+
.PHONY: image-build
29+
image-build:
30+
@echo "Building container image: $(IMAGE_FULL)"
31+
$(CONTAINER_RUNTIME) build \
32+
--build-arg GO_CONTAINER_IMAGE=$(GO_CONTAINER_IMAGE) \
33+
--build-arg VERSION=$(VERSION) \
34+
-t $(IMAGE_FULL) \
35+
.
36+
37+
.PHONY: image-push
38+
image-push:
39+
@if [ -z "$(IMAGE_REGISTRY)" ]; then \
40+
echo "Error: IMAGE_REGISTRY must be set to push images"; \
41+
echo "Example: make image-push IMAGE_REGISTRY=ghcr.io/oxidecomputer"; \
42+
exit 1; \
43+
fi
44+
@echo "Pushing container image: $(IMAGE_FULL)"
45+
$(CONTAINER_RUNTIME) push $(IMAGE_FULL)

0 commit comments

Comments
 (0)