Skip to content

Commit eba8bf9

Browse files
authored
Merge pull request #48 from aifoundry-org/docker-images
docker build support
2 parents 75d5f3b + 9f2428c commit eba8bf9

File tree

4 files changed

+121
-4
lines changed

4 files changed

+121
-4
lines changed

.github/workflows/ci.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,23 @@ jobs:
4848
go-version-file: 'go.mod'
4949
- name: Build
5050
run: |
51-
make build
51+
make build ARCH=${{ matrix.arch }} OS=${{ matrix.os }}
52+
image:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
with:
58+
submodules: recursive
59+
- name: Set up QEMU
60+
uses: docker/setup-qemu-action@v3
61+
- name: Set up Docker Buildx
62+
uses: docker/setup-buildx-action@v3
63+
- name: Build Docker image
64+
uses: docker/build-push-action@v6
65+
with:
66+
platforms: linux/amd64,linux/arm64,linux/riscv64
67+
context: .
68+
file: Dockerfile
69+
push: false
70+
tags: build

.github/workflows/publish.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Publish Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
build-and-push:
10+
name: Build and Push Docker Image
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
env:
18+
IMAGE_NAME: ${{ secrets.IMAGE_NAME || 'aifoundryorg/oxide-controller' }}
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
submodules: recursive
25+
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
31+
- name: Extract metadata for Docker
32+
id: meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: docker.io/${{ env.IMAGE_NAME }}
36+
tags: |
37+
type=semver,pattern={{version}}
38+
type=semver,pattern={{major}}.{{minor}}
39+
type=sha
40+
41+
- name: Log in to container registry
42+
uses: docker/login-action@v3
43+
with:
44+
registry: docker.io
45+
username: ${{ secrets.DH_REGISTRY_USERNAME }}
46+
password: ${{ secrets.DH_REGISTRY_TOKEN }}
47+
48+
- name: Build and push Docker image
49+
uses: docker/build-push-action@v6
50+
with:
51+
platforms: linux/amd64,linux/arm64,linux/riscv64
52+
context: .
53+
file: Dockerfile
54+
push: true
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}
57+
cache-from: type=gha
58+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM --platform=$BUILDPLATFORM golang:1.24.3-alpine3.21 AS build
2+
3+
ARG TARGETPLATFORM
4+
ARG BUILDPLATFORM
5+
ARG TARGETARCH
6+
ARG TARGETOS
7+
8+
RUN apk update && \
9+
apk add --no-cache make git
10+
11+
WORKDIR /app
12+
COPY go.mod go.sum ./
13+
RUN go mod download
14+
COPY . .
15+
RUN make install TARGET=/oxide-controller OS=$(TARGETOS) ARCH=$(TARGETARCH)
16+
17+
FROM scratch
18+
COPY --from=build /oxide-controller /oxide-controller
19+
20+
ENTRYPOINT ["/oxide-controller"]

Makefile

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,26 @@
33
all: build link
44

55
BINDIR ?= bin
6-
ARCH ?= $(shell go env GOARCH)
7-
OS ?= $(shell go env GOOS)
8-
CONTROLLER_GENERIC ?= $(BINDIR)/oxide-controller
6+
7+
# determine my architecture and OS
8+
MYARCH = $(shell go env GOARCH)
9+
MYOS = $(shell go env GOOS)
10+
11+
# default to the current architecture and OS
12+
ARCH ?= $(MYARCH)
13+
OS ?= $(MYOS)
14+
CONTROLLER_NAME ?= oxide-controller
15+
CONTROLLER_GENERIC ?= $(BINDIR)/$(CONTROLLER_NAME)
916
CONTROLLER ?= $(CONTROLLER_GENERIC)-$(OS)-$(ARCH)
17+
TARGET ?= /usr/local/bin/$(CONTROLLER_NAME)
18+
19+
IMAGE_NAME ?= aifoundryorg/oxide-controller
1020

1121
build: $(CONTROLLER)
1222

23+
install: build
24+
@cp $(CONTROLLER) $(TARGET)
25+
1326
$(BINDIR):
1427
@mkdir -p $@
1528

@@ -19,7 +32,14 @@ $(CONTROLLER): $(BINDIR)
1932
link: $(CONTROLLER) $(CONTROLLER_GENERIC)
2033

2134
$(CONTROLLER_GENERIC): $(CONTROLLER)
35+
ifeq ($(ARCH),$(MYARCH))
36+
ifeq ($(OS),$(MYOS))
2237
@ln -sf $(notdir $(CONTROLLER)) $@
38+
endif
39+
endif
2340

2441
test:
2542
go test -v ./...
43+
44+
image:
45+
docker build -t oxide-controller:latest .

0 commit comments

Comments
 (0)