Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/init repo #1

Merged
merged 32 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Build and publish Docker images

on:
push:
branches:
- main
tags:
- 'v*'
release:
types: [published]


jobs:
latest:
runs-on: ubuntu-22.04
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to Github Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta for latest
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/lablabs/aws-service-quotas-exporter
tags: |
type=raw,value=latest

- name: Docker meta for tag
if: startsWith(github.ref, 'refs/tags/')
id: meta-tag
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/lablabs/aws-service-quotas-exporter
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=${{ github.ref_name }}

- name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
tag:
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to Github Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta for latest
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/lablabs/aws-service-quotas-exporter
tags: |
type=raw,value=latest

- name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
46 changes: 46 additions & 0 deletions .github/workflows/go-binary-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Generate release binary artifacts
jaygridley marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches:
- main
tags:
- 'v*'
release:
types: [published]

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v5
-
name: Run GoReleaser
if: startsWith(github.ref, 'refs/tags/')
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Run GoReleaser snapshot
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Go tests

on:
push:
pull_request:
permissions:
contents: read

env:
GO_VERSION: '1.22.0'

jobs:
build:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Test
env:
GOPROXY: "https://proxy.golang.org"
run: go test -v ./...
17 changes: 17 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Golang lint
on:
push:
pull_request:
permissions:
contents: read

jobs:
golangci:
name: Golang CI linter
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.57.1
41 changes: 41 additions & 0 deletions .github/workflows/helm-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Release Charts

on:
push:
branches:
- main

#on:
# push:
# pull_request:

env:
HELM_VERSION: 3.14.0

jobs:
release:
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions
# see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
permissions:
contents: write
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"

- name: Install Helm
uses: azure/setup-helm@v4
with:
version: ${{ env.HELM_VERSION }}

- name: Run chart-releaser
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@

# Go workspace file
go.work

.env
.envrc

.idea

coverage.out

bin/*
14 changes: 14 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
linters:
enable:
- megacheck
- gofmt
- govet
- revive

linters-settings:
staticcheck:
checks:
- '-SA5008'
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
12 changes: 12 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
builds:
- id: "exporter"
main: ./cmd/exporter
binary: exporter
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm64
mod_timestamp: "{{ .CommitTimestamp }}"
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: check-merge-conflict
- id: detect-aws-credentials
args: ['--allow-missing-credentials']
- id: detect-private-key
- id: end-of-file-fixer

- repo: https://github.com/golangci/golangci-lint
rev: v1.57.1
hooks:
- id: golangci-lint

# - repo: https://github.com/gruntwork-io/pre-commit
# rev: v0.1.17
# hooks:
# - id: helmlint
#
# - repo: https://github.com/norwoodj/helm-docs
# rev: v1.13.0
# hooks:
# - id: helm-docs
# args:
# - --chart-search-root=charts
# - id: helm-docs-built
# args:
# - --chart-search-root=charts
4 changes: 4 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
helm 3.14.2
awscli 2.7.14
pre-commit 2.20.0
golang 1.22.0
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ARG ALPINE_VERSION=3.19
FROM python:3.10-alpine${ALPINE_VERSION} as builder_aws_cli

ARG AWS_CLI_VERSION=2.15.19
RUN apk add --no-cache git unzip groff build-base libffi-dev cmake
RUN git clone --single-branch --depth 1 -b ${AWS_CLI_VERSION} https://github.com/aws/aws-cli.git

WORKDIR aws-cli
RUN ./configure --with-install-type=portable-exe --with-download-deps
RUN make
RUN make install

# reduce image size: remove autocomplete and examples
RUN rm -rf \
/usr/local/lib/aws-cli/aws_completer \
/usr/local/lib/aws-cli/awscli/data/ac.index \
/usr/local/lib/aws-cli/awscli/examples
RUN find /usr/local/lib/aws-cli/awscli/data -name completions-1*.json -delete
RUN find /usr/local/lib/aws-cli/awscli/botocore/data -name examples-1.json -delete
RUN (cd /usr/local/lib/aws-cli; for a in *.so*; do test -f /lib/$a && rm $a; done)

FROM golang:1.22-alpine${ALPINE_VERSION} as builder_golang

ARG GOOS=linux
ARG GOARCH=amd64

RUN apk --update add ca-certificates

WORKDIR $GOPATH/src/github.com/lablabs/aws-service-quotas-exporter
COPY go.mod go.sum ./
COPY . .
RUN go mod download
RUN go mod vendor
RUN go mod verify

RUN cd cmd/exporter && \
GOOS=$GOOS GOARCH=$GOARCH \
CGO_ENABLED=0 \
go build -o /aws-service-quotas-exporter .

FROM alpine:${ALPINE_VERSION}

RUN apk update && apk add jq bash

COPY --from=builder_aws_cli /usr/local/lib/aws-cli/ /usr/local/lib/aws-cli/
RUN ln -s /usr/local/lib/aws-cli/aws /usr/local/bin/aws

COPY --from=builder_golang /aws-service-quotas-exporter .

ENTRYPOINT ["/aws-service-quotas-exporter"]
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# aws-service-quotas-exporter
AWS Quotas utilisation prometheus exporter

AWS service quotas exporter exposes actual quotas for your AWS accounts and allow you to scrape actual
usage of AWS resources. Base on those two types of data, you can easily build
alert rules to prevent case when you are not able to provision another AWS resources due to reach the limit of AWS quota

## AWS Co
jaygridley marked this conversation as resolved.
Show resolved Hide resolved
Loading