Skip to content

Commit 6f527b7

Browse files
Merge pull request #1 from nRFCloud/initial-project-structure
Initial Project
2 parents 777ecf6 + 9e5efcf commit 6f527b7

31 files changed

Lines changed: 4537 additions & 14 deletions

.github/workflows/ci.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: '1.21'
20+
21+
- name: Cache Go modules
22+
uses: actions/cache@v3
23+
with:
24+
path: ~/go/pkg/mod
25+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
26+
restore-keys: |
27+
${{ runner.os }}-go-
28+
29+
- name: Download dependencies
30+
run: go mod download
31+
32+
- name: Run fmt
33+
run: make fmt
34+
35+
- name: Run vet
36+
run: make vet
37+
38+
- name: Run tests
39+
run: make test
40+
41+
- name: Upload coverage reports
42+
uses: codecov/codecov-action@v3
43+
with:
44+
file: ./cover.out
45+
flags: unittests
46+
name: codecov-umbrella
47+
48+
lint-helm:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
54+
- name: Set up Helm
55+
uses: azure/setup-helm@v3
56+
with:
57+
version: '3.12.0'
58+
59+
- name: Lint Helm chart
60+
run: make helm-lint
61+
62+
- name: Template Helm chart
63+
run: make helm-template
64+
65+
docker-build:
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Checkout
69+
uses: actions/checkout@v4
70+
71+
- name: Set up Docker Buildx
72+
uses: docker/setup-buildx-action@v3
73+
74+
- name: Build Docker image
75+
uses: docker/build-push-action@v5
76+
with:
77+
context: .
78+
platforms: linux/amd64,linux/arm64
79+
push: false
80+
tags: test-image:latest
81+
cache-from: type=gha
82+
cache-to: type=gha,mode=max

.github/workflows/release.yaml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
packages: write
18+
id-token: write
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Set up Go
27+
uses: actions/setup-go@v4
28+
with:
29+
go-version: '1.21'
30+
31+
- name: Set up Helm
32+
uses: azure/setup-helm@v3
33+
with:
34+
version: '3.12.0'
35+
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@v3
38+
39+
- name: Log in to Container Registry
40+
uses: docker/login-action@v3
41+
with:
42+
registry: ${{ env.REGISTRY }}
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Extract version from tag
47+
id: version
48+
run: |
49+
VERSION=${GITHUB_REF#refs/tags/v}
50+
echo "version=$VERSION" >> $GITHUB_OUTPUT
51+
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
52+
53+
- name: Update Chart.yaml with release version
54+
run: |
55+
sed -i "s/^version: .*/version: ${{ steps.version.outputs.version }}/" chart/Chart.yaml
56+
sed -i "s/^appVersion: .*/appVersion: \"${{ steps.version.outputs.version }}\"/" chart/Chart.yaml
57+
58+
- name: Run tests
59+
run: |
60+
go mod download
61+
make test
62+
63+
- name: Build and push Docker image
64+
uses: docker/build-push-action@v5
65+
with:
66+
context: .
67+
platforms: linux/amd64,linux/arm64
68+
push: true
69+
tags: |
70+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
71+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
72+
cache-from: type=gha
73+
cache-to: type=gha,mode=max
74+
75+
- name: Package Helm chart
76+
run: |
77+
helm package chart --version ${{ steps.version.outputs.version }} --app-version ${{ steps.version.outputs.version }}
78+
79+
- name: Create GitHub Release
80+
uses: softprops/action-gh-release@v1
81+
with:
82+
files: |
83+
flux-extension-controller-${{ steps.version.outputs.version }}.tgz
84+
generate_release_notes: true
85+
make_latest: true
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
89+
publish-helm-chart:
90+
runs-on: ubuntu-latest
91+
needs: release
92+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
93+
permissions:
94+
contents: read
95+
packages: write
96+
97+
steps:
98+
- name: Checkout
99+
uses: actions/checkout@v4
100+
101+
- name: Set up Helm
102+
uses: azure/setup-helm@v3
103+
with:
104+
version: '3.12.0'
105+
106+
- name: Extract version from tag
107+
id: version
108+
run: |
109+
VERSION=${GITHUB_REF#refs/tags/v}
110+
echo "version=$VERSION" >> $GITHUB_OUTPUT
111+
112+
- name: Update Chart.yaml with release version
113+
run: |
114+
sed -i "s/^version: .*/version: ${{ steps.version.outputs.version }}/" chart/Chart.yaml
115+
sed -i "s/^appVersion: .*/appVersion: \"${{ steps.version.outputs.version }}\"/" chart/Chart.yaml
116+
117+
- name: Log in to Container Registry
118+
uses: docker/login-action@v3
119+
with:
120+
registry: ${{ env.REGISTRY }}
121+
username: ${{ github.actor }}
122+
password: ${{ secrets.GITHUB_TOKEN }}
123+
124+
- name: Package and push Helm chart to OCI registry
125+
run: |
126+
helm package chart --version ${{ steps.version.outputs.version }} --app-version ${{ steps.version.outputs.version }}
127+
helm push flux-extension-controller-${{ steps.version.outputs.version }}.tgz oci://${{ env.REGISTRY }}/${{ github.repository }}/charts

.gitignore

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# If you prefer the allow list template instead of the deny list, see community template:
2-
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3-
#
41
# Binaries for programs and plugins
52
*.exe
63
*.exe~
@@ -11,22 +8,51 @@
118
# Test binary, built with `go test -c`
129
*.test
1310

14-
# Code coverage profiles and other test artifacts
11+
# Output of the go coverage tool, specifically when used with LiteIDE
1512
*.out
16-
coverage.*
17-
*.coverprofile
18-
profile.cov
1913

2014
# Dependency directories (remove the comment below to include it)
2115
# vendor/
2216

2317
# Go workspace file
2418
go.work
25-
go.work.sum
2619

27-
# env file
28-
.env
20+
# Build output
21+
bin/
22+
dist/
2923

30-
# Editor/IDE
31-
# .idea/
32-
# .vscode/
24+
# IDE files
25+
.vscode/
26+
.idea/
27+
*.swp
28+
*.swo
29+
*~
30+
31+
# OS generated files
32+
.DS_Store
33+
.DS_Store?
34+
._*
35+
.Spotlight-V100
36+
.Trashes
37+
ehthumbs.db
38+
Thumbs.db
39+
40+
# Helm packages
41+
*.tgz
42+
43+
# Temporary files
44+
tmp/
45+
temp/
46+
47+
# Config files with secrets
48+
config.yaml
49+
*.pem
50+
*.key
51+
!chart/templates/*.yaml
52+
53+
# Coverage files
54+
cover.out
55+
coverage.txt
56+
57+
# Docker build context
58+
.dockerignore

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Build the manager binary
2+
FROM golang:1.21-alpine AS builder
3+
4+
# Install ca-certificates and git
5+
RUN apk add --no-cache ca-certificates git
6+
7+
WORKDIR /workspace
8+
9+
# Copy the Go Modules manifests
10+
COPY go.mod go.mod
11+
COPY go.sum go.sum
12+
13+
# Cache deps before building and copying source so that we don't need to re-download as much
14+
# and so that source changes don't invalidate our downloaded layer
15+
RUN go mod download
16+
17+
# Copy the go source
18+
COPY cmd/ cmd/
19+
COPY controllers/ controllers/
20+
COPY pkg/ pkg/
21+
22+
# Build
23+
ARG TARGETOS=linux
24+
ARG TARGETARCH=amd64
25+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -o manager cmd/manager/main.go
26+
27+
# Use distroless as minimal base image to package the manager binary
28+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
29+
FROM gcr.io/distroless/static:nonroot
30+
WORKDIR /
31+
COPY --from=builder /workspace/manager .
32+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
33+
34+
USER 65532:65532
35+
36+
ENTRYPOINT ["/manager"]

0 commit comments

Comments
 (0)