Skip to content

Commit 7bb7db5

Browse files
committed
initial structure and ci/cd
1 parent 6d78636 commit 7bb7db5

File tree

13 files changed

+317
-0
lines changed

13 files changed

+317
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Build & Release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
architectures:
7+
description: A JSON list of GOARCH values for which to build
8+
default: '["amd64", "arm64"]'
9+
required: false
10+
type: string
11+
push-container-image:
12+
description: Whether to push the resulting container image to the registry
13+
default: false
14+
required: false
15+
type: boolean
16+
create-release:
17+
description: Whether to create a Github release and attach the artifacts to it
18+
default: false
19+
required: false
20+
type: boolean
21+
22+
permissions:
23+
contents: write
24+
packages: write
25+
26+
jobs:
27+
build-go:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
arch: ${{ fromJson(inputs.architectures) }}
32+
steps:
33+
- name: Check out code
34+
uses: actions/checkout@v5
35+
36+
- name: Install Go
37+
uses: actions/setup-go@v5
38+
with:
39+
go-version-file: go.mod
40+
41+
- name: Run linter
42+
uses: golangci/golangci-lint-action@v8
43+
44+
- name: Run tests
45+
run: |-
46+
go test -v ./...
47+
48+
- name: Build
49+
run: |-
50+
mkdir -p $GITHUB_WORKSPACE/dist
51+
52+
CGO_ENABLED=0 \
53+
GOARCH=${{ matrix.arch }} \
54+
GOOS=linux \
55+
go build \
56+
-ldflags '\
57+
-s -w \
58+
-buildid=${{ github.sha }} \
59+
-X main.version=${{ github.ref_name }} \
60+
-X main.commit=${{ github.sha }} \
61+
' \
62+
-trimpath -mod=readonly \
63+
-o $GITHUB_WORKSPACE/dist/multigres-operator-${{ matrix.arch }} \
64+
./cmd/multigres-operator
65+
66+
- name: Upload artifacts
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: multigres-operator-${{matrix.arch}}
70+
path: dist/*
71+
72+
build-push-container:
73+
needs: [ build-go ]
74+
runs-on: ubuntu-latest
75+
steps:
76+
- name: Check out code
77+
uses: actions/checkout@v5
78+
79+
- name: Set up QEMU
80+
uses: docker/setup-qemu-action@v3
81+
82+
- name: Setup Docker buildx
83+
uses: docker/setup-buildx-action@v3
84+
85+
- name: Log into registry
86+
uses: docker/login-action@v3
87+
with:
88+
registry: ghcr.io
89+
username: ${{ github.actor }}
90+
password: ${{ secrets.GITHUB_TOKEN }}
91+
92+
- name: Extract container metadata
93+
id: meta
94+
uses: docker/metadata-action@v5
95+
with:
96+
github-token: ${{ secrets.GITHUB_TOKEN }}
97+
images: ghcr.io/${{ github.repository }}
98+
tags: |
99+
type=ref,event=branch,prefix=
100+
type=ref,event=tag,prefix=
101+
type=sha,format=short,prefix=
102+
type=sha,format=long,prefix=
103+
104+
- uses: actions/download-artifact@v5
105+
with:
106+
pattern: multigres-operator-*
107+
path: dist/
108+
109+
- name: Build and push container image
110+
id: build-and-push
111+
uses: docker/build-push-action@v5
112+
with:
113+
context: .
114+
file: Containerfile
115+
platforms: linux/${{ join(fromJson(inputs.architectures), ',linux/') }}
116+
push: ${{ inputs.push-container-image }}
117+
tags: ${{ steps.meta.outputs.tags }}
118+
labels: ${{ steps.meta.outputs.labels }}
119+
provenance: false
120+
cache-from: type=gha
121+
cache-to: type=gha,mode=max
122+
123+
create-release:
124+
needs: [ build-go ]
125+
runs-on: ubuntu-latest
126+
if: ${{ inputs.create-release }}
127+
steps:
128+
- uses: actions/download-artifact@v5
129+
with:
130+
pattern: "*"
131+
path: dist/
132+
133+
- name: Release
134+
uses: softprops/action-gh-release@v2
135+
with:
136+
files: dist/**

.github/workflows/main.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Build main
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
run:
14+
uses: ./.github/workflows/build-and-release.yaml
15+
with:
16+
push-container-image: true
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Run checks
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: write
8+
packages: write
9+
10+
jobs:
11+
run:
12+
uses: ./.github/workflows/build-and-release.yaml

.github/workflows/tags.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Release tag
2+
3+
on:
4+
push:
5+
tags:
6+
- '**'
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
run:
14+
uses: ./.github/workflows/build-and-release.yaml
15+
with:
16+
push-container-image: true
17+
create-release: true

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# direnv
2+
.direnv/
3+
4+
# nix
5+
result
6+
result-*
7+
8+
# generic
9+
dist/

.golangci.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version = "2"
2+
[formatters]
3+
enable = [ "gofumpt", "golines" ]

Containerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM --platform=$BUILDPLATFORM alpine:3.22.1 AS build
2+
ARG TARGETOS
3+
ARG TARGETARCH
4+
5+
COPY dist dist
6+
RUN cp dist/multigres-operator-${TARGETARCH}/multigres-operator-${TARGETARCH} multigres-operator
7+
RUN chmod +x multigres-operator
8+
9+
FROM alpine:3.22.1
10+
11+
COPY --from=build multigres-operator multigres-operator
12+
13+
ENTRYPOINT [ "./multigres-operator" ]

cmd/multigres-operator/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func main() {
8+
fmt.Println("TODO")
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestNothing(t *testing.T) {
8+
// TODO: write real tests
9+
}

devshell.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{ pkgs }:
2+
pkgs.mkShell {
3+
# Add build dependencies
4+
packages = with pkgs; [ go ];
5+
6+
# Add environment variables
7+
env = { };
8+
9+
# Load custom bash code
10+
shellHook = ''
11+
12+
'';
13+
}

0 commit comments

Comments
 (0)