Skip to content

Commit

Permalink
Update Docker build (#1569)
Browse files Browse the repository at this point in the history
Signed-off-by: SuperQ <[email protected]>
  • Loading branch information
SuperQ authored Nov 20, 2024
1 parent 3d12bc9 commit 7c30771
Show file tree
Hide file tree
Showing 23 changed files with 599 additions and 581 deletions.
33 changes: 14 additions & 19 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 10
groups:
aws-sdk-v2:
patterns:
- "github.com/aws/aws-sdk-go-v2*"
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 10
- package-ecosystem: docker
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 10
- package-ecosystem: gomod
directory: /
schedule:
interval: monthly
open-pull-requests-limit: 10
groups:
aws-sdk-v2:
patterns:
- "github.com/aws/aws-sdk-go-v2*"
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
open-pull-requests-limit: 10
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Go

on:
pull_request:
workflow_call:

jobs:
build:
name: Build
runs-on: ubuntu-latest
container:
image: quay.io/prometheus/golang-builder:1.23-base
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- uses: prometheus/promci@52c7012f5f0070d7281b8db4a119e21341d43c91 # v0.4.5
- uses: ./.github/promci/actions/setup_environment
- run: make
- run: git diff --exit-code

verify-example-configs:
name: verify
runs-on: ubuntu-latest
container:
image: quay.io/prometheus/golang-builder:1.23-base
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- run: make build
- name: Verify example configs
run: find ./examples -name "*.yml" -print0 | xargs -0 -I % ./yace verify-config -config.file %
61 changes: 0 additions & 61 deletions .github/workflows/go.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# This action is synced from https://github.com/prometheus/prometheus
name: golangci-lint
on:
push:
paths:
- "go.sum"
- "go.mod"
- "**.go"
- "scripts/errcheck_excludes.txt"
- ".github/workflows/golangci-lint.yml"
- ".golangci.yml"
pull_request:

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
golangci:
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Go
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
with:
go-version: 1.23.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
with:
args: --verbose
version: v1.61.0
15 changes: 11 additions & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ on: push
name: Build and test
jobs:
buildDockerImage:
name: Build docker image
name: Publish master branch artifacts
runs-on: ubuntu-latest
needs: [build, verify]
if: github.event_name == 'push' && github.event.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
- name: Build docker image
run: docker build -t yace --build-arg VERSION=${{github.event.release.tag_name}} .
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: prometheus/promci@52c7012f5f0070d7281b8db4a119e21341d43c91 # v0.4.5
- uses: ./.github/promci/actions/publish_master
with:
docker_hub_login: ${{ secrets.docker_hub_login }}
docker_hub_password: ${{ secrets.docker_hub_password }}
quay_io_login: ${{ secrets.quay_io_login }}
quay_io_password: ${{ secrets.quay_io_password }}
47 changes: 16 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,24 @@ name: Publish Docker image and binaries
on:
push:
tags:
- 'v*'
- 'v*'

jobs:
buildDockerImage:
if: github.repository == 'nerdswords/yet-another-cloudwatch-exporter'
name: Build docker image
name: Publish release artefacts
runs-on: ubuntu-latest
needs: [build, verify]
if: |
(*github.repository == 'prometheus-community/yet-another-cloudwatch-exporter')
&&
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v.'))
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: ^1.23

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

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

- name: Log into docker
env:
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
DOCKER_REGISTRY_URL: ghcr.io
DOCKER_USERNAME: ${{ github.actor }}
run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL

- name: Build and Publish docker image
run: docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t ghcr.io/nerdswords/yet-another-cloudwatch-exporter:${{github.ref_name}} --build-arg VERSION=${{github.ref_name}} --push .

- name: Build && release binaries
uses: goreleaser/goreleaser-action@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: release --clean
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: prometheus/promci@52c7012f5f0070d7281b8db4a119e21341d43c91 # v0.4.5
- uses: ./.github/promci/actions/publish_release
with:
docker_hub_login: ${{ secrets.docker_hub_login }}
docker_hub_password: ${{ secrets.docker_hub_password }}
quay_io_login: ${{ secrets.quay_io_login }}
quay_io_password: ${{ secrets.quay_io_password }}
github_token: ${{ secrets.PROMBOT_GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.build
yet-another-cloudwatch-exporter
!charts/yet-another-cloudwatch-exporter
vendor
dist
/yace
.idea
*.tar.gz
25 changes: 25 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
extends: default
ignore: |
**/node_modules

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
commas: disable
comments: disable
comments-indentation: disable
document-start: disable
indentation:
spaces: consistent
indent-sequences: consistent
key-duplicates:
ignore: |
config/testdata/section_key_dup.bad.yml
line-length: disable
truthy:
check-keys: false
38 changes: 12 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
FROM golang:1.23 as builder
ARG ARCH="amd64"
ARG OS="linux"
FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest
LABEL maintainer="The Prometheus Authors <[email protected]>"

WORKDIR /opt/
ARG ARCH="amd64"
ARG OS="linux"
COPY .build/${OS}-${ARCH}/yace /bin/yace

COPY go.mod go.sum ./
RUN go mod download
COPY examples/ec2.yml /etc/yace/config.yml

COPY . ./

ENV GOOS linux
ENV CGO_ENABLED=0

ARG VERSION
RUN go build -v -ldflags "-X main.version=$VERSION" -o yace ./cmd/yace

FROM alpine:3.20.3

EXPOSE 5000
ENTRYPOINT ["yace"]
CMD ["--config.file=/tmp/config.yml"]
RUN addgroup -g 1000 exporter && \
adduser -u 1000 -D -G exporter exporter -h /exporter

WORKDIR /exporter/


RUN apk --no-cache add ca-certificates
COPY --from=builder /opt/yace /usr/local/bin/yace
USER exporter
EXPOSE 5000
USER nobody
ENTRYPOINT [ "/bin/yace" ]
CMD [ "--config.file=/etc/yace/config.yml" ]
6 changes: 3 additions & 3 deletions docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.8'
networks:
monitoring:
driver: bridge

volumes:
prometheus_data: {}

Expand Down Expand Up @@ -43,14 +43,14 @@ services:
- monitoring

yace:
build:
build:
context: ../
dockerfile: Dockerfile
restart: always
environment:
AWS_REGION: ${AWS_REGION}
AWS_PROFILE: ${AWS_PROFILE}
expose:
expose:
- 8080
volumes:
- ./yace-config.yaml:/tmp/config.yml
Expand Down
12 changes: 6 additions & 6 deletions docker-compose/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
global:
scrape_interval: 1m

scrape_configs:
- job_name: "prometheus"
- job_name: prometheus
scrape_interval: 1m
static_configs:
- targets: ["localhost:9090"]

- job_name: "yace"
- targets:
- localhost:9090
- job_name: yace
static_configs:
- targets: ["yace:8080"]
- targets:
- yace:8080
Loading

0 comments on commit 7c30771

Please sign in to comment.