Skip to content

Commit 3aa5e0c

Browse files
committed
Add new way to build the images
1 parent be22c16 commit 3aa5e0c

File tree

8 files changed

+136
-133
lines changed

8 files changed

+136
-133
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

-33
This file was deleted.

.github/ISSUE_TEMPLATE/config.yml

-1
This file was deleted.

.github/ISSUE_TEMPLATE/question.md

-29
This file was deleted.

.github/workflows/codeql-analysis.yml

-52
This file was deleted.

.github/workflows/image-builder-workflow.yaml

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: buildandDeploy
1+
name: Build and scan
22

33
# Controls when the action will run. Triggers the workflow on push or pull request
44
# events but only for the master branch
@@ -11,7 +11,8 @@ jobs:
1111
# This workflow contains a single job called "build"
1212
build:
1313
env:
14-
VERSION: "v1.24.0"
14+
VERSION: latest
15+
EXPORTER_NAME: redis-exporter
1516
# The type of runner that the job will run on
1617
runs-on: ubuntu-latest
1718
steps:
@@ -27,15 +28,27 @@ jobs:
2728
registry: artifactory.internal.sysdig.com
2829
2930
password: ${{ secrets.ARTI_TOKEN }}
30-
- name: Build docker image
31+
- name: Increase version and build
3132
run: |
32-
docker build -f ./docker/Dockerfile.amd64 -t temp-redis-exporter:latest .
33-
33+
docker pull artifactory.internal.sysdig.com/$EXPORTER_NAME:$VERSION
34+
export RELEASE=$(docker inspect --format '{{ index .Config.Labels "release" }}' artifactory.internal.sysdig.com/$EXPORTER_NAME:$VERSION)
35+
docker build --label release=$RELEASE -f ./docker/Dockerfile -t $EXPORTER_NAME:$VERSION --target scratch .
36+
docker build --label version=$RELEASE -f ./docker/Dockerfile -t $EXPORTER_NAME:$VERSION-ubi --target ubi .
37+
3438
- name: Scan local image
3539
id: scan-local
3640
uses: sysdiglabs/scan-action@v3
3741
with:
38-
image-tag: "temp-redis-exporter:latest"
42+
image-tag: "redis-exporter:latest"
43+
sysdig-secure-token: ${{ secrets.SYSDIG_SECURE_TOKEN }}
44+
ignore-failed-scan: true
45+
input-type: docker-daemon
46+
run-as-user: root
47+
- name: Scan local image 2
48+
id: scan-local2
49+
uses: sysdiglabs/scan-action@v3
50+
with:
51+
image-tag: "redis-exporter:latest-ubi"
3952
sysdig-secure-token: ${{ secrets.SYSDIG_SECURE_TOKEN }}
4053
ignore-failed-scan: true
4154
input-type: docker-daemon
@@ -49,8 +62,18 @@ jobs:
4962

5063
- name: Change the tag of the image
5164
run: |
52-
docker tag temp-redis-exporter:latest artifactory.internal.sysdig.com/redis-exporter:$VERSION
65+
docker tag $EXPORTER_NAME:$VERSION artifactory.internal.sysdig.com/$EXPORTER_NAME:$VERSION
66+
docker tag $EXPORTER_NAME:$VERSION-ubi artifactory.internal.sysdig.com/$EXPORTER_NAME:$VERSION-ubi
5367
5468
- name: Push the image
5569
run: |
56-
docker push artifactory.internal.sysdig.com/redis-exporter:$VERSION
70+
docker push artifactory.internal.sysdig.com/$EXPORTER_NAME:$VERSION
71+
docker push artifactory.internal.sysdig.com/$EXPORTER_NAME:$VERSION-ubi
72+
73+
- name: Fake Upload master to Quay.io
74+
uses: fjogeleit/http-request-action@master
75+
with:
76+
url: 'https://sysdig-jenkins.internal.sysdig.com/view/Integrations/job/integrations-redis-exporter/buildWithParameters?token=${{ secrets.JENKINS_PROMCAT_LAUNCH_TOKEN }}&EXPORTER=redis-exporter&DRY_RUN=true'
77+
method: 'POST'
78+
79+
password: ${{ secrets.JENKINS_PROMCAT_API_TOKEN }}

.github/workflows/release.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
on:
2+
release:
3+
types: [released]
4+
name: Build, test and publish
5+
jobs:
6+
buildDockerImage:
7+
env:
8+
EXPORTER_NAME: redis-exporter
9+
name: Build docker image
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@master
13+
- name: Login to Artifactory
14+
uses: docker/login-action@v1
15+
with:
16+
registry: artifactory.internal.sysdig.com
17+
18+
password: ${{ secrets.ARTI_TOKEN }}
19+
- name: Release if tagged
20+
if: "!startswith(github.ref, 'refs/tags/v')"
21+
run: exit 78
22+
- name: Build image
23+
run: |
24+
docker build --label release=${{ github.event.release.tag_name }} -f ./docker/Dockerfile --target scratch -t artifactory.internal.sysdig.com/$EXPORTER_NAME:latest .
25+
docker build --label release=${{ github.event.release.tag_name }} -f ./docker/Dockerfile --target ubi -t artifactory.internal.sysdig.com/$EXPORTER_NAME:${{ github.event.release.tag_name }}-ubi .
26+
- name: Publish docker image
27+
run: |
28+
docker tag artifactory.internal.sysdig.com/$EXPORTER_NAME:latest artifactory.internal.sysdig.com/$EXPORTER_NAME:${{ github.event.release.tag_name }}
29+
docker push artifactory.internal.sysdig.com/$EXPORTER_NAME:${{ github.event.release.tag_name }}
30+
docker push artifactory.internal.sysdig.com/$EXPORTER_NAME:${{ github.event.release.tag_name }}-ubi
31+
docker push artifactory.internal.sysdig.com/$EXPORTER_NAME:latest
32+
- name: Upload master to Quay.io
33+
uses: fjogeleit/http-request-action@master
34+
with:
35+
url: 'https://sysdig-jenkins.internal.sysdig.com/view/Integrations/job/integrations-redis-exporter/buildWithParameters?token=${{ secrets.JENKINS_PROMCAT_LAUNCH_TOKEN }}&EXPORTER=redis-exporter&DRY_RUN=false'
36+
method: 'POST'
37+
38+
password: ${{ secrets.JENKINS_PROMCAT_API_TOKEN }}

build/Jenkinsfile

+26-10
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,56 @@
1+
string projectName = "prometheus-integrations"
2+
13
pipeline {
2-
agent {
3-
label 'qa_terminating_j8'
4-
}
4+
agent none
5+
56

67
options {
7-
disableConcurrentBuilds()
8+
skipDefaultCheckout()
89
}
910

1011
environment {
1112
registryCredential = 'jenkins-artifactory'
1213
ARTIFACTORY_URL = 'docker.internal.sysdig.com'
13-
EXPORTER = 'redis-exporter'
14-
VERSION = 'v1.24.0'
1514
}
1615

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+
1721
stages {
1822
stage('Pull image from artifactory') {
23+
agent any
1924
steps {
2025
script {
21-
docker.withRegistry("https://${env.ARTIFACTORY_URL}", registryCredential) {
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}"
2230
sh """docker pull ${env.ARTIFACTORY_URL}/${env.EXPORTER}:${env.VERSION}"""
31+
sh """docker pull ${env.ARTIFACTORY_URL}/${env.EXPORTER}:${env.VERSION}-ubi"""
2332
}
2433
}
2534
}
2635
}
2736
stage('Push image to Quay'){
37+
agent any
2838
steps {
2939
script {
40+
if (params.DRY_RUN) {
41+
echo "docker push quay.io/sysdig/${env.EXPORTER}:${env.VERSION}"
42+
} else {
3043
docker.withRegistry("https://quay.io", "QUAY") {
31-
sh """docker tag ${env.ARTIFACTORY_URL}/${env.EXPORTER}:${env.VERSION} quay.io/sysdig/${env.EXPORTER}:latest"""
3244
sh """docker tag ${env.ARTIFACTORY_URL}/${env.EXPORTER}:${env.VERSION} quay.io/sysdig/${env.EXPORTER}:${env.VERSION}"""
33-
sh """docker push quay.io/sysdig/${env.EXPORTER}:latest"""
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"""
3447
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+
}
3551
}
3652
}
3753
}
3854
}
39-
}
55+
} //stages
4056
}

docker/Dockerfile

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM golang:1.16-alpine as builder
2+
WORKDIR /go/src/github.com/oliver006/redis_exporter/
3+
4+
ADD . /go/src/github.com/oliver006/redis_exporter/
5+
6+
ARG GOARCH="amd64"
7+
ARG SHA1="[no-sha]"
8+
ARG TAG="[no-tag]"
9+
10+
RUN apk --no-cache add ca-certificates
11+
RUN BUILD_DATE=$(date +%F-%T) && CGO_ENABLED=0 GOOS=linux GOARCH=$GOARCH go build -o /redis_exporter \
12+
-ldflags "-s -w -extldflags \"-static\" -X main.BuildVersion=$TAG -X main.BuildCommitSha=$SHA1 -X main.BuildDate=$BUILD_DATE" .
13+
14+
RUN [ $GOARCH = "amd64" ] && /redis_exporter -version || ls -la /redis_exporter
15+
16+
#
17+
# scratch release container
18+
#
19+
FROM scratch as scratch
20+
21+
COPY --from=builder /redis_exporter /redis_exporter
22+
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
23+
COPY --from=builder /etc/nsswitch.conf /etc/nsswitch.conf
24+
25+
# Run as non-root user for secure environments
26+
USER 59000:59000
27+
28+
EXPOSE 9121
29+
ENTRYPOINT [ "/redis_exporter" ]
30+
31+
FROM quay.io/sysdig/sysdig-mini-ubi:1.1.10 as ubi
32+
33+
COPY --from=builder /redis_exporter /redis_exporter
34+
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
35+
COPY --from=builder /etc/nsswitch.conf /etc/nsswitch.conf
36+
37+
# Run as non-root user for secure environments
38+
USER 59000:59000
39+
40+
EXPOSE 9121
41+
ENTRYPOINT [ "/redis_exporter" ]

0 commit comments

Comments
 (0)