Skip to content

Commit a8735d3

Browse files
authored
Merge branch 'build' into master
2 parents 075dc6d + 76a350d commit a8735d3

File tree

6 files changed

+169
-12
lines changed

6 files changed

+169
-12
lines changed

.github/dependabot.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
version: 2
2+
registries:
3+
docker-registry-quay-io:
4+
type: docker-registry
5+
url: https://quay.io
6+
username: "${{secrets.DEPENDABOT_USER}}"
7+
password: "${{secrets.DEPENDABOT_PASS}}"
28
updates:
3-
- package-ecosystem: "gomod"
4-
directory: "/"
5-
schedule:
6-
interval: "monthly"
9+
- package-ecosystem: "docker"
10+
directory: "/"
11+
schedule:
12+
interval: "daily"
13+
registries:
14+
- docker-registry-quay-io

.github/workflows/build.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Build
2+
3+
# Controls when the action will run. Triggers the workflow on push or pull request
4+
# events but only for the master branch
5+
on:
6+
push:
7+
branches: [ build ]
8+
9+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
10+
jobs:
11+
# This workflow contains a single job called "build"
12+
build:
13+
strategy:
14+
matrix:
15+
docker: ['scratch','ubi']
16+
# The type of runner that the job will run on
17+
runs-on: ubuntu-latest
18+
name: ${{ matrix.docker }}
19+
steps:
20+
- name: build
21+
uses: sysdiglabs/[email protected]
22+
with:
23+
exporter: postgresql-exporter
24+
artifactory_token: ${{ secrets.ARTI_TOKEN }}
25+
artifactory_username: [email protected]
26+
sysdig_secure_token: ${{ secrets.SYSDIG_SECURE_TOKEN }}
27+
tag_name: dev
28+
target: ${{ matrix.docker }}
29+
repository: artifactory.internal.sysdig.com

.github/workflows/push.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Push
2+
3+
# Controls when the action will run. Triggers the workflow on push or pull request
4+
# events but only for the master branch
5+
on:
6+
workflow_run:
7+
workflows: [Release]
8+
types: [completed]
9+
10+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
11+
jobs:
12+
# This workflow contains a single job called "build"
13+
on-success:
14+
# The type of runner that the job will run on
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Upload master to Quay.io
18+
uses: fjogeleit/http-request-action@master
19+
with:
20+
url: 'https://sysdig-jenkins.internal.sysdig.com/view/Integrations/job/integrations-postgresql-exporter/buildWithParameters?token=${{ secrets.JENKINS_PROMCAT_LAUNCH_TOKEN }}&EXPORTER=postgresql-exporter&DRY_RUN=false'
21+
method: 'POST'
22+
23+
password: ${{ secrets.JENKINS_PROMCAT_API_TOKEN }}

.github/workflows/release.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Release
2+
on:
3+
release:
4+
types: [released]
5+
jobs:
6+
buildDockerImage:
7+
strategy:
8+
matrix:
9+
docker: ['scratch','ubi']
10+
name: Build docker image ${{ matrix.docker }}
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Release if tagged
14+
if: "!startswith(github.ref, 'refs/tags/v')"
15+
run: exit 78
16+
- name: build
17+
uses: sysdiglabs/[email protected]
18+
with:
19+
exporter: postgresql-exporter
20+
artifactory_token: ${{ secrets.ARTI_TOKEN }}
21+
artifactory_username: [email protected]
22+
tag_name: ${{ github.event.release.tag_name }}
23+
target: ${{ matrix.docker }}
24+
repository: artifactory.internal.sysdig.com

Dockerfile

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1-
ARG ARCH="amd64"
2-
ARG OS="linux"
3-
FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest
4-
LABEL maintainer="The Prometheus Authors <[email protected]>"
1+
FROM golang:1.17.2 as base
2+
ARG VERSION
3+
ARG GIT_COMMIT
4+
ARG DATE
5+
ARG TARGETARCH
56

6-
ARG ARCH="amd64"
7-
ARG OS="linux"
8-
COPY .build/${OS}-${ARCH}/postgres_exporter /bin/postgres_exporter
7+
WORKDIR /go/src/github.com/prometheus-community/postgres_exporter
98

9+
FROM base as builder
10+
COPY go.mod go.sum ./
11+
RUN go mod download
12+
COPY cmd ./cmd
13+
COPY .promu.yml .promu.yml
14+
COPY Makefile Makefile
15+
COPY Makefile.common Makefile.common
16+
RUN make build
17+
RUN cp postgres_exporter /bin/postgres_exporter
18+
19+
FROM scratch as scratch
20+
COPY --from=builder /bin/postgres_exporter /bin/postgres_exporter
1021
EXPOSE 9187
11-
USER nobody
22+
USER 59000:59000
1223
ENTRYPOINT [ "/bin/postgres_exporter" ]
24+
25+
FROM quay.io/sysdig/sysdig-mini-ubi:1.3.1 as ubi
26+
COPY --from=builder /bin/postgres_exporter /bin/postgres_exporter
27+
EXPOSE 9187
28+
USER 59000:59000
29+
ENTRYPOINT [ "/bin/postgres_exporter" ]

build/Jenkinsfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
string projectName = "prometheus-integrations"
2+
3+
pipeline {
4+
agent none
5+
6+
7+
options {
8+
skipDefaultCheckout()
9+
}
10+
11+
environment {
12+
registryCredential = 'jenkins-artifactory'
13+
ARTIFACTORY_URL = 'docker.internal.sysdig.com'
14+
}
15+
16+
parameters {
17+
booleanParam(name: 'DRY_RUN', defaultValue: true, description: 'Perform a dry run (does not push images)')
18+
string(name: 'EXPORTER', defaultValue: "exporter", description: 'Exporter name')
19+
}
20+
21+
stages {
22+
stage('Pull image from artifactory') {
23+
agent any
24+
steps {
25+
script {
26+
docker.withRegistry("https://${env.ARTIFACTORY_URL}", registryCredential) {
27+
sh """docker pull ${env.ARTIFACTORY_URL}/${env.EXPORTER}:latest"""
28+
env.VERSION = sh(script:"""docker inspect --format '{{ index .Config.Labels "release" }}' ${env.ARTIFACTORY_URL}/${env.EXPORTER}:latest""", returnStdout: true).trim()
29+
echo "VERSION = ${env.VERSION}"
30+
sh """docker pull ${env.ARTIFACTORY_URL}/${env.EXPORTER}:${env.VERSION}"""
31+
sh """docker pull ${env.ARTIFACTORY_URL}/${env.EXPORTER}:${env.VERSION}-ubi"""
32+
}
33+
}
34+
}
35+
}
36+
stage('Push image to Quay'){
37+
agent any
38+
steps {
39+
script {
40+
if (params.DRY_RUN) {
41+
echo "docker push quay.io/sysdig/${env.EXPORTER}:${env.VERSION}"
42+
} else {
43+
docker.withRegistry("https://quay.io", "QUAY") {
44+
sh """docker tag ${env.ARTIFACTORY_URL}/${env.EXPORTER}:${env.VERSION} quay.io/sysdig/${env.EXPORTER}:${env.VERSION}"""
45+
sh """docker tag ${env.ARTIFACTORY_URL}/${env.EXPORTER}:${env.VERSION} quay.io/sysdig/${env.EXPORTER}:latest"""
46+
sh """docker tag ${env.ARTIFACTORY_URL}/${env.EXPORTER}:${env.VERSION}-ubi quay.io/sysdig/${env.EXPORTER}:${env.VERSION}-ubi"""
47+
sh """docker push quay.io/sysdig/${env.EXPORTER}:${env.VERSION}"""
48+
sh """docker push quay.io/sysdig/${env.EXPORTER}:latest"""
49+
sh """docker push quay.io/sysdig/${env.EXPORTER}:${env.VERSION}-ubi"""
50+
}
51+
}
52+
}
53+
}
54+
}
55+
} //stages
56+
}

0 commit comments

Comments
 (0)