Skip to content

Commit 3874aad

Browse files
authored
Add additional binaries and docker targets (#206)
1 parent 14bc569 commit 3874aad

File tree

8 files changed

+143
-71
lines changed

8 files changed

+143
-71
lines changed

.github/workflows/main.yml

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,73 @@ on:
77
types: [created]
88

99
jobs:
10+
11+
determine-version:
12+
name: Determine version
13+
runs-on: ubuntu-latest
14+
steps:
15+
- id: determine_version
16+
run: |
17+
if [ ${{ github.event_name }} == "release" ]; then
18+
echo "version=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
19+
else
20+
echo "version=${{ github.sha }}" >> "$GITHUB_OUTPUT"
21+
fi
22+
cat "$GITHUB_OUTPUT"
23+
outputs:
24+
version: ${{ steps.determine_version.outputs.version }}
25+
1026
build:
1127
name: Build
1228
runs-on: ubuntu-latest
29+
needs: [ determine-version ]
1330
steps:
14-
- uses: actions/setup-go@v4
31+
- uses: actions/setup-go@v5
1532
with:
1633
go-version: '1.24'
34+
- uses: docker/setup-qemu-action@v3
35+
- uses: docker/setup-buildx-action@v3
36+
1737
- uses: actions/checkout@v4
18-
- name: Lint, test and build
19-
run: |
2038

21-
# Get staticcheck
22-
export PATH=$PATH:$(go env GOPATH)/bin
39+
- name: Lint
40+
run: make lint
2341

24-
# Lint and test
25-
make lint
26-
make format
42+
- name: Format
43+
run: make format && git diff --exit-code
2744

28-
# Exit if after formatting there are any code differences
29-
git diff --exit-code
45+
- name: Test
46+
run: make test
3047

31-
make test
48+
- name: Build
49+
run: make package_all VERSION=${{ needs.determine-version.outputs.version }}
3250

33-
# Build
34-
if [ ${{ github.event_name }} == "release" ]; then
35-
# github.ref is in the form refs/tags/VERSION, so apply regex to just get version
36-
VERSION=$(echo "${{ github.ref }}" | grep -P '([^\/]+$)' -o)
37-
else
38-
VERSION=$(git rev-parse --short ${{ github.sha }})
39-
fi
40-
make docker VERSION=${VERSION}
41-
- name: Deploy
42-
env:
43-
DOCKER_USER: ${{ secrets.DOCKER_USER }}
44-
DOCKER_PASS: ${{ secrets.DOCKER_PASS }}
51+
- name: Docker Hub authentication
4552
if: github.event_name != 'pull_request' && github.repository == 'jthomperoo/custom-pod-autoscaler'
46-
run: |
47-
48-
# Array of images to publish
49-
declare -a IMAGES=(python python-3-12 python-3-13 alpine)
50-
echo "$DOCKER_PASS" | docker login --username=$DOCKER_USER --password-stdin
51-
52-
if [ ${{ github.event_name }} == "release" ]; then
53+
uses: docker/login-action@v3
54+
with:
55+
username: ${{ secrets.DOCKER_USER }}
56+
password: ${{ secrets.DOCKER_PASS }}
5357

54-
# This needs to be determined again, due to env vars not being shared between steps
55-
# https://github.com/actions/starter-workflows/issues/68
56-
VERSION=$(echo "${{ github.ref }}" | grep -P '([^\/]+$)' -o)
58+
- name: Build Docker images
59+
if: github.event_name != 'pull_request' && github.repository == 'jthomperoo/custom-pod-autoscaler'
60+
run: make docker_multi_platform VERSION=${{ needs.determine-version.outputs.version }}
5761

58-
# Go through each image type and publish each one individually
59-
for image in "${IMAGES[@]}"; do
60-
docker tag custompodautoscaler/${image}:${VERSION} custompodautoscaler/${image}:latest
61-
docker push custompodautoscaler/${image}:${VERSION}
62-
docker push custompodautoscaler/${image}:latest
63-
done
62+
- name: Tag latest Docker images
63+
if: github.event_name == 'release'
64+
run: make docker_tag_latest
6465

65-
# Package binary
66-
tar -czvf custom-pod-autoscaler.tar.gz dist/*
67-
else
68-
for image in "${IMAGES[@]}"; do
69-
docker push custompodautoscaler/${image}:$(git rev-parse --short ${{ github.sha }})
70-
done
71-
fi
72-
- name: Deploy binary
73-
if: github.event_name == 'release' && github.repository == 'jthomperoo/custom-pod-autoscaler'
74-
uses: Shopify/[email protected]
66+
- name: Publish binaries
67+
if: github.event_name == 'release'
68+
uses: softprops/action-gh-release@v2
7569
with:
76-
name: custom-pod-autoscaler.tar.gz
77-
path: custom-pod-autoscaler.tar.gz
78-
repo-token: ${{ secrets.GITHUB_TOKEN }}
70+
files: |
71+
custom-pod-autoscaler.tar.gz
72+
custom-pod-autoscaler-linux-386.tar.gz
73+
custom-pod-autoscaler-linux-amd64.tar.gz
74+
custom-pod-autoscaler-linux-arm.tar.gz
75+
custom-pod-autoscaler-linux-arm64.tar.gz
76+
custom-pod-autoscaler-darwin-amd64.tar.gz
77+
custom-pod-autoscaler-darwin-arm64.tar.gz
78+
custom-pod-autoscaler-windows-386.tar.gz
79+
custom-pod-autoscaler-windows-amd64.tar.gz

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor/
22
dist/
3-
*.out
3+
*.out
4+
*.tar.gz

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- New binary build targets:
10+
- Linux i386 (x86)
11+
- Linux ARM
12+
- Linux ARM64
13+
- Darwin AMD64
14+
- Darwin ARM64
15+
- Windows i386 (x86)
16+
- Windows AMD64
17+
- New Docker platform:
18+
- Linux ARM64
819

920
## [v2.12.1] - 2025-02-14
1021
### Fixed

CONTRIBUTING.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,11 @@ the autoscaler's image is available in the registry it can be deployed using `ku
164164

165165
### Commands
166166

167-
* `make` - builds the CPA binary.
168-
* `make docker` - builds the CPA base images.
167+
* `make` - builds the CPA Linux Docker image for your local architecture (either AMD64 or ARM64).
168+
* `make package_linux_arm64` - builds the CPA binary for the Linux ARM64 target (see the Makefile for a full list of
169+
targets) and packages it into a tar.gz file.
170+
* `make package_all` - builds the CPA binary for all available targets and packages them.
171+
* `make docker_multi_platform` - performs a multi-platform docker build of the CPA base images.
169172
* `make test` - runs the unit tests.
170173
* `make lint` - lints the code.
171174
* `make beautify` - beautifies the code, must be run to pass the CI.

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414

1515
# Python 3.13 build
1616
FROM python:3.13-slim AS python-3-13
17+
ARG TARGETARCH
1718
WORKDIR /app
18-
COPY dist /app/
19+
COPY dist/linux_${TARGETARCH} /app/
1920
CMD [ "/app/custom-pod-autoscaler" ]
2021

2122
# Python 3.12 build
2223
FROM python:3.12-slim AS python-3-12
24+
ARG TARGETARCH
2325
WORKDIR /app
24-
COPY dist /app/
26+
COPY dist/linux_${TARGETARCH} /app/
2527
CMD [ "/app/custom-pod-autoscaler" ]
2628

2729
# Alpine build
2830
FROM alpine:3 AS alpine
31+
ARG TARGETARCH
2932
WORKDIR /app
30-
COPY dist /app/
33+
COPY dist/linux_${TARGETARCH} /app/
3134
CMD [ "/app/custom-pod-autoscaler" ]

Makefile

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ REGISTRY = custompodautoscaler
22
NAME = custom-pod-autoscaler
33
VERSION = latest
44

5-
default:
6-
@echo "=============Building============="
7-
CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'main.Version=$(VERSION)'" -o dist/$(NAME) main.go
8-
cp LICENSE dist/LICENSE
5+
default: package_linux_amd64 package_linux_arm64
6+
docker build --target=python-3-13 --tag $(REGISTRY)/python-3-13:$(VERSION) --tag $(REGISTRY)/python:$(VERSION) .
7+
docker build --target=python-3-12 --tag $(REGISTRY)/python-3-12:$(VERSION) .
8+
docker build --target=alpine --tag $(REGISTRY)/alpine:$(VERSION) .
99

1010
test:
1111
@echo "=============Running tests============="
@@ -20,18 +20,64 @@ format:
2020
gofmt -s -w .
2121
go mod tidy
2222

23-
docker: default
24-
@echo "=============Building docker images============="
25-
docker ps
26-
docker build --target=python-3-12 -t $(REGISTRY)/python-3-12:$(VERSION) .
27-
docker build --target=python-3-13 -t $(REGISTRY)/python-3-13:$(VERSION) .
28-
docker build --target=alpine -t $(REGISTRY)/alpine:$(VERSION) .
29-
docker tag $(REGISTRY)/python-3-13:$(VERSION) $(REGISTRY)/python:$(VERSION)
30-
3123
doc:
3224
@echo "=============Serving docs============="
3325
mkdocs serve
3426

3527
coverage:
3628
@echo "=============Loading coverage HTML============="
3729
go tool cover -html=coverage.out
30+
31+
package_all: package_linux_386 package_linux_amd64 package_linux_arm package_linux_arm64 package_darwin_amd64 package_darwin_arm64 package_windows_386 package_windows_amd64
32+
cp custom-pod-autoscaler-linux-amd64.tar.gz custom-pod-autoscaler.tar.gz
33+
34+
package_linux_386:
35+
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags="-X 'main.Version=$(VERSION)'" -o dist/linux_386/custom-pod-autoscaler main.go
36+
cp LICENSE dist/linux_386/LICENSE
37+
tar -czvf custom-pod-autoscaler-linux-386.tar.gz dist/linux_386/*
38+
39+
package_linux_amd64:
40+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X 'main.Version=$(VERSION)'" -o dist/linux_amd64/custom-pod-autoscaler main.go
41+
cp LICENSE dist/linux_amd64/LICENSE
42+
tar -czvf custom-pod-autoscaler-linux-amd64.tar.gz dist/linux_amd64/*
43+
44+
package_linux_arm:
45+
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-X 'main.Version=$(VERSION)'" -o dist/linux_arm/custom-pod-autoscaler main.go
46+
cp LICENSE dist/linux_arm/LICENSE
47+
tar -czvf custom-pod-autoscaler-linux-arm.tar.gz dist/linux_arm/*
48+
49+
package_linux_arm64:
50+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-X 'main.Version=$(VERSION)'" -o dist/linux_arm64/custom-pod-autoscaler main.go
51+
cp LICENSE dist/linux_arm64/LICENSE
52+
tar -czvf custom-pod-autoscaler-linux-arm64.tar.gz dist/linux_arm64/*
53+
54+
package_darwin_amd64:
55+
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-X 'main.Version=$(VERSION)'" -o dist/darwin_amd64/custom-pod-autoscaler main.go
56+
cp LICENSE dist/darwin_amd64/LICENSE
57+
tar -czvf custom-pod-autoscaler-darwin-amd64.tar.gz dist/darwin_amd64/*
58+
59+
package_darwin_arm64:
60+
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-X 'main.Version=$(VERSION)'" -o dist/darwin_arm64/custom-pod-autoscaler main.go
61+
cp LICENSE dist/darwin_arm64/LICENSE
62+
tar -czvf custom-pod-autoscaler-darwin-arm64.tar.gz dist/darwin_arm64/*
63+
64+
package_windows_386:
65+
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="-X 'main.Version=$(VERSION)'" -o dist/windows_386/custom-pod-autoscaler.exe main.go
66+
cp LICENSE dist/windows_386/LICENSE
67+
tar -czvf custom-pod-autoscaler-windows-386.tar.gz dist/windows_386/*
68+
69+
package_windows_amd64:
70+
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-X 'main.Version=$(VERSION)'" -o dist/windows_amd64/custom-pod-autoscaler.exe main.go
71+
cp LICENSE dist/windows_amd64/LICENSE
72+
tar -czvf custom-pod-autoscaler-windows-amd64.tar.gz dist/windows_amd64/*
73+
74+
docker_multi_platform: package_linux_amd64 package_linux_arm64
75+
docker buildx build --push --platform=linux/amd64,linux/arm64 --target=python-3-13 --tag $(REGISTRY)/python-3-13:$(VERSION) --tag $(REGISTRY)/python:$(VERSION) .
76+
docker buildx build --push --platform=linux/amd64,linux/arm64 --target=python-3-12 --tag $(REGISTRY)/python-3-12:$(VERSION) .
77+
docker buildx build --push --platform=linux/amd64,linux/arm64 --target=alpine --tag $(REGISTRY)/alpine:$(VERSION) .
78+
79+
docker_tag_latest:
80+
docker buildx imagetools create --tag $(REGISTRY)/python:$(VERSION) $(REGISTRY)/python:latest
81+
docker buildx imagetools create --tag $(REGISTRY)/python-3-13:$(VERSION) $(REGISTRY)/python-3-13:latest
82+
docker buildx imagetools create --tag $(REGISTRY)/python-3-13:$(VERSION) $(REGISTRY)/python-3-12:latest
83+
docker buildx imagetools create --tag $(REGISTRY)/alpine:$(VERSION) $(REGISTRY)/alpine:latest

docs/reference/docker-images.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ The Custom Pod Autoscaler is bundled with the following Docker base images:
77
- `custompodautoscaler/python-3-12` tracks latest stable Python 3.12.x release (debian based).
88
- `custompodautoscaler/alpine` tracks latest stable Alpine 3.x release.
99

10+
## Platforms
11+
12+
These Docker platforms are currently supported:
13+
14+
- Linux AMD64
15+
- Linux ARM64
16+
1017
## Deprecated images
1118

1219
The following images are deprecated and will no longer recieve updates:

example/custom-docker-image/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ WORKDIR /app
2020
# Install wget
2121
RUN apt-get update && apt-get install wget -y
2222

23-
# Install CPA
23+
# Install CPA (using AMD64 binary)
2424
RUN wget \
2525
-qO- \
2626
https://github.com/jthomperoo/custom-pod-autoscaler/releases/download/v2.12.1/custom-pod-autoscaler.tar.gz \

0 commit comments

Comments
 (0)