diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index bd7c5233..00000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: bug -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Configuration** -If applicable, add screenshots to help explain your problem. - -**Additional context** -Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index bdf172c0..00000000 --- a/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1,5 +0,0 @@ -blank_issues_enabled: false -contact_links: - - name: Questions and Answers - url: https://github.com/burningalchemist/sql_exporter/discussions - about: Please ask your questions on installation and usage here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 570b10b0..00000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an improvement for this project -title: '' -labels: enhancement -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index af76e691..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "gomod" - directory: "/" - schedule: - interval: "monthly" - labels: - - "dependencies" - commit-message: - prefix: "deps" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index d066f350..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Go - -on: - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - build: - if: ${{ !startsWith(github.event.head_commit.message, 'docs:') }} - name: Build - runs-on: ubuntu-latest - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v5 - with: - go-version: ^1.20 - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: Style - run: make style - - name: Vet - run: make vet - - name: Test - run: make test - - name: Build - run: make build diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 04a838ba..00000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [master] - pull_request: - # The branches below must be a subset of the branches above - branches: [master] - schedule: - - cron: '0 23 * * 5' - -jobs: - analyze: - if: | - ${{ !startsWith(github.event.head_commit.message, 'docs:') }} || - ${{ !startsWith(github.event.head_commit.message, 'build:') }} - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - # Override automatic language detection by changing the below list - # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] - language: ['go'] - # Learn more... - # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: ^1.20 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/helm-workflow.yaml b/.github/workflows/helm-workflow.yaml deleted file mode 100644 index 22fcd14a..00000000 --- a/.github/workflows/helm-workflow.yaml +++ /dev/null @@ -1,115 +0,0 @@ -name: Helm -on: - push: - branches: - - master - pull_request: - branches: - - master -env: - HELM_VERSION: 3.12.1 - PYTHON_VERSION: 3.9 - TARGET_BRANCH: chart-testing-target-branch - TARGET_REMOTE: test -jobs: - helm-jobs: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Set up Helm - uses: azure/setup-helm@v4 - with: - version: "v${{ env.HELM_VERSION }}" - - uses: actions/setup-python@v5 - with: - python-version: ${{ env.PYTHON_VERSION }} - check-latest: true - # --------------------------------------------------------------- - # -- Instead of comparing to the master branch, I'm getting - # -- the commit hash set in the previous step from a - # -- currently released chart. If it doesn't exists, then - # -- I assume that chart is not released and compare to the - # -- previous commit - # -- - # -- Also, I'm setting the RepoURL here. Since we plan to support - # -- the official chart in this git repository, the helm - # -- repository is expected to belong to this repo as well. - # --------------------------------------------------------------- - - name: Retrieve the latest commit sha from the helm chart - run: | - HELM_REPO_URL="https://${GITHUB_REPOSITORY_OWNER}.github.io/${GITHUB_REPOSITORY#*/}" - if helm repo add sql-exporter $HELM_REPO_URL - then - helm repo update - echo "TARGET_COMMIT=$(helm show chart sql-exporter/sql-exporter | yq '.annotations.git/commit-sha')" >> "${GITHUB_ENV}" - else - echo "TARGET_COMMIT=$(git show HEAD^1 --pretty=format:%H --no-patch)" >> "${GITHUB_ENV}" - fi - # --------------------------------------------------------------- - # -- As I could find CT doesn't support testing against commits - # -- directly, so I'm creating a new fake remote from a commit - # -- and testing the chart against it. This workaround doesn't - # -- support maintainers validation, but we have it disabled - # -- anyway - # --------------------------------------------------------------- - - name: Prepare a dummy remote to test the chart - run: | - DUMMY_REMOTE=$(mktemp -d) - git init "${DUMMY_REMOTE}" - git remote add "${TARGET_REMOTE}" "${DUMMY_REMOTE}" - git checkout -b "${TARGET_BRANCH}" "${TARGET_COMMIT}" - git push --set-upstream "${TARGET_REMOTE}" "${TARGET_BRANCH}" - git checkout "${GITHUB_SHA}" - - name: Set up chart-testing - uses: helm/chart-testing-action@v2.6.0 - - name: Run chart-testing (list-changed) - id: list-changed - run: | - changed=$(ct list-changed --chart-dirs . --target-branch "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}") - 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 "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}" --validate-maintainers=false --chart-dirs . - - name: Setup helmfile - if: steps.list-changed.outputs.changed == 'true' - uses: mamezou-tech/setup-helmfile@v2.0.0 - - name: Create kind cluster - if: steps.list-changed.outputs.changed == 'true' - uses: helm/kind-action@v1.9.0 - - name: Init postgres server - if: steps.list-changed.outputs.changed == 'true' - run: | - helmfile -f helm/ci/helmfile.yaml sync - - name: Run chart-testing (install) - if: steps.list-changed.outputs.changed == 'true' - run: ct install --target-branch "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}" --chart-dirs . - - name: Run chart-testing (upgrade) - if: steps.list-changed.outputs.changed == 'true' - run: ct install --target-branch "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}" --chart-dirs . --upgrade - - name: Configure Git - run: | - git config user.name "$GITHUB_ACTOR" - git config user.email "$GITHUB_ACTOR@users.noreply.github.com" - # --------------------------------------------------------------- - # -- On each run we're setting an annotation with the current - # -- commit hash, so in case it's released, we will see it - # -- running `$ helm show sql-exporter/sql-exporter` - # --------------------------------------------------------------- - - name: Set the git sha annotations in the helm chart - run: yq -i ".annotations.git/commit-sha = \"${GITHUB_SHA}\"" ./helm/Chart.yaml - - - name: Release charts - if: ${{ github.event.repository.default_branch && github.event_name == 'push' }} - uses: helm/chart-releaser-action@main - with: - charts_dir: . - mark_as_latest: false - packages_with_index: true - env: - CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - CR_RELEASE_NAME_TEMPLATE: "chart-{{ .Name }}-{{ .Version }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0a8f4fe8..7ab91eb2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,94 +1,41 @@ -name: Build and Publish artifacts +name: Release on: workflow_dispatch: push: tags: - - '*.*.*' + - "*.*" + - "*.*.*" jobs: build: - name: Build and upload artifacts + name: Build runs-on: ubuntu-latest - env: - VERSION: ${{ github.ref_name }} steps: - - name: Set up Go 1.x - uses: actions/setup-go@v5 - with: - go-version: ^1.20 - - name: Check out code into the Go module directory - uses: actions/checkout@v4 + - uses: actions/checkout@v1 - - name: Promu - Crossbuild - run: make crossbuild - - - name: Promu - Prepare packages - run: make crossbuild-tarballs - - - name: Create deb package - uses: burningalchemist/action-gh-nfpm@v1 - with: - packager: deb - config: packaging/conf/nfpm.yaml - target: .tarballs/ - - name: Create rpm package - uses: burningalchemist/action-gh-nfpm@v1 - with: - packager: rpm - config: packaging/conf/nfpm.yaml - target: .tarballs/ - - - name: Calculate checksums - run: make crossbuild-checksum - - - name: Upload artifacts - uses: softprops/action-gh-release@v2 - with: - files: | - .tarballs/* - docker: - name: Push Docker image to Docker Hub - runs-on: ubuntu-latest - needs: build - steps: - - name: Check out the repo - uses: actions/checkout@v4 - - - name: Get Go version from the '.promu.yml' config - id: promu-go-version - run: printf "version=%s" "$(yq '.go.version' .promu.yml)" >> $GITHUB_OUTPUT + - name: Print version info + id: semver + run: | + make version - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + id: qemu + uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@v1 - - name: Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} + - name: Available platforms + run: echo ${{ steps.buildx.outputs.platforms }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5 + - name: Log in to the GitHub Container registry + uses: docker/login-action@v2 with: - images: burningalchemist/sql_exporter - tags: | - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - file: Dockerfile.multi-arch - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - platforms: linux/amd64,linux/arm64 - provenance: false - build-args: | - GOVERSION=${{ steps.promu-go-version.outputs.version }} + - name: Build mssql-exporter + run: | + make release \ No newline at end of file diff --git a/Makefile b/Makefile index dfbb99e4..69c412bd 100644 --- a/Makefile +++ b/Makefile @@ -27,20 +27,24 @@ pkgs = $(shell $(GO) list ./... | grep -v /vendor/) PREFIX ?= $(shell pwd) BIN_DIR ?= $(shell pwd) -DOCKER_IMAGE_NAME ?= sql-exporter +REGISTRY ?= ghcr.io/kubedb +BIN ?= mssql-exporter +IMAGE := $(REGISTRY)/$(BIN) +TAG ?= $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "") +DOCKER_PLATFORMS := linux/amd64 linux/arm64 +PLATFORM ?= $(firstword $(DOCKER_PLATFORMS)) +VERSION = $(TAG)_$(subst /,_,$(PLATFORM)) + +DOCKER_IMAGE_NAME ?= mssql-exporter DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) -all: format build test +all: format build style: @echo ">> checking code style" @! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' -test: - @echo ">> running tests" - @$(GO) test -short $(pkgs) - format: @echo ">> formatting code" @$(GO) fmt $(pkgs) @@ -95,4 +99,35 @@ promu: $(GO) install github.com/prometheus/promu@$(PROMU_VERSION) endif -.PHONY: all style format build test vet tarball docker promu +.PHONY: container +container: $(BUILD_DIRS) + @echo "container: $(IMAGE):$(VERSION)" + tar -czh . | docker buildx build --platform $(PLATFORM) --load --pull -t $(IMAGE):$(VERSION) -f Dockerfile - + @echo + +push: container + @docker push $(IMAGE):$(VERSION) + @echo "pushed: $(IMAGE):$(VERSION)" + @echo + +push-%: + @$(MAKE) push \ + --no-print-directory \ + PLATFORM=$(subst _,/,$*) + +.PHONY: docker-manifest +docker-manifest: + docker manifest create -a $(IMAGE):$(TAG) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(TAG)_$(subst /,_,$(PLATFORM))) + docker manifest push $(IMAGE):$(TAG) + +all-push: $(addprefix push-, $(subst /,_,$(DOCKER_PLATFORMS))) + +.PHONY: version +version: + @echo ::set-output name=version::$(TAG) + +.PHONY: release +release: + @$(MAKE) all-push docker-manifest --no-print-directory + +.PHONY: all style format build vet tarball promu