-
Notifications
You must be signed in to change notification settings - Fork 1
189 lines (186 loc) · 7.12 KB
/
make-deb-and-publish.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
---
env:
PACKAGE_NAME: promtail
# renovate: datasource=github-releases depName=grafana/loki
PACKAGE_VERSION: v3.2.1
PACKAGE_DESCRIPTION: "Promtail is an agent which ships the contents of local logs to a private Loki instance or Grafana Cloud. It is usually deployed to every machine that has applications needed to be monitored."
APT_DEPENDENCIES: "git build-essential libsystemd-dev gccgo-aarch64-linux-gnu gccgo-arm-linux-gnueabi curl xz-utils"
name: Build, package and publish
"on":
push:
paths-ignore:
- "*.md"
- LICENSE
- .github/renovate.json
- .gitignore
branches:
- main
pull_request:
branches:
- main
jobs:
build:
name: Build & Package
runs-on: ubuntu-latest
strategy:
matrix:
goarch:
- amd64
- arm64
- arm
fail-fast: true
container: debian:bookworm-slim
steps:
- name: Install build dependencies
run: apt-get update && apt-get install -y ${APT_DEPENDENCIES}
if: ${{ env.APT_DEPENDENCIES != '' }}
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
repository: grafana/loki.git
ref: ${{ env.PACKAGE_VERSION }}
- name: Set up Golang
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5
with:
go-version: 1.21
cache: false
- id: go-cache-paths
run: |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: Golang cache
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4
with:
path: |
${{ steps.go-cache-paths.outputs.go-build }}
${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-${{ matrix.goarch }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.goarch }}-
- name: Build
run: |
case ${ARCH} in
amd64)
export CC=gcc;;
arm64)
export CC=aarch64-linux-gnu-gcc;;
arm)
export CC=arm-linux-gnueabi-gcc;;
esac
git config --global --add safe.directory '*'
export GIT_REVISION=$(git rev-parse --short HEAD)
echo $GIT_REVISION
export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo $GIT_BRANCH
export IMAGE_TAG=$(./tools/image-tag)
echo $IMAGE_TAG
export DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
GOOS=linux GOARCH=${ARCH} go build -ldflags '-s -w -X ${VPREFIX}.Branch=${GIT_BRANCH} -X ${VPREFIX}.Version=${IMAGE_TAG} -X ${VPREFIX}.Revision=${GIT_REVISION} -X ${VPREFIX}.BuildUser=$(whoami)@$(hostname) -X ${VPREFIX}.BuildDate=${DATE}' -tags netgo -mod vendor --tags=promtail_journal_enabled -o dist/${PACKAGE_NAME}_linux_${ARCH} ./clients/cmd/promtail
env:
ARCH: ${{ matrix.goarch }}
VPREFIX: github.com/grafana/loki/pkg/util/build
CGO_ENABLED: 1
GOARM: 6
- name: Install upx
run: |
curl -L -O https://github.com/upx/upx/releases/download/v4.2.2/upx-4.2.2-amd64_linux.tar.xz
tar -xvf upx-4.2.2-amd64_linux.tar.xz
mv upx-4.2.2-amd64_linux/upx /usr/local/bin
- name: Squish
run: upx dist/${PACKAGE_NAME}_linux_${ARCH}
env:
ARCH: ${{ matrix.goarch }}
- name: Upload artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
with:
name: binary-${{ matrix.goarch }}
path: dist/${{ env.PACKAGE_NAME }}_linux_${{ matrix.goarch }}
build-package:
name: Build Deb Package
runs-on: ubuntu-latest
strategy:
matrix:
goarch:
- amd64
- arm64
- arm
fail-fast: true
needs: build
steps:
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Download build artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: binary-${{ matrix.goarch }}
- name: Package
run: |
case ${ARCH} in
amd64)
export DEB_ARCH=amd64;;
arm)
export DEB_ARCH=armhf;;
arm64)
export DEB_ARCH=aarch64;;
esac
chmod +x ${PACKAGE_NAME}_*
bundle exec fpm -f \
-s dir \
-t deb \
--license Apache \
--deb-priority optional \
--deb-systemd-enable \
--deb-systemd-restart-after-upgrade \
--deb-systemd-auto-start \
--maintainer [email protected] \
--vendor https://grafana.com/ \
-n ${DEB_NAME} \
--description "${APP_DESCRIPTION}" \
--url ${APP_URL} \
--prefix / \
-a ${DEB_ARCH} \
-v ${PACKAGE_VERSION}-$(printf "%04d" $GITHUB_RUN_NUMBER) \
--before-install deb_scripts/before_install.sh \
--before-upgrade deb_scripts/before_upgrade.sh \
--after-remove deb_scripts/after_remove.sh \
--deb-systemd deb_scripts/promtail.service \
--config-files /etc/promtail/promtail.yml \
promtail.yml=/etc/promtail/promtail.yml \
promtail_linux_${ARCH}=/usr/bin/promtail
env:
DEB_NAME: ${{ env.PACKAGE_NAME }}
APP_DESCRIPTION: ${{ env.PACKAGE_DESCRIPTION }}
APP_URL: https://github.com/grafana/loki/blob/master/docs/clients/promtail/
ARCH: ${{ matrix.goarch }}
PACKAGE_VERSION: ${{ env.PACKAGE_VERSION }}
- name: Upload build artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
with:
name: deb-package-${{ matrix.goarch }}
path: "*.deb"
publish:
name: Publish
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs: build-package
steps:
- name: Download deb artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
pattern: deb-package-*
merge-multiple: true
- name: Upload to Apt repo
env:
APT_CREDENTIALS: ${{ secrets.APT_CREDENTIALS }}
APT_KEY_PASSPHRASE: ${{ secrets.APT_KEY_PASSPHRASE }}
run: |
echo $APT_CREDENTIALS > aptly-auth
find -type f -name "*.deb" -exec curl -f --netrc-file aptly-auth -XPOST -F file=@{} https://apttoo.growse.com/api/files/${PACKAGE_NAME} \;
export result=$(curl -f --netrc-file aptly-auth -X POST https://apttoo.growse.com/api/repos/defaultrepo/file/${PACKAGE_NAME})
echo $result
export failed=$(echo $result | jq '.FailedFiles | length')
if [[ "$failed" != "0" ]]; then exit 1; fi
curl -f --netrc-file aptly-auth -X PUT -H"Content-type: application/json" --data '{"Signing":{"Passphrase":"'"$APT_KEY_PASSPHRASE"'","Batch":true}}' https://apttoo.growse.com/api/publish/:./stablish