diff --git a/.github/workflows/build-and-push-image.yml b/.github/workflows/build-and-push-image.yml new file mode 100644 index 0000000..b1efec9 --- /dev/null +++ b/.github/workflows/build-and-push-image.yml @@ -0,0 +1,67 @@ +name: Build Image and Publish to Dockerhub + +on: + release: + types: [ published ] + workflow_dispatch: + inputs: + tag: + description: 'Image tag' + required: true + default: 'test' +permissions: + contents: read + +jobs: + image: + name: Build Image from Dockerfile and binaries + runs-on: ubuntu-latest + steps: + # environment + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: '0' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Get Image Tag Name + run: | + if [ x${{ github.event.inputs.tag }} == x"" ]; then + echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + else + echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV + fi + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + # prepare image tags + - name: Prepare Image Tags + run: | + echo "TAG_MANAGER=akyriako78/rekuberate-io-sleepcycles:${{ env.TAG_NAME }}" >> $GITHUB_ENV + echo "TAG_RUNNER=akyriako78/rekuberate-io-sleepcycles:${{ env.TAG_NAME }}" >> $GITHUB_ENV + + - name: Build and push manager + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm/v7,linux/arm64 + push: true + tags: | + ${{ env.TAG_MANAGER }} + + - name: Build and push runner + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile.runner + platforms: linux/amd64,linux/arm/v7,linux/arm64 + push: true + tags: | + ${{ env.TAG_RUNNER }} diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..96d67ab --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,50 @@ +name: golangci-lint +on: + push: + branches: + - master + - dev + pull_request: +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + pull-requests: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + timeout-minutes: 5 + strategy: + fail-fast: true + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: '1.23' + cache: false + + - name: golangci-lint + uses: golangci/golangci-lint-action@v4 + with: + version: v1.61 + args: --timeout 5m + + - name: Go Format + run: gofmt -s -w . && git diff --exit-code + + - name: Go Vet + run: go vet ./... + + - name: Go Tidy + run: go mod tidy && git diff --exit-code + + - name: Go Mod + run: go mod download + + - name: Go Mod Verify + run: go mod verify + + # TODO: enable tests + # - name: Go Test + # run: go test -v -count=1 -race -shuffle=on -coverprofile=coverage.txt ./... diff --git a/.github/workflows/lint-helm-test.yaml b/.github/workflows/lint-helm-test.yaml new file mode 100644 index 0000000..700984d --- /dev/null +++ b/.github/workflows/lint-helm-test.yaml @@ -0,0 +1,45 @@ +name: Lint and Test Charts + +on: pull_request + +jobs: + lint-test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Helm + uses: azure/setup-helm@v4.2.0 + with: + version: v3.14.4 + + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + check-latest: true + + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.6.1 + + - name: Run chart-testing (list-changed) + id: list-changed + run: | + changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }}) + if [[ -n "$changed" ]]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + fi + + - name: Run chart-testing (lint) + if: steps.list-changed.outputs.changed == 'true' + run: ct lint --target-branch ${{ github.event.repository.default_branch }} + + - name: Create kind cluster + if: steps.list-changed.outputs.changed == 'true' + uses: helm/kind-action@v1.10.0 + + - name: Run chart-testing (install) + if: steps.list-changed.outputs.changed == 'true' + run: ct install --target-branch ${{ github.event.repository.default_branch }} diff --git a/controllers/sleepcycle_controller.go b/controllers/sleepcycle_controller.go index c703c23..d1e5275 100644 --- a/controllers/sleepcycle_controller.go +++ b/controllers/sleepcycle_controller.go @@ -19,6 +19,9 @@ package controllers import ( "context" "fmt" + "strings" + "time" + "github.com/go-logr/logr" "github.com/hashicorp/go-multierror" corev1alpha1 "github.com/rekuberate-io/sleepcycles/api/v1alpha1" @@ -31,7 +34,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "time" ) const ( diff --git a/controllers/sleepcycle_runners_cronjobs.go b/controllers/sleepcycle_runners_cronjobs.go index c81cde4..08fe628 100644 --- a/controllers/sleepcycle_runners_cronjobs.go +++ b/controllers/sleepcycle_runners_cronjobs.go @@ -3,6 +3,9 @@ package controllers import ( "context" "fmt" + "strconv" + "strings" + "github.com/go-logr/logr" corev1alpha1 "github.com/rekuberate-io/sleepcycles/api/v1alpha1" batchv1 "k8s.io/api/batch/v1" @@ -11,8 +14,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - "strconv" - "strings" ) var ( diff --git a/runners/runner.go b/runners/runner.go index 2d7e715..a694f59 100644 --- a/runners/runner.go +++ b/runners/runner.go @@ -4,6 +4,11 @@ import ( "context" "flag" "fmt" + "os" + "strconv" + "strings" + "time" + "github.com/go-logr/logr" "github.com/pkg/errors" "go.uber.org/zap/zapcore" @@ -17,12 +22,9 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/record" "k8s.io/utils/pointer" - "os" + ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log/zap" - "strconv" - "strings" - "time" ) var (