Skip to content

Commit c00a90c

Browse files
Crusoe CCM
1 parent d4bccf1 commit c00a90c

26 files changed

+2146
-1
lines changed

.github/workflows/golangci-lint.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
pull_request:
5+
permissions:
6+
contents: read
7+
jobs:
8+
golangci:
9+
name: lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/setup-go@v4
13+
with:
14+
go-version: "1.23"
15+
cache: false
16+
- uses: actions/checkout@v3
17+
- name: golangci-lint
18+
uses: golangci/golangci-lint-action@v3
19+
with:
20+
version: v1.62.0
21+
args: "--timeout=5m"

.github/workflows/tag-release.yml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: semver tag
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
attestations: write
11+
packages: write
12+
13+
env:
14+
CRUSOE_CLOUD_CONTROLLER_MANAGER_NAME: ccm.crusoe.ai
15+
16+
jobs:
17+
semver-tag:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Set up Git
26+
run: |
27+
git config user.name "crusoe-cloud"
28+
git config user.email "support@crusoecloud.com"
29+
30+
- name: Load versions from text file
31+
run: |
32+
source versions.env
33+
echo "MAJOR_VERSION=${MAJOR_VERSION}" >> $GITHUB_ENV
34+
echo "MINOR_VERSION=${MINOR_VERSION}" >> $GITHUB_ENV
35+
36+
- name: Calculate and set new version
37+
run: |
38+
chmod +x ./scripts/tag_semver.sh
39+
./scripts/tag_semver.sh $MAJOR_VERSION $MINOR_VERSION ""
40+
shell: bash
41+
42+
- name: Read version and push tag
43+
run: |
44+
source variables.env
45+
echo "Calculated version: $RELEASE_VERSION"
46+
source variables.env
47+
git tag $RELEASE_VERSION
48+
git push origin $RELEASE_VERSION
49+
goreleaser:
50+
needs: semver-tag
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
54+
with:
55+
# Allow goreleaser to access older tag information.
56+
fetch-depth: 0
57+
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
58+
with:
59+
go-version-file: 'go.mod'
60+
cache: true
61+
- name: Set up QEMU
62+
uses: docker/setup-qemu-action@v3
63+
- name: Set up Docker Buildx
64+
uses: docker/setup-buildx-action@v3
65+
- name: Login to GitHub Container Registry
66+
uses: docker/login-action@v3
67+
with:
68+
registry: ghcr.io
69+
username: ${{ github.actor }}
70+
password: ${{ secrets.GITHUB_TOKEN }}
71+
- name: Import GPG key
72+
uses: crazy-max/ghaction-import-gpg@72b6676b71ab476b77e676928516f6982eef7a41 # v5.3.0
73+
id: import_gpg
74+
with:
75+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
76+
passphrase: ${{ secrets.PASSPHRASE }}
77+
- name: Run GoReleaser
78+
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
79+
with:
80+
args: release --clean
81+
version: 2.1.x
82+
env:
83+
# GitHub sets the GITHUB_TOKEN secret automatically.
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
dist/
2+
.DS_Store
3+
*.swp
4+
coverage.out
5+
aliaslint.so
6+
gokart_result.json
7+
golangci-lint.json
8+
tests.xml
9+
coverage.xml
10+
.vscode/*
11+
.idea/*

.gitlab-ci.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
include:
2+
- project: 'crusoeenergy/tools'
3+
file: '/templates/go.gitlab-ci.yml'
4+
5+
variables:
6+
CI_IMAGE: registry.gitlab.com/crusoeenergy/tools/go-ci-1.22
7+
8+
test_and_lint:
9+
rules:
10+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "release"'
11+
changes: !reference [.code-changes, changes]
12+
- if: '$CI_MERGE_REQUEST_ID'
13+
changes: !reference [.code-changes, changes]
14+
# don't run CI for semver tags, do run it for custom tags
15+
- if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG !~ /^(.+\/)?v[0-9]+\.[0-9]+\.[0-9]+$/'
16+
17+
build_and_push:
18+
script:
19+
- |-
20+
if [ "${BUILD_IN_SUBPATH:-true}" == "true" ]; then
21+
cd ${SUBPROJECT_REL_PATH}
22+
fi
23+
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
24+
# Build an image based on the commit ref, this will be available
25+
# internally for testing feature branches and testing pre-release versions
26+
- docker build --no-cache --pull -f "${DOCKERFILE:-./Dockerfile}" --build-arg CI_SERVER_HOST="$CI_SERVER_HOST" --build-arg CI_JOB_TOKEN="$CI_JOB_TOKEN" --build-arg CRUSOE_CLOUD_CONTROLLER_MANAGER_NAME="$CRUSOE_CLOUD_CONTROLLER_MANAGER_NAME" --build-arg CRUSOE_CLOUD_CONTROLLER_MANAGER_VERSION="$CI_COMMIT_REF_NAME" -t $RELEASE_IMAGE:"${CI_COMMIT_REF_NAME##*/}" .
27+
- docker push $RELEASE_IMAGE:"${CI_COMMIT_REF_NAME##*/}"
28+
29+
# Remove the tag_semver and pages jobs from merges into main.
30+
# The tag_semver job will be run using a GitHub action instead
31+
# and new versions will be pushed then.
32+
tag_semver:
33+
rules:
34+
- when: never
35+
36+
code_intelligence:
37+
rules:
38+
- when: never
39+
40+
pages:
41+
rules:
42+
- when: never

.gitlab/CODEOWNERS

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# default = everyone is codeowner
2+
* @crusoeenergy/island
3+
4+
.gitlab/CODEOWNERS @lanwall12 @nitper @bsherrycrusoe @ksosnowski3 @dpattishall
5+
6+
# more restrictive ownership for adding dependencies and changing ci/build
7+
.gitlab-ci.yml @lanwall12 @nitper @crusoeenergy/island/managed
8+
.golangci-lint.yml @lanwall12 @nitper @crusoeenergy/island/managed
9+
go.mod @lanwall12 @nitper @crusoeenergy/island/managed
10+
Makefile @lanwall12 @nitper @crusoeenergy/island/managed
11+
Dockerfile @lanwall12 @nitper @crusoeenergy/island/managed
12+
Dockerfile.* @lanwall12 @nitper @crusoeenergy/island/managed

.golangci.yml

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# see https://golangci-lint.run/usage/configuration/
2+
linters-settings:
3+
errcheck:
4+
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
5+
# default is false: such cases aren't reported by default.
6+
check-type-assertions: true
7+
8+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
9+
# default is false: such cases aren't reported by default.
10+
check-blank: true
11+
govet:
12+
check-shadowing: true
13+
gci:
14+
local-prefixes: gitlab.com/crusoeenergy
15+
gocritic:
16+
enabled-tags:
17+
- diagnostic
18+
- experimental
19+
- opinionated
20+
- performance
21+
- style
22+
disabled-checks:
23+
- commentedOutCode
24+
whitespace:
25+
multi-if: true # Enforces newlines (or comments) after every multi-line if statement
26+
gosec:
27+
global:
28+
audit: enabled # Run extra checks that might be "nosy"
29+
gomoddirectives:
30+
replace-allow-list:
31+
- github.com/crusoecloud/client-go
32+
33+
linters:
34+
disable-all: true
35+
enable:
36+
- asciicheck
37+
- bodyclose
38+
- cyclop
39+
- dogsled
40+
- dupl
41+
- durationcheck
42+
- errcheck
43+
- errorlint
44+
- exhaustive
45+
- forbidigo
46+
- forcetypeassert
47+
- funlen
48+
- gci
49+
- gochecknoinits
50+
- gochecknoglobals
51+
- gocognit
52+
- goconst
53+
- gocritic
54+
- gocyclo
55+
- godot
56+
- gofmt
57+
- gofumpt
58+
- goheader
59+
- goimports
60+
- gomoddirectives
61+
- gomodguard
62+
- goprintffuncname
63+
- gosec
64+
- gosimple
65+
- govet
66+
- ineffassign
67+
- lll
68+
- makezero
69+
- misspell
70+
- nakedret
71+
- nestif
72+
- nilerr
73+
- nlreturn
74+
- noctx
75+
- nolintlint
76+
- paralleltest
77+
- prealloc
78+
- predeclared
79+
- promlinter
80+
- revive
81+
- rowserrcheck
82+
- sqlclosecheck
83+
- staticcheck
84+
- stylecheck
85+
- tagliatelle
86+
- testpackage
87+
- thelper
88+
- tparallel
89+
- typecheck
90+
- unconvert
91+
- unparam
92+
- unused
93+
- wastedassign
94+
- whitespace
95+
- wrapcheck
96+
97+
issues:
98+
# Excluding configuration per-path, per-linter, per-text and per-source
99+
exclude-rules:
100+
# Exclude lll issues for long lines with go:generate
101+
- linters:
102+
- lll
103+
source: "^//go:generate "
104+
105+
run:
106+
# include test files or not
107+
tests: true
108+
109+
# golangci.com configuration
110+
# https://github.com/golangci/golangci/wiki/Configuration
111+
service:
112+
golangci-lint-version: 1.50.1 # use a fixed version for consistent results

.goreleaser.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
version: 2
2+
# Visit https://goreleaser.com for documentation on how to customize this
3+
# behavior.
4+
before:
5+
hooks:
6+
- go mod tidy
7+
builds:
8+
- main: ./cmd/crusoe-cloud-controller-manager/main.go
9+
env:
10+
- CGO_ENABLED=0
11+
mod_timestamp: '{{.CommitTimestamp }}'
12+
flags:
13+
- -trimpath
14+
ldflags:
15+
- "-X 'github.com/crusoecloud/crusoe-cloud-controller-manager/internal/ccm.version={{ .Tag }}' -X 'github.com/crusoecloud/crusoe-cloud-controller-manager/internal/ccm.name={{ .Env.CRUSOE_CLOUD_CONTROLLER_MANAGER_NAME }}'"
16+
goos:
17+
- linux
18+
goarch:
19+
- amd64
20+
- arm64
21+
binary: '{{ .ProjectName }}'
22+
dockers:
23+
- image_templates:
24+
- 'ghcr.io/crusoecloud/{{ .ProjectName }}:{{ .Tag }}-amd64'
25+
use: buildx
26+
build_flag_templates:
27+
- "--pull"
28+
- "--platform=linux/amd64"
29+
dockerfile: Dockerfile.goreleaser
30+
- image_templates:
31+
- 'ghcr.io/crusoecloud/{{ .ProjectName }}:{{ .Tag }}-arm64'
32+
use: buildx
33+
build_flag_templates:
34+
- "--pull"
35+
- "--platform=linux/arm64"
36+
dockerfile: Dockerfile.goreleaser
37+
goarch: arm64
38+
docker_manifests:
39+
- name_template: 'ghcr.io/crusoecloud/{{ .ProjectName }}:{{ .Tag }}'
40+
image_templates:
41+
- 'ghcr.io/crusoecloud/{{ .ProjectName }}:{{ .Tag }}-amd64'
42+
- 'ghcr.io/crusoecloud/{{ .ProjectName }}:{{ .Tag }}-arm64'
43+
signs:
44+
- artifacts: checksum
45+
args:
46+
# if you are using this in a GitHub action or some other automated pipeline, you
47+
# need to pass the batch flag to indicate its not interactive.
48+
- "--batch"
49+
- "--local-user"
50+
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
51+
- "--output"
52+
- "${signature}"
53+
- "--detach-sign"
54+
- "${artifact}"
55+
56+
changelog:
57+
disable: true

Dockerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
##########################################
2+
# STEP 1: build crusoe-cloud-controller-manager binary #
3+
##########################################
4+
5+
FROM golang:1.22.9 AS builder
6+
7+
ARG CRUSOE_CLOUD_CONTROLLER_MANAGER_NAME
8+
ENV CRUSOE_CLOUD_CONTROLLER_MANAGER_NAME=$CRUSOE_CLOUD_CONTROLLER_MANAGER_NAME
9+
ARG CRUSOE_CLOUD_CONTROLLER_MANAGER_VERSION
10+
ENV CRUSOE_CLOUD_CONTROLLER_MANAGER_VERSION=$CRUSOE_CLOUD_CONTROLLER_MANAGER_VERSION
11+
12+
WORKDIR /build
13+
14+
COPY go.mod .
15+
COPY go.sum .
16+
17+
RUN go mod download
18+
19+
COPY . .
20+
21+
RUN make cross
22+
23+
################################################################
24+
# STEP 2: build a small image and run crusoe-cloud-controller-manager binary #
25+
################################################################
26+
27+
# Dockerfile.goreleaser should be kept roughly in sync
28+
FROM alpine:3.20.3
29+
30+
COPY --from=builder /build/dist/crusoe-cloud-controller-manager /usr/local/go/bin/crusoe-cloud-controller-manager
31+
32+
ENTRYPOINT ["/usr/local/go/bin/crusoe-cloud-controller-manager"]

Dockerfile.goreleaser

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
################################################################
2+
# STEP 2: build a small image and run crusoe-cloud-controller-manager binary #
3+
################################################################
4+
FROM alpine:3.20.3
5+
6+
COPY crusoe-cloud-controller-manager /usr/local/go/bin/crusoe-cloud-controller-manager
7+
8+
ENTRYPOINT ["/usr/local/go/bin/crusoe-cloud-controller-manager"]

0 commit comments

Comments
 (0)