Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit b930781

Browse files
author
Audrius Karabanovas
committed
Moving to GH actions as CI/CD pipeline
1 parent bfd285c commit b930781

10 files changed

+201
-141
lines changed

.github/main.workflow

-9
This file was deleted.

.github/workflows/push.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
on: push
2+
name: test-and-build
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
8+
- name: Set up Go 1.13
9+
uses: actions/setup-go@v1
10+
with:
11+
go-version: 1.13
12+
id: go
13+
14+
- name: Check out code into the Go module directory
15+
uses: actions/checkout@v1
16+
17+
- name: Get dependencies
18+
run: |
19+
go mod download
20+
21+
- name: Run unit-tests
22+
run: |
23+
GO111MODULE=on CGO_ENABLED=0 go test ./...
24+
25+
- name: Build executables
26+
run: |
27+
./build.sh
28+
29+
- name: Upload artifact
30+
uses: actions/[email protected]
31+
with:
32+
name: binaries
33+
path: .build
34+
35+
dockerimage:
36+
runs-on: ubuntu-latest
37+
needs: build
38+
steps:
39+
- name: Check out code into the Go module directory
40+
uses: actions/checkout@v1
41+
with:
42+
fetch-depth: 1
43+
44+
- name: Download artifact
45+
uses: actions/[email protected]
46+
with:
47+
name: binaries
48+
path: .build
49+
50+
- name: Build docker image
51+
run: |
52+
docker build . -t trustpilot/beat-exporter
53+
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
on:
2+
release:
3+
types: [published]
4+
name: handle-release
5+
jobs:
6+
artifacts:
7+
name: Create and upload release artifacts
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Set up Go 1.13
11+
uses: actions/setup-go@v1
12+
with:
13+
go-version: 1.13
14+
id: go
15+
16+
- name: Check out code at release tag
17+
uses: actions/checkout@v1
18+
with:
19+
ref: ${{ github.ref }}
20+
fetch-depth: 1
21+
22+
- name: Get dependencies
23+
run: |
24+
go mod download
25+
26+
- name: Build executables
27+
run: |
28+
./build.sh
29+
30+
- name: Create artifact archives
31+
run: |
32+
./create-artifacts.sh
33+
34+
- name: Upload artifacts archives
35+
uses: skx/github-action-publish-binaries@master
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
with:
39+
args: './.release/beat-exporter-*'
40+
41+
docker:
42+
name: Publish docker images
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Set up Go 1.13
46+
uses: actions/setup-go@v1
47+
with:
48+
go-version: 1.13
49+
id: go
50+
51+
- name: Check out code into the Go module directory
52+
uses: actions/checkout@v1
53+
with:
54+
ref: ${{ github.ref }}
55+
fetch-depth: 1
56+
57+
- name: Get dependencies
58+
run: |
59+
go mod download
60+
61+
- name: Build executables
62+
run: |
63+
./build.sh
64+
65+
- name: Build and push docker image with version tags
66+
uses: jerray/[email protected]
67+
with:
68+
username: ${{ secrets.DOCKER_USERNAME }}
69+
password: ${{ secrets.DOCKER_PASSWORD }}
70+
repository: trustpilot/beat-exporter
71+
auto_tag: true
72+
73+
- name: Build and push docker image with latest tag
74+
uses: jerray/[email protected]
75+
with:
76+
username: ${{ secrets.DOCKER_USERNAME }}
77+
password: ${{ secrets.DOCKER_PASSWORD }}
78+
repository: trustpilot/beat-exporter
79+
tags: latest

.promu.yml

-23
This file was deleted.

.travis.yml

-20
This file was deleted.

Dockerfile

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
FROM quay.io/prometheus/golang-builder as builder
1+
FROM quay.io/prometheus/busybox:latest
2+
LABEL MAINTAINER="Audrius Karabanovas <[email protected]>"
23

3-
ADD . /go/src/github.com/trustpilot/beat-exporter
4-
WORKDIR /go/src/github.com/trustpilot/beat-exporter
5-
6-
RUN make
7-
8-
FROM quay.io/prometheus/busybox:latest
9-
MAINTAINER Audrius Karabanovas <[email protected]>
10-
11-
COPY --from=builder /go/src/github.com/trustpilot/beat-exporter/beat-exporter /bin/beat-exporter
4+
COPY .build/linux-amd64/beat-exporter /bin/beat-exporter
125

136
EXPOSE 9479
147
ENTRYPOINT [ "/bin/beat-exporter" ]

Makefile

-78
This file was deleted.

VERSION

-1
This file was deleted.

build.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ -z "$GITHUB_WORKSPACE" ]]; then
6+
GITHUB_WORKSPACE=$(pwd)
7+
echo "Setting up GITHUB_WORKSPACE to current directory: ${GITHUB_WORKSPACE}"
8+
fi
9+
10+
if [[ -z "$GITHUB_ACTOR" ]]; then
11+
GITHUB_ACTOR=$(whoami)
12+
echo "Setting up GITHUB_ACTOR to current user: ${GITHUB_ACTOR}"
13+
fi
14+
15+
GITVERSION=$(git describe --tags --always)
16+
GITBRANCH=$(git branch | grep \* | cut -d ' ' -f2)
17+
GITREVISION=$(git log -1 --oneline | cut -d ' ' -f1)
18+
TIME=$(date +%FT%T%z)
19+
LDFLAGS="-s -X github.com/prometheus/common/version.Version=${GITVERSION} \
20+
-X github.com/prometheus/common/version.Revision=${GITREVISION} \
21+
-X github.com/prometheus/common/version.Branch=master \
22+
-X github.com/prometheus/common/version.BuildUser=${GITHUB_ACTOR} \
23+
-X github.com/prometheus/common/version.BuildDate=${TIME}"
24+
25+
for OS in "darwin" "linux" "windows"; do
26+
for ARCH in "amd64" "386"; do
27+
echo "Building ${OS}/${ARCH} with version: ${GITVERSION}, revision: ${GITREVISION}, buildUser: ${GITHUB_ACTOR}"
28+
if [[ $OS == "windows" ]]; then
29+
GO111MODULE=on CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH} go build -ldflags "${LDFLAGS}" -tags 'netgo static_build' -a -o ".build/${OS}-${ARCH}/beat-exporter.exe"
30+
else
31+
GO111MODULE=on CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH} go build -ldflags "${LDFLAGS}" -tags 'netgo static_build' -a -o ".build/${OS}-${ARCH}/beat-exporter"
32+
fi
33+
done
34+
done

create-artifacts.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ -z "$GITHUB_WORKSPACE" ]]; then
6+
echo "Set the GITHUB_WORKSPACE env variable."
7+
exit 1
8+
fi
9+
10+
if [[ -z "$GITHUB_REPOSITORY" ]]; then
11+
echo "Set the GITHUB_REPOSITORY env variable."
12+
exit 1
13+
fi
14+
15+
echo "GITHUB WORKSPACE: ${GITHUB_WORKSPACE}"
16+
echo "GITHUB REPO: ${GITHUB_REPOSITORY}"
17+
18+
RELEASE_DIR=.release
19+
VERSION=$(git describe --tags | cut -d '-' -f1 | cut -d 'v' -f2)
20+
RELEASE_FILES=LICENSE
21+
22+
mkdir -p $RELEASE_DIR
23+
24+
for ARTIFACT in $(ls .build); do
25+
ARTIFACT_NAME="beat-exporter-${VERSION}-${ARTIFACT}.tar.gz"
26+
echo "Creating ${ARTIFACT_NAME}"
27+
for FILE in $RELEASE_FILES; do
28+
cp "${GITHUB_WORKSPACE}/${FILE}" "${GITHUB_WORKSPACE}/.build/${ARTIFACT}/${FILE}"
29+
done
30+
31+
cd "${GITHUB_WORKSPACE}/.build/${ARTIFACT}" && tar -cvzf ${GITHUB_WORKSPACE}/${RELEASE_DIR}/${ARTIFACT_NAME} *
32+
done

0 commit comments

Comments
 (0)