Skip to content

Commit

Permalink
Feat: Add magefile, ko and goreleaser (#14)
Browse files Browse the repository at this point in the history
* Add serviceMonitor to helm chart

* Add support for magefile

* Update release github action

* Update CI for add new env vars

* Test github action for mage release

* Update magefile for ko login

* Test with Github Actions for magefile

* Add some testing flows for magefile

* Test release CI

* More test for all platform supports

* Add RELEASE_TOKEN for creating release on GH

* fix: Add RELEASE_TOKEN for creating release on GH

* Test with ko-goreleaser-magefile stack again

* Update github workflows for verify and release flows

---------

Co-authored-by: alperencelik <[email protected]>
  • Loading branch information
alperencelik and alperencelik authored Jan 7, 2024
1 parent de2a0a8 commit efb9830
Show file tree
Hide file tree
Showing 14 changed files with 680 additions and 32 deletions.
47 changes: 26 additions & 21 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
name: docker-build
name: Release

on:
push:
branches:
- "main"

env:
TEST_TAG: alperencelik/kubemox:test
LATEST_TAG: alperencelik/kubemox:latest
tags:
- '*'

jobs:
docker:
release:
permissions:
packages: write
contents: write
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: Check out code
uses: actions/checkout@v2

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.LATEST_TAG }}

- name: Set environment variables
run: |
echo "BUILD_IMAGE=golang:1.21" >> $GITHUB_ENV
echo "KO_DOCKER_REPO=alperencelik/kubemox" >> $GITHUB_ENV
- name: Run mage.go Release
run: go run mage.go Release
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: verify

on:
pull_request:
types: [opened, edited, synchronize, reopened]
branches:
- main

jobs:
verify:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: Check out code
uses: actions/checkout@v2

- name: Run mage.go
run: go run mage.go
100 changes: 100 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
linters-settings:
errcheck:
ignore: github.com/go-kit/log:.*
dupl:
threshold: 100
funlen:
lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner.
statements: 50
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
gocyclo:
min-complexity: 15
gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
goimports:
local-prefixes: github.com/golangci/golangci-lint
gomnd:
# don't include the "operation" and "assign"
checks:
- argument
- case
- condition
- return
ignored-numbers:
- '0'
- '1'
- '2'
- '3'
ignored-functions:
- strings.SplitN

govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
revive:
rules:
- name: unexported-return
disabled: true
- name: unused-parameter

linters:
disable-all: true
enable:
- bodyclose
- dogsled
- dupl
- errcheck
- exportloopref
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- nolintlint
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

run:
timeout: 5m
skip-dirs:
- test # test files
101 changes: 101 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
project_name: kubemox

before:
hooks:
- go mod tidy
- /bin/bash -c 'if [ -n "$(git --no-pager diff --exit-code go.mod go.sum)" ]; then exit 1; fi'

builds:
- id: kubemox
binary: kubemox
main: cmd/main.go
env:
- CGO_ENABLED=0
flags:
- -trimpath
ldflags:
- -extldflags "-static"
- -s
- -w
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm
- arm64
ignore:
- goos: openbsd
goarch: arm
goarm: 6
mod_timestamp: '{{ .CommitTimestamp }}'

kos:
- id: kubemox-image
build: kubemox
main: ./cmd/...
base_image: ghcr.io/distroless/static:latest
platforms:
- all
ldflags:
- -extldflags "-static"
- -s
- -w
tags:
- latest
- '{{ .Tag }}'
env:
- CGO_ENABLED=0
flags:
- -trimpath
sbom: none
bare: true
preserve_import_paths: false
base_import_paths: false

archives:
- id: with-version
name_template: >-
{{ .ProjectName }}_
{{- .Version }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
format: tar.gz
format_overrides:
- goos: windows
format: zip
files:
- README.md
- id: without-version
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
format: tar.gz
format_overrides:
- goos: windows
format: zip
files:
- README.md

checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt'

snapshot:
name_template: SNAPSHOT-{{ .Commit }}

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- '^demo:'
- 'README'
- Merge pull request
- Merge branch
14 changes: 14 additions & 0 deletions .ko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defaultBaseImage: ghcr.io/distroless/static:latest

builds:
- id: kubemox
dir: cmd
main: main.go
env:
- CGO_ENABLED=0
ldflags:
- -extldflags "-static"
- -s
- -w
- "{{ .Env.LDFLAGS }}"
sbom: none
65 changes: 65 additions & 0 deletions charts/kubemox/samples/virtualmachineset-new.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apiVersion: proxmox.alperen.cloud/v1alpha1
kind: VirtualMachineSet
metadata:
labels:
app.kubernetes.io/name: virtualmachineset
app.kubernetes.io/instance: virtualmachineset-sample
app.kubernetes.io/part-of: kubemox
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: kubemox
name: kubernetes-master
spec:
# Number of VMs to be created
replicas: 1
nodeName: lowtower
template:
# Name of the template to be cloned
name: fedora-template
# CPU cores to be allocated to the VM
cores: 4
# CPU sockets to be allocated to the VM
socket: 1
# Memory to be allocated to the VM
memory: 4096 # As MB
# Disk used by the VM
disk:
- storage: nvme
size: 50 # As GB
type: scsi
# Network interfaces used by the VM
network:
- model: virtio
bridge: vmbr0
---
apiVersion: proxmox.alperen.cloud/v1alpha1
kind: VirtualMachineSet
metadata:
labels:
app.kubernetes.io/name: virtualmachineset
app.kubernetes.io/instance: virtualmachineset-sample
app.kubernetes.io/part-of: kubemox
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: kubemox
name: kubernetes-worker
spec:
# Number of VMs to be created
replicas: 2
nodeName: lowtower
template:
# Name of the template to be cloned
name: fedora-template
# CPU cores to be allocated to the VM
cores: 8
# CPU sockets to be allocated to the VM
socket: 1
# Memory to be allocated to the VM
memory: 32768 # As MB
# Disk used by the VM
disk:
- storage: nvme
size: 50 # As GB
type: scsi
# Network interfaces used by the VM
network:
- model: virtio
bridge: vmbr0
4 changes: 2 additions & 2 deletions charts/kubemox/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
targetPort: {{ .Values.service.targetPort }}
protocol: TCP
name: http
name: {{ .Values.service.portName }}
selector:
{{- include "kubemox.selectorLabels" . | nindent 4 }}
Loading

0 comments on commit efb9830

Please sign in to comment.