Skip to content

Commit

Permalink
build: build and publish using ko
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh committed Aug 8, 2024
1 parent e55d0b7 commit c8b6a94
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 53 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/build-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build and Publish

on:
push:

permissions:
packages: write
contents: write

jobs:
build-and-push-docker-image:
name: Build Docker image and push
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 'stable'

- uses: go-semantic-release/action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup ko
uses: ko-build/[email protected]

- name: Login to Github Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build containers
run: |
git fetch --tags
descr=$(git describe --tags)
short=$(git describe --tags --abbrev=0)
export version="${descr#v}"
if [[ $descr == $short ]]; then
minor="${v#*.}"
major="${v%%.*}"
ko build --bare --sbom=none -t edge -t latest -t "$version" -t "$minor" -t "$major" ./cmd/syncthing-configd
else
ko build --bare --sbom=none -t edge ./cmd/syncthing-configd
fi
env:
KO_DOCKER_REPO: ghcr.io/kastelo/syncthing-configd
42 changes: 0 additions & 42 deletions .github/workflows/build.yml

This file was deleted.

11 changes: 11 additions & 0 deletions .ko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
builds:
- id: syncthing-configd
dir: .
main: ./cmd/syncthing-configd
ldflags:
- -s -w
- -extldflags "-static"
- -X kastelo.dev/syncthing-configd/internal/build.GitVersion={{.Env.version}}
defaultPlatforms:
- linux/arm64
- linux/amd64
11 changes: 0 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ install: test
test:
@go test ./...

.PHONY: build
build: test build-linux-amd64 build-linux-arm64

build-linux-amd64:
@mkdir -p bin
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -v -ldflags $(ldflags) -o bin/syncthing-configd-linux-amd64 ./cmd/syncthing-configd

build-linux-arm64:
@mkdir -p bin
@GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -v -ldflags $(ldflags) -o bin/syncthing-configd-linux-arm64 ./cmd/syncthing-configd

.PHONY: proto
proto:
@clang-format -i proto/*.proto
Expand Down

0 comments on commit c8b6a94

Please sign in to comment.