Skip to content

Add HTTP tls (issue #393) #988

Add HTTP tls (issue #393)

Add HTTP tls (issue #393) #988

Workflow file for this run

name: Go application CI/CD
on:
push:
branches:
- master
- v1
tags:
- "*"
pull_request:
branches:
- master
- v1
env:
TAG_NAME: "${GITHUB_REF##*/}"
jobs:
lint:
name: Lint code
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Lint code using golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
- name: Check go mod tidy
run: |
go mod tidy
git diff --exit-code -- go.mod go.sum
lint-scripts:
name: Lint scripts
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run ShellCheck
uses: ludeeus/[email protected]
test:
name: Unit test code
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Test code
run: go test ./... -covermode=atomic -coverprofile=coverage.out
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
verify-helm-readme:
name: Verify that Helm README is up to date
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Node 18
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install README generator
run: make install-helm-readme
- name: Generate README
run: make helm-readme
- name: Verify that there are no changes
run: git diff --exit-code || (echo "README.md is not up to date. Please use helm-readme and commit the changes." && exit 1)
verify-makefile-readme:
name: Verify that Makefile section of README is up to date
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Generate README
run: make update-readme-descriptions
- name: Verify that there are no changes
run: git diff --exit-code || (echo "README.md is not up to date. Please use update-readme-descriptions and commit the changes." && exit 1)
lint-helm-chart:
name: Lint Helm chart
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Helm
uses: azure/setup-helm@v4
with:
version: 3.13.3
- name: Lint Helm chart
working-directory: ./chart
run: helm lint .
template-helm-chart:
name: Verify templating chart with default values
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Helm
uses: azure/setup-helm@v4
with:
version: 3.11.2
- name: Template Helm chart
working-directory: ./chart
run: helm template . > /dev/null
test-integration:
name: Test integration with Prometheus
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Compose
uses: ndeloof/[email protected]
with:
version: v2.15.1
legacy: true
- name: Print compose version
run: docker-compose version
- name: Wait for compose
run: make wait-for-compose
- name: Print compose logs if failed
run: docker-compose logs
if: failure()
- name: Print exporter logs if failed
run: docker-compose logs exporter
if: failure()
- name: Run metrics integration test
run: make verify-metrics
- name: Generate metric names for README
run: ./scripts/add_metrics_to_readme.sh
- name: Verify that there are no changes
run: git diff --exit-code || echo "README.md is not up to date. Please use add_metrics_to_readme.sh and commit the changes."
- name: Shutdown compose
run: docker-compose down -v
build-linux:
name: Build Linux binary
runs-on: ubuntu-20.04
needs: [lint, test]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Build Linux binary
run: make build-linux
env:
VERSION: ${{ github.ref }}
- name: Upload Linux binary
uses: actions/upload-artifact@v4
with:
name: logstash-exporter-linux
path: out/main-linux
build-linux-arm:
name: Build Linux ARM binary
runs-on: ubuntu-20.04
needs: [lint, test]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Build Linux ARM binary
run: make build-linux-arm
env:
VERSION: ${{ github.ref }}
- name: Upload Linux ARM binary
uses: actions/upload-artifact@v4
with:
name: logstash-exporter-linux-arm
path: out/main-linux-arm
build-darwin:
name: Build Mac binary
runs-on: ubuntu-20.04
needs: [lint, test]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Build Mac binary
run: make build-darwin
env:
VERSION: ${{ github.ref }}
- name: Upload Mac binary
uses: actions/upload-artifact@v4
with:
name: logstash-exporter-darwin
path: out/main-darwin
build-windows:
name: Build Windows binary
runs-on: ubuntu-20.04
needs: [lint, test]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Build Windows binary
run: make build-windows
env:
VERSION: ${{ github.ref }}
- name: Upload Windows binary
uses: actions/upload-artifact@v4
with:
name: logstash-exporter-windows
path: out/main-windows
build-linux-docker-image:
name: Build Linux Docker image
runs-on: ubuntu-20.04
needs: [build-linux]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build Docker image
run: make build-docker
- name: Package Docker image
run: docker save logstash-exporter:latest | gzip > logstash-exporter.tar.gz
- name: Upload Docker image as an artifact
uses: actions/upload-artifact@v4
with:
name: logstash-exporter-docker-image
path: logstash-exporter.tar.gz
retention-days: 1
- name: Login to GitHub registry
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master'
run: echo ${{ secrets.GH_PAT }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
- name: Login to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ secrets.DOCKER_HUB_PAT }} | docker login -u ${{ github.repository_owner }} --password-stdin
- name: Tag Docker image with master
if: github.ref == 'refs/heads/master'
run: docker tag logstash-exporter:latest ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:master
- name: Tag Docker image with tag to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: docker tag logstash-exporter:latest ${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
- name: Tag Docker image with tag to ghcr.io
if: startsWith(github.ref, 'refs/tags/')
run: docker tag logstash-exporter:latest ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
- name: Push Docker image to GitHub registry
if: github.ref == 'refs/heads/master'
run: docker push ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:master
- name: Push Docker image with tag to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: docker push ${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
- name: Push Docker image with tag to ghcr.io
if: startsWith(github.ref, 'refs/tags/')
run: docker push ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
build-docker-linux-arm-image:
name: Build Linux ARM Docker image
runs-on: ubuntu-20.04
needs: [build-linux]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ secrets.DOCKER_HUB_PAT }} | docker login -u ${{ github.repository_owner }} --password-stdin
- name: Build Docker image
run: "VERSION=${{ env.TAG_NAME }} DOCKER_IMG=${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }} make build-docker-multi"
test-helm-integration:
name: Test integration with Helm chart
runs-on: ubuntu-20.04
needs:
- verify-helm-readme
- lint-helm-chart
- template-helm-chart
- build-linux-docker-image
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Docker image
uses: actions/download-artifact@v4
with:
name: logstash-exporter-docker-image
path: .helm/files
- name: Load Docker image
run: docker load -i .helm/files/logstash-exporter.tar.gz
- name: Install Helm
uses: azure/setup-helm@v4
with:
version: 3.13.3
- name: Include current chart versions
working-directory: .helm/logstash-integration-test-chart
run: helm dependency update
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
cluster_name: kind-chart-testing
- name: Export Docker image to Kind cluster
run: kind load docker-image logstash-exporter:latest --name kind-chart-testing
- name: Template Helm chart
working-directory: .helm/logstash-integration-test-chart
run: helm template .
- name: Install Helm chart
working-directory: .helm/logstash-integration-test-chart
run: helm install --wait --timeout 10m --debug logstash-integration-test-chart .
- name: Print exporter logs
run: kubectl logs -n default -l app=logstash-exporter
if: failure()
create-release:
name: Create GitHub release
runs-on: ubuntu-20.04
permissions:
contents: write
packages: write
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
release_id: ${{ steps.create_release.outputs.id }}
needs:
- build-linux
- build-darwin
- build-windows
- build-linux-arm
- build-linux-docker-image
- build-docker-linux-arm-image
- test-integration
- lint-scripts
- verify-makefile-readme
- test-helm-integration
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Output tag information
run: |
echo "Tag name: ${{ env.TAG_NAME }}"
echo "Tag ref: ${{ github.ref }}"
- name: Generate release notes
run: ./scripts/create_release_notes.sh
- name: Determine if prerelease
id: prerelease
run: |
# if tag name does not start with v, or when the tag name contains -suffix, then it is a prerelease
if [[ "${{ env.TAG_NAME }}" =~ ^v.*$ ]] && [[ "${{ env.TAG_NAME }}" =~ -.*$ ]]; then
echo "::set-output name=is_prerelease::true"
else
echo "::set-output name=is_prerelease::false"
fi
- name: Create GitHub release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body_path: "./release_notes.txt"
draft: false
prerelease: ${{ steps.prerelease.outputs.is_prerelease }}
upload-binaries:
strategy:
matrix:
binary: [linux, darwin, windows, linux-arm]
runs-on: ubuntu-20.04
needs:
- create-release
- build-linux
- build-darwin
- build-windows
- build-linux-arm
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download binary
uses: actions/download-artifact@v4
with:
name: logstash-exporter-${{ matrix.binary }}
- name: Generate sha256 checksum
run: |
CHECKSUM_FILE="main-${{ matrix.binary }}.sha256"
sha256sum main-${{ matrix.binary }} | cut -d ' ' -f1 | tr -d $'\n' > "$CHECKSUM_FILE"
echo -n ' logstash-exporter-${{ matrix.binary }}' >> "$CHECKSUM_FILE"
- name: Upload binary to GitHub release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: main-${{ matrix.binary }}
asset_name: logstash-exporter-${{ matrix.binary }}
asset_content_type: application/octet-stream
- name: Upload sha256 checksum to GitHub release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: main-${{ matrix.binary }}.sha256
asset_name: logstash-exporter-${{ matrix.binary }}.sha256
asset_content_type: text/plain