Skip to content

Commit

Permalink
Initialize CSI Driver
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeyaraj-crusoe committed Jul 12, 2024
1 parent 6f5e201 commit 15a2ece
Show file tree
Hide file tree
Showing 34 changed files with 2,833 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .github/workflows/build-publish-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: build and publish

on:
push:
tags:
- v*

permissions:
contents: read
packages: write
attestations: write
id-token: write

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log into the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
24 changes: 24 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- main
pull_request:
permissions:
contents: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.22"
cache: false
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
43 changes: 43 additions & 0 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: semver tag

on:
push:
branches:
- main

permissions:
contents: write

jobs:
semver-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Git
run: |
git config user.name "crusoe-cloud"
git config user.email "[email protected]"
- name: Load versions from text file
run: |
source versions.env
echo "MAJOR_VERSION=${MAJOR_VERSION}" >> $GITHUB_ENV
echo "MINOR_VERSION=${MINOR_VERSION}" >> $GITHUB_ENV
- name: Calculate and set new version
run: |
chmod +x ./scripts/tag_semver.sh
./scripts/tag_semver.sh $MAJOR_VERSION $MINOR_VERSION ""
shell: bash

- name: Read version and push tag
run: |
source variables.env
echo "Calculated version: $RELEASE_VERSION"
source variables.env
git tag $RELEASE_VERSION
git push origin $RELEASE_VERSION
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.jar
*.swp
*tmp/
.idea/
.DS_Store
.vscode/*
aliaslint.so
coverage.out
dist/
gokart_result.json
golangci-lint.json
node_modules/
package*.json
tests.xml
coverage.xml
42 changes: 42 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
include:
- project: 'crusoeenergy/tools'
file: '/templates/go.gitlab-ci.yml'

variables:
CI_IMAGE: registry.gitlab.com/crusoeenergy/tools/go-ci-1.22

test_and_lint:
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "release"'
changes: !reference [.code-changes, changes]
- if: '$CI_MERGE_REQUEST_ID'
changes: !reference [.code-changes, changes]
# don't run CI for semver tags, do run it for custom tags
- if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG !~ /^(.+\/)?v[0-9]+\.[0-9]+\.[0-9]+$/'

build_and_push:
script:
- |-
if [ "${BUILD_IN_SUBPATH:-true}" == "true" ]; then
cd ${SUBPROJECT_REL_PATH}
fi
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
# Build an image based on the commit ref, this will be available
# internally for testing feature branches and testing pre-release versions
- 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_CSI_DRIVER_NAME="$CRUSOE_CSI_DRIVER_NAME" --build-arg CRUSOE_CSI_DRIVER_VERSION="$CI_COMMIT_REF_NAME" -t $RELEASE_IMAGE:"${CI_COMMIT_REF_NAME##*/}" .
- docker push $RELEASE_IMAGE:"${CI_COMMIT_REF_NAME##*/}"

# Remove the tag_semver and pages jobs from merges into main.
# The tag_semver job will be run using a GitHub action instead
# and new versions will be pushed then.
tag_semver:
rules:
- when: never

code_intelligence:
rules:
- when: never

pages:
rules:
- when: never
12 changes: 12 additions & 0 deletions .gitlab/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# default = everyone is codeowner
* @crusoeenergy/island

.gitlab/CODEOWNERS @lanwall12 @nitper @bsherrycrusoe @ksosnowski3 @dpattishall

# more restrictive ownership for adding dependencies and changing ci/build
.gitlab-ci.yml @lanwall12 @nitper @crusoeenergy/island/ccx
.golangci-lint.yml @lanwall12 @nitper @crusoeenergy/island/ccx
go.mod @lanwall12 @nitper @crusoeenergy/island/ccx
Makefile @lanwall12 @nitper @crusoeenergy/island/ccx
Dockerfile @lanwall12 @nitper @crusoeenergy/island/ccx
Dockerfile.* @lanwall12 @nitper @crusoeenergy/island/ccx
118 changes: 118 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# see https://golangci-lint.run/usage/configuration/
linters-settings:
errcheck:
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: true

# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
govet:
check-shadowing: true
gci:
sections:
- standard
- default
- prefix(github.com/crusoecloud)
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- commentedOutCode
whitespace:
multi-if: true # Enforces newlines (or comments) after every multi-line if statement
gosec:
global:
audit: enabled # Run extra checks that might be "nosy"
gomoddirectives:
replace-allow-list:
- github.com/crusoecloud/client-go

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- cyclop
- dogsled
- dupl
- durationcheck
- errcheck
- errorlint
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- funlen
- gci
- gochecknoinits
- gochecknoglobals
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nlreturn
- noctx
- nolintlint
- paralleltest
- prealloc
- predeclared
- promlinter
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tagliatelle
- testpackage
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- wastedassign
- whitespace
- wrapcheck

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Exclude lll issues for long lines with go:generate
- linters:
- lll
source: "^//go:generate "

run:
# include test files or not
tests: true

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.50.1 # use a fixed version for consistent results
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
##########################################
# STEP 1: build crusoe-csi-driver binary #
##########################################

FROM golang:1.22 as builder

ARG CRUSOE_CSI_DRIVER_NAME
ENV CRUSOE_CSI_DRIVER_NAME=$CRUSOE_CSI_DRIVER_NAME
ARG CRUSOE_CSI_DRIVER_VERSION
ENV CRUSOE_CSI_DRIVER_VERSION=$CRUSOE_CSI_DRIVER_VERSION

WORKDIR /build
COPY . .

RUN make cross

################################################################
# STEP 2: build a small image and run crusoe-csi-driver binary #
################################################################
FROM alpine

# Need to get these updates for k8s mount-utils library to work properly
RUN apk update && \
apk add --no-cache e2fsprogs && \
apk add --no-cache blkid && \
rm -rf /var/cache/apk/*

COPY --from=builder /build/dist/crusoe-csi-driver /usr/local/go/bin/crusoe-csi-driver

ENTRYPOINT ["/usr/local/go/bin/crusoe-csi-driver"]
Loading

0 comments on commit 15a2ece

Please sign in to comment.