Skip to content

Commit

Permalink
fix the examples to point at the oss repository (#192)
Browse files Browse the repository at this point in the history
* fix the examples to point at the OSS unbuntu image
* fixed nfpm reference to follow the convention we use
* mounted the conf files into compose
* updated vendoring
---------

Co-authored-by: o.omahony <[email protected]>
  • Loading branch information
oliveromahony and o.omahony authored Feb 15, 2023
1 parent 7a76bce commit 24a158b
Show file tree
Hide file tree
Showing 1,470 changed files with 140,495 additions and 28,513 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ jobs:
retention-days: 3


build-example:
name: Build Grafana Dashboard Example
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- name: Setup build environment
run: |
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }}
- name: Build Grafana example
run: make build-grafana-example
- name: Clean Grafana example
run: make clean-grafana-example

trigger-release-workflow:
if: ${{ startsWith(github.ref_name, 'release-') && !github.event.pull_request.head.repo.fork }}
needs: [ lint, unit-test, component-test, performance-test ]
Expand Down
45 changes: 31 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ CERTS_DIR := ./build/certs
PACKAGE_PREFIX := nginx-agent
PACKAGES_REPO := "pkgs.nginx.com"
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
OSARCH := $(shell uname -m)
# override this value if you want to change the architecture. GOOS options here: https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63
uname_m := $(shell uname -m)
ifeq ($(uname_m),aarch64)
OSARCH = arm64
else
ifeq ($(uname_m),x86_64)
OSARCH = amd64
else
OSARCH = $(uname_m)
endif
endif

TEST_BUILD_DIR := build/test
PACKAGE_NAME := "${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-SNAPSHOT-${COMMIT}"
# override this value if you want to change the architecture. GOOS options here: https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63
LOCAL_ARCH := amd64

CERT_CLIENT_CA_CN := client-ca.local
CERT_CLIENT_INT_CN := client-int.local
Expand Down Expand Up @@ -112,19 +121,19 @@ launch-swagger-ui: generate-swagger ## Launch Swagger UI
# Local Packaging #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
local-apk-package: ## Create local apk package
GOWORK=off CGO_ENABLED=0 GOARCH=${LOCAL_ARCH} GOOS=linux go build -ldflags=${DEBUG_LDFLAGS} -o ./build/nginx-agent
ARCH=${LOCAL_ARCH} VERSION=$(shell echo ${VERSION} | tr -d 'v') nfpm pkg --config ./scripts/.local-nfpm.yaml --packager apk --target ./build/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-SNAPSHOT-${COMMIT}.apk;
GOWORK=off CGO_ENABLED=0 GOARCH=${OSARCH} GOOS=linux go build -ldflags=${DEBUG_LDFLAGS} -o ./build/nginx-agent
ARCH=${OSARCH} VERSION=$(shell echo ${VERSION} | tr -d 'v') go run github.com/goreleaser/nfpm/v2/cmd/nfpm pkg --config ./scripts/.local-nfpm.yaml --packager apk --target ./build/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-SNAPSHOT-${COMMIT}.apk;

local-deb-package: ## Create local deb package
GOWORK=off CGO_ENABLED=0 GOARCH=${LOCAL_ARCH} GOOS=linux go build -ldflags=${DEBUG_LDFLAGS} -o ./build/nginx-agent
ARCH=${LOCAL_ARCH} VERSION=$(shell echo ${VERSION} | tr -d 'v') nfpm pkg --config ./scripts/.local-nfpm.yaml --packager deb --target ./build/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-SNAPSHOT-${COMMIT}.deb;
GOWORK=off CGO_ENABLED=0 GOARCH=${OSARCH} GOOS=linux go build -ldflags=${DEBUG_LDFLAGS} -o ./build/nginx-agent
ARCH=${OSARCH} VERSION=$(shell echo ${VERSION} | tr -d 'v') go run github.com/goreleaser/nfpm/v2/cmd/nfpm pkg --config ./scripts/.local-nfpm.yaml --packager deb --target ./build/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-SNAPSHOT-${COMMIT}.deb;

local-rpm-package: ## Create local rpm package
GOWORK=off CGO_ENABLED=0 GOARCH=${LOCAL_ARCH} GOOS=linux go build -ldflags=${DEBUG_LDFLAGS} -o ./build/nginx-agent
ARCH=${LOCAL_ARCH} VERSION=$(shell echo ${VERSION} | tr -d 'v') nfpm pkg --config ./scripts/.local-nfpm.yaml --packager rpm --target ./build/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-SNAPSHOT-${COMMIT}.rpm;
GOWORK=off CGO_ENABLED=0 GOARCH=${OSARCH} GOOS=linux go build -ldflags=${DEBUG_LDFLAGS} -o ./build/nginx-agent
ARCH=${OSARCH} VERSION=$(shell echo ${VERSION} | tr -d 'v') go run github.com/goreleaser/nfpm/v2/cmd/nfpm pkg --config ./scripts/.local-nfpm.yaml --packager rpm --target ./build/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-SNAPSHOT-${COMMIT}.rpm;

local-txz-package: ## Create local txz package
GOWORK=off CGO_ENABLED=0 GOARCH=${LOCAL_ARCH} GOOS=freebsd go build -ldflags=${DEBUG_LDFLAGS} -o ./build/nginx-agent
GOWORK=off CGO_ENABLED=0 GOARCH=${OSARCH} GOOS=freebsd go build -ldflags=${DEBUG_LDFLAGS} -o ./build/nginx-agent
$(CONTAINER_CLITOOL) run -v ${PWD}:/nginx-agent/$(CONTAINER_VOLUME_FLAGS) build-local-packager:1.0.0

txz-packager-image: ## Builds txz packager container image
Expand All @@ -139,7 +148,7 @@ include Makefile.packaging
generate-mocks: ## Regenerate all needed mocks, in order to add new mocks generation add //go:generate mockgen to file from witch mocks should be generated
GOWORK=off go generate ./...

test: unit-test performance-test component-test ## Run all tests
test: unit-test performance-test component-test integration-test ## Run all tests

$(TEST_BUILD_DIR):
mkdir -p $(TEST_BUILD_DIR)
Expand Down Expand Up @@ -180,8 +189,8 @@ performance-test: ## Run performance tests
$(CONTAINER_CLITOOL) run -v ${PWD}:/home/nginx/$(CONTAINER_VOLUME_FLAGS) --rm nginx-agent-benchmark:1.0.0

integration-test: local-deb-package
PACKAGE_NAME=${PACKAGE_NAME} BASE_IMAGE=${BASE_IMAGE} go test ./test/integration/install
PACKAGE_NAME=${PACKAGE_NAME} BASE_IMAGE=${BASE_IMAGE} go test ./test/integration/api
PACKAGE_NAME=${PACKAGE_NAME} BASE_IMAGE=${BASE_IMAGE} go test -v ./test/integration/install
PACKAGE_NAME=${PACKAGE_NAME} BASE_IMAGE=${BASE_IMAGE} go test -v ./test/integration/api

test-bench: ## Run benchmark tests
cd test/performance && GOWORK=off CGO_ENABLED=0 go test -mod=vendor -count 5 -timeout 2m -bench=. -benchmem metrics_test.go
Expand Down Expand Up @@ -244,5 +253,13 @@ run-container: ## Run container from specified IMAGE_TAG
$(CONTAINER_CLITOOL) run ${IMAGE_TAG}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Dashboard Targets #
# Grafana Example Dashboard Targets #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
clean-grafana-example: clean ## Clean example packages and docker
cd ./examples/grafana-metrics/ && BASE_IMAGE= PACKAGE_NAME= ${CONTAINER_COMPOSE} down

build-grafana-example: local-deb-package ## Build the example of nginx-agent
cd ./examples/grafana-metrics/ && BASE_IMAGE=${BASE_IMAGE} PACKAGE_NAME=${PACKAGE_NAME} ${CONTAINER_COMPOSE} build

run-grafana-example: ## Start the example of nginx-agent
cd ./examples/grafana-metrics/ && BASE_IMAGE=${BASE_IMAGE} PACKAGE_NAME=${PACKAGE_NAME} ${CONTAINER_COMPOSE} up
44 changes: 0 additions & 44 deletions examples/grafana-metrics/Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions examples/grafana-metrics/Makefile

This file was deleted.

14 changes: 7 additions & 7 deletions examples/grafana-metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ This README will give instructions on how to run the demonstration on how the NG

<br>

## Run Example
Run the following command to start up the agent grafana metrics example. This will create all the servies listed in [List of Services](#list-of-services).
## Run Grafana Example
Run the following command from the root directory, to start up the agent grafana metrics example. This will create all the services listed in [List of Services](#list-of-services).
```
make clean build run
make clean-grafana-example build-grafana-example run-grafana-example
```
<br>

Expand All @@ -16,7 +16,7 @@ The services run by this example are listed below
|-------------|-------|
| Grafana | 3000 |
| NGINX | 8080 |
| Grafana | 8081 |
| AGENT API | 8081 |
| Prometheus | 9090 |

<br>
Expand All @@ -42,7 +42,7 @@ If you monitor the dashboard you'll see the graphs being populated.

## Teardown Example

Run the following command in the grafana directory to shut down example services.
Run the following command from the root directory to shut down example services.
```
make clean-grafana-example
```
make clean
```
15 changes: 12 additions & 3 deletions examples/grafana-metrics/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ volumes:

services:
agent:
build: ./
image: nginx/agent-example
container_name: agent
restart: unless-stopped
build:
context: ../../
dockerfile: ./scripts/docker/nginx-oss/ubuntu/Dockerfile
args:
PACKAGE_NAME: ${PACKAGE_NAME}
BASE_IMAGE: ${BASE_IMAGE}
ENTRY_POINT: "./scripts/docker/nginx-oss/entrypoint.sh"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./nginx-agent.conf:/etc/nginx-agent/nginx-agent.conf
ports:
- 8080:8080
- 8081:8081
Expand All @@ -36,6 +44,7 @@ services:
- monitoring
grafana:
image: grafana/grafana-oss:latest
restart: unless-stopped
volumes:
- ./grafana-datasources.yml:/etc/grafana/provisioning/datasources/grafana-datasources.yml
- ./grafana-dashboards.yml:/etc/grafana/provisioning/dashboards/grafana-dashboards.yml
Expand Down
49 changes: 0 additions & 49 deletions examples/grafana-metrics/entrypoint.sh

This file was deleted.

23 changes: 5 additions & 18 deletions examples/grafana-metrics/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

error_log /var/log/nginx/error.log;

events {
worker_connections 1024;
Expand All @@ -23,27 +18,19 @@ http {
'"$http_user_agent" "$http_x_forwarded_for" '
'"$bytes_sent" "$request_length" "$request_time" '
'"$gzip_ratio" $server_protocol ';

access_log /usr/local/nginx/logs/access.log main;
access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 8080;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /usr/local/nginx/html;
root /usr/share/nginx/html;
index index.html index.htm;
allow 127.0.0.1;
}
Expand All @@ -67,7 +54,7 @@ http {
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/nginx/html;
root /usr/share/nginx/html;
}
}
}
Loading

0 comments on commit 24a158b

Please sign in to comment.