mirror of
https://github.com/ribbybibby/ssl_exporter.git
synced 2024-11-19 20:31:51 +02:00
CI improvements
This commit is contained in:
parent
88198bf608
commit
0b960631e6
44
.github/workflows/build.yaml
vendored
44
.github/workflows/build.yaml
vendored
@ -1,44 +0,0 @@
|
||||
name: build
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: ribbybibby/ssl-exporter
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
snapshot:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v1
|
||||
with:
|
||||
go-version: 1.17.x
|
||||
- name: Build release snapshot
|
||||
run: make snapshot
|
||||
- name: Archive release snapshot
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: release-snapshot
|
||||
path: |
|
||||
bin/*.tar.gz
|
||||
bin/*.txt
|
||||
bin/*.yaml
|
9
.github/workflows/release.yaml
vendored
9
.github/workflows/release.yaml
vendored
@ -10,12 +10,21 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Unshallow
|
||||
run: git fetch --prune --unshallow
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v1
|
||||
with:
|
||||
go-version: 1.17.x
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Release with GoReleaser
|
||||
run: make release
|
||||
env:
|
||||
|
39
.github/workflows/test-and-snapshot.yaml
vendored
Normal file
39
.github/workflows/test-and-snapshot.yaml
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
name: test-and-snapshot
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v1
|
||||
with:
|
||||
go-version: 1.17.x
|
||||
|
||||
- name: Test
|
||||
run: make test
|
||||
|
||||
snapshot:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v1
|
||||
with:
|
||||
go-version: 1.17.x
|
||||
|
||||
- name: Build release snapshot
|
||||
run: make snapshot
|
||||
|
||||
- name: Archive release snapshot
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: release-snapshot
|
||||
path: |
|
||||
bin/*.tar.gz
|
||||
bin/*.txt
|
||||
bin/*.yaml
|
@ -13,12 +13,24 @@ builds:
|
||||
flags:
|
||||
- -v
|
||||
ldflags: |
|
||||
-X github.com/prometheus/common/version.Version={{.Env.APP_VERSION}}
|
||||
-X github.com/prometheus/common/version.Revision={{.Env.APP_REVISION}}
|
||||
-X github.com/prometheus/common/version.Version={{.Version}}
|
||||
-X github.com/prometheus/common/version.Revision={{.Commit}}
|
||||
-X github.com/prometheus/common/version.Branch={{.Env.APP_BRANCH}}
|
||||
-X github.com/prometheus/common/version.BuildUser={{.Env.APP_USER}}@{{.Env.APP_HOST}}
|
||||
-X github.com/prometheus/common/version.BuildDate={{.Env.APP_BUILD_DATE}}
|
||||
-X github.com/prometheus/common/version.BuildDate={{.Date}}
|
||||
release:
|
||||
github:
|
||||
owner: ribbybibby
|
||||
name: ssl_exporter
|
||||
dockers:
|
||||
- image_templates:
|
||||
- '{{.Env.APP_DOCKER_IMAGE_NAME}}:{{.Version}}'
|
||||
- '{{.Env.APP_DOCKER_IMAGE_NAME}}:latest'
|
||||
dockerfile: Dockerfile
|
||||
build_flag_templates:
|
||||
- "--pull"
|
||||
- "--label=org.opencontainers.image.created={{.Date}}"
|
||||
- "--label=org.opencontainers.image.name={{.ProjectName}}"
|
||||
- "--label=org.opencontainers.image.revision={{.Commit}}"
|
||||
- "--label=org.opencontainers.image.version={{.Version}}"
|
||||
- "--label=org.opencontainers.image.source={{.GitURL}}"
|
||||
|
20
Dockerfile
20
Dockerfile
@ -1,20 +1,16 @@
|
||||
FROM golang:1.17-buster AS build
|
||||
|
||||
ADD . /tmp/ssl_exporter
|
||||
|
||||
RUN cd /tmp/ssl_exporter && \
|
||||
echo "ssl:*:100:ssl" > group && \
|
||||
echo "ssl:*:100:100::/:/ssl_exporter" > passwd && \
|
||||
make
|
||||
FROM alpine:3.15 as build
|
||||
RUN apk --update add ca-certificates
|
||||
RUN echo "ssl:*:100:ssl" > /tmp/group && \
|
||||
echo "ssl:*:100:100::/:/ssl_exporter" > /tmp/passwd
|
||||
|
||||
|
||||
FROM scratch
|
||||
|
||||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=build /tmp/ssl_exporter/group \
|
||||
/tmp/ssl_exporter/passwd \
|
||||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
COPY --from=build /tmp/group \
|
||||
/tmp/passwd \
|
||||
/etc/
|
||||
COPY --from=build /tmp/ssl_exporter/ssl_exporter /
|
||||
COPY ssl_exporter /
|
||||
|
||||
USER ssl:ssl
|
||||
EXPOSE 9219/tcp
|
||||
|
21
Dockerfile.local
Normal file
21
Dockerfile.local
Normal file
@ -0,0 +1,21 @@
|
||||
FROM golang:1.15-buster AS build
|
||||
|
||||
ADD . /tmp/ssl_exporter
|
||||
|
||||
RUN cd /tmp/ssl_exporter && \
|
||||
echo "ssl:*:100:ssl" > group && \
|
||||
echo "ssl:*:100:100::/:/ssl_exporter" > passwd && \
|
||||
make
|
||||
|
||||
|
||||
FROM scratch
|
||||
|
||||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=build /tmp/ssl_exporter/group \
|
||||
/tmp/ssl_exporter/passwd \
|
||||
/etc/
|
||||
COPY --from=build /tmp/ssl_exporter/ssl_exporter /
|
||||
|
||||
USER ssl:ssl
|
||||
EXPOSE 9219/tcp
|
||||
ENTRYPOINT ["/ssl_exporter"]
|
18
Makefile
18
Makefile
@ -8,12 +8,10 @@ DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
|
||||
# Race detector is only supported on amd64.
|
||||
RACE := $(shell test $$(go env GOARCH) != "amd64" || (echo "-race"))
|
||||
|
||||
export APP_HOST ?= $(shell hostname)
|
||||
export APP_BRANCH ?= $(shell git describe --all --contains --dirty HEAD)
|
||||
export APP_VERSION := $(shell cat VERSION)
|
||||
export APP_REVISION := $(shell git rev-parse HEAD)
|
||||
export APP_USER := $(shell id -u --name)
|
||||
export APP_BUILD_DATE := $(shell date '+%Y%m%d-%H:%M:%S')
|
||||
export APP_HOST ?= $(shell hostname)
|
||||
export APP_BRANCH ?= $(shell git describe --all --contains --dirty HEAD)
|
||||
export APP_USER := $(shell id -u --name)
|
||||
export APP_DOCKER_IMAGE_NAME := ribbybibby/$(DOCKER_IMAGE_NAME)
|
||||
|
||||
all: clean format vet build test
|
||||
|
||||
@ -36,17 +34,17 @@ vet:
|
||||
build:
|
||||
@echo ">> building binary"
|
||||
@CGO_ENABLED=0 go build -v \
|
||||
-ldflags "-X github.com/prometheus/common/version.Version=$(APP_VERSION) \
|
||||
-X github.com/prometheus/common/version.Revision=$(APP_REVISION) \
|
||||
-ldflags "-X github.com/prometheus/common/version.Version=dev \
|
||||
-X github.com/prometheus/common/version.Revision=$(shell git rev-parse HEAD) \
|
||||
-X github.com/prometheus/common/version.Branch=$(APP_BRANCH) \
|
||||
-X github.com/prometheus/common/version.BuildUser=$(APP_USER)@$(APP_HOST) \
|
||||
-X github.com/prometheus/common/version.BuildDate=$(APP_BUILD_DATE)\
|
||||
-X github.com/prometheus/common/version.BuildDate=$(shell date '+%Y%m%d-%H:%M:%S') \
|
||||
" \
|
||||
-o $(BIN_NAME) .
|
||||
|
||||
docker:
|
||||
@echo ">> building docker image"
|
||||
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
|
||||
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" -f Dockerfile.local .
|
||||
|
||||
$(GOPATH)/bin/goreleaser:
|
||||
@go install github.com/goreleaser/goreleaser@v1.2.2
|
||||
|
Loading…
Reference in New Issue
Block a user