diff --git a/.github/workflows/dockerhub-publish.yml b/.github/workflows/dockerhub-publish.yml deleted file mode 100644 index 40f82ac..0000000 --- a/.github/workflows/dockerhub-publish.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Dockerhub-Publish - -on: - create: - tags: - - v* - -jobs: - publish-docker-hub: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@master - - name: Prepare - id: prep - run: | - DOCKER_IMAGE=${{ secrets.DOCKER_IMAGE }} - VERSION=edge - if [[ $GITHUB_REF == refs/tags/* ]]; then - VERSION=${GITHUB_REF#refs/tags/} - elif [[ $GITHUB_REF == refs/heads/* ]]; then - VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') - elif [[ $GITHUB_REF == refs/pull/* ]]; then - VERSION=pr-${{ github.event.number }} - fi - TAGS="${DOCKER_IMAGE}:${VERSION}" - if [ "${{ github.event_name }}" = "push" ]; then - TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" - fi - echo ::set-output name=version::${VERSION} - echo ::set-output name=tags::${TAGS} - echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Login to DockerHub - if: github.event_name != 'pull_request' - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - file: ./Dockerfile - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.prep.outputs.tags }} - labels: | - org.opencontainers.image.source=${{ github.event.repository.html_url }} - org.opencontainers.image.created=${{ steps.prep.outputs.created }} - org.opencontainers.image.revision=${{ github.sha }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a986fec --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,74 @@ +name: Release + +on: + release: + types: [published] + +jobs: + init: + name: 🚩 Initialize + runs-on: ubuntu-latest + steps: + - name: Cancel previous workflow + uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ github.token }} + + docker: + name: 🐳 Build Docker image + runs-on: ubuntu-20.04 + needs: init + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Get repository info + uses: gacts/github-slug@v1 + id: slug + + - name: Setup QEMU + uses: docker/setup-qemu-action@v2 + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Dockerhub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_LOGIN }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Get Current Date + id: date + run: echo "::set-output name=date::$(date +'%Y-%m-%d')" + + - name: Build & Push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile + push: true + platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v6,linux/arm/v7 + build-args: | + APP_VERSION=${{ steps.slug.outputs.version }}" + DATE_CREATED=${{ steps.date.outputs.date }} + tags: | + r1cloud/cdn-exporter:${{ steps.slug.outputs.version }} + r1cloud/cdn-exporter:latest + + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + image-ref: r1cloud/cdn-exporter:latest + exit-code: "0" + ignore-unfixed: true + vuln-type: "os,library" + severity: "CRITICAL,HIGH" + format: "template" + template: "@/contrib/sarif.tpl" + output: "trivy-results.sarif" + + - name: Upload Trivy scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: "trivy-results.sarif" diff --git a/Dockerfile b/Dockerfile index de13241..18c3376 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,20 @@ COPY ./package*.json ./ RUN npm install FROM node:14-alpine AS APP + +ARG APP_VERSION="undefined@docker" + +LABEL \ + org.opencontainers.image.title="cdn-exporter" \ + org.opencontainers.image.description="Prometheus exporter for ArvanCloud CDN" \ + org.opencontainers.image.url="https://github.com/arvancloud/ar-prometheus-exporter" \ + org.opencontainers.image.source="https://github.com/arvancloud/ar-prometheus-exporter" \ + org.opencontainers.image.vendor="arvancloud" \ + org.opencontainers.image.author="arvancloud" \ + org.opencontainers.version="$APP_VERSION" \ + org.opencontainers.image.created="$DATE_CREATED" \ + org.opencontainers.image.licenses="MIT" + WORKDIR /app COPY . . COPY --from=BUILDER /app/node_modules node_modules diff --git a/README.md b/README.md index 26c74bd..6bb5d78 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,19 @@ -# ar-prometheus-exporter +# CDN Prometheus exporter ![logo](.github/logo.svg) -A very simple Prometheus exporter that exposes metrics from ArvanCloud API as described in the [documentation](https://www.arvancloud.ir/api/cdn/4.0). +A very simple Prometheus exporter that exposes metrics from ArvanCloud CDN API as described in the [documentation](https://www.arvancloud.ir/api/cdn/4.0). ## How-to You can run the exporter using Docker: ```bash -git clone git@github.com:arvancloud/ar-prometheus-exporter.git && cd ar-prometheus-exporter -docker build -t ar-prometheus-exporter . docker run -d \ -p 9786:9786 \ -e DOMAINS=example.com,example.ir \ -e API_KEY=TOKEN_HERE \ - ar-prometheus-exporter + r1cloud/cdn-exporter ``` ### Metrics @@ -46,8 +44,3 @@ The exporter exposes the following metrics, all returned per PoP: | `BASE_URL` | Arvan base URL | string | | | `METRICS_PERIOD` | Arvan report period | enum(1h, 3h, 6h, 12h, 24h, 7d, 30d) | 3h | | `METRICS_PREFIX` | exported metrics prefix | string | `arvancloud_cdn_` | - -### 👨🏻‍💻 Contributors - -- SadeghHayeri [![https://github.com/sadeghhayeri](https://img.shields.io/github/followers/sadeghhayeri?color=red&label=Follow&logo=github&style=flat-square)](https://github.com/sadeghhayeri) -- Yazdan [![https://github.com/yzdann](https://img.shields.io/github/followers/yzdann?color=red&label=Follow&logo=github&style=flat-square)](https://github.com/yzdann) diff --git a/docker-compose.yml b/docker-compose.yml index f94dc8a..3eccf6b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,10 @@ -version: '3.2' -service: - ar-exporter: - build: - context: . - dockerfile: ./dockerfile - targer: app - container_name: ar-exporter +version: "3.9" + +services: + cdn-exporter: + image: r1cloud/cdn-exporter ports: - - 9786:9786 + - 9786:9786 environment: - DOMAINS: example.com - API_KEY: arvan-api-key - network_mode: "bridge" \ No newline at end of file + DOMAINS: example.com + API_KEY: arvan-api-key