Skip to content

Add manifests to deploy Metricly on top of OpenShift #64

Add manifests to deploy Metricly on top of OpenShift

Add manifests to deploy Metricly on top of OpenShift #64

Workflow file for this run

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: build-metricly
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23.3'
# Install dependencies
- name: Install dependencies
run: go mod tidy
# Run static analysis and linters
- name: Run linters
run: |
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint run
# Run tests
- name: Run tests
run: go test ./... -v -coverprofile=coverage.out
# Upload test coverage
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.out
docker-build-test:
name: Build and test container Image
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build and run container
run: |
pip3 install podman-compose
docker compose up -d --build
sleep 60
docker ps -a
# health_status=$(sudo docker inspect --format '{{.State.Health.Status}}' metricly_metricly)
# if [[ "$health_status" != "healthy" ]]; then
# sudo podman inspect metricly_metricly
# echo "Error: The container is not healthy. Exiting."
# # exit 1 # Fail the script if the container is not healthy
# fi
# Verify metrics are exposed
- name: Verify metrics endpoint
run: |
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8080/api/v1/metrics)
if [ "$RESPONSE" -ne 200 ]; then
echo "Metrics endpoint not reachable"
exit 1
fi
echo "Metrics endpoint is reachable and returned HTTP $RESPONSE"
# Optional - Inspect metrics content
- name: Fetch and log metrics
run: |
RESPONSE=$(curl -s http://127.0.0.1:8080/api/v1/metrics)
if echo "$RESPONSE" | grep -q "metricly_cpu_total"; then
echo "metricly_cpu_total found!"
else
echo "metricly_cpu_total not found!" && exit 1
fi
if echo "$RESPONSE" | grep -q "metricly_memory_total_bytes"; then
echo "metricly_memory_total_bytes Metrics found!"
else
echo "metricly_memory_total_bytes not found!" && exit 1
fi
if echo "$RESPONSE" | grep -q "metricly_disk_usage_percentage"; then
echo "metricly_disk_usage_percentage Metrics found!"
else
echo "metricly_disk_usage_percentage not found!" && exit 1
fi
if echo "$RESPONSE" | grep -q "metricly_network_rx_bytes"; then
echo "metricly_network_rx_bytes Metrics found!"
else
echo "metricly_network_rx_bytes not found!" && exit 1
fi
# Verify /query api
- name: Test /api/v1/query
run: |
time=$(($(date +%s) - 10))
RESPONSE=$(curl -s "http://127.0.0.1:8080/api/v1/query?metric=metricly_cpu_total&time=$time")
if [[ $(echo "$RESPONSE" | jq '.data.result[0].value|length') -ne 2 ]]; then
echo "Didn't get any data point"
echo $RESPONSE
exit 1
fi
# Verify /query_range api
- name: Test /api/v1/query_range
run: |
start=$(($(date +%s) - 100))
end=$(date +%s)
RESPONSE=$(curl -s "http://127.0.0.1:8080/api/v1/query_range?metric=metricly_cpu_total&start=$start&end=$end&step=15s")
if [[ $(echo "$RESPONSE" | jq '.data.result[0].values|length') -le 1 ]]; then
echo "Didn't multiple data points"
echo $RESPONSE
exit 1
fi
RESPONSE=$(curl -s "http://127.0.0.1:8080/api/v1/query_range?metric=metricly_cpu_total&last=2m&step=15s")
if [[ $(echo "$RESPONSE" | jq '.data.result[0].values|length') -le 1 ]]; then
echo "Didn't multiple data points"
echo $RESPONSE
exit 1
fi
# Verify /aggregate api
- name: Test /api/v1/aggregate
run: |
RESPONSE=$(curl -s "http://127.0.0.1:8080/api/v1/aggregate?metric=metricly_cpu_total&operation=avg&window=1m")
if [[ $(echo "$RESPONSE" | jq '.data.result[0].value|length') -ne 2 ]]; then
echo "Didn't multiple data points"
echo $RESPONSE
exit 1
fi
# Step 6: Stop and remove the container
- name: Clean up container
run: make run_compose_down
docker-build-push:
name: Push Metricly to Quay.io
runs-on: ubuntu-latest
needs: docker-build-test
if: github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Quay.io
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: quay.io/yadneshk/metricly:latest