-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (147 loc) · 7.04 KB
/
dockerimage.yml
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
name: Docker image build and push
on:
pull_request:
types: [ closed ]
push:
branches:
- 'master'
jobs:
build-latest:
if: ${{ github.event.pull_request.merged == true || ( github.ref == 'refs/heads/master' && github.event_name == 'push' ) }}
name: Build latest Image
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: [amd64, arm64, 386]
steps:
- uses: actions/checkout@v4
- name: Prepare multiarch
run: sudo podman run --rm --privileged docker.io/tonistiigi/binfmt --install all
- name: Build latest image
id: build-latest-image
uses: redhat-actions/[email protected]
with:
image: loki
archs: ${{ matrix.arch }}
tags: latest-${{ matrix.arch }}
containerfiles: |
./Dockerfile
build-args: |
VERSION=master
GOARCH=${{ matrix.arch }}
layers: true
- name: Push latest image to ghcr
uses: redhat-actions/[email protected]
with:
image: ${{ steps.build-latest-image.outputs.image }}
tags: ${{ steps.build-latest-image.outputs.tags }}
registry: ghcr.io/${{ github.repository_owner }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
build-version:
if: ${{ github.event.pull_request.merged == true || ( github.ref == 'refs/heads/master' && github.event_name == 'push' ) }}
outputs:
version: ${{ steps.loki-version.outputs.version }}
name: Build Version Image
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: [amd64, arm64, 386]
steps:
- uses: actions/checkout@v4
- name: Get latest Loki release
id: loki-version
run: |
export LOKI_LATEST=$(curl -s "https://api.github.com/repos/grafana/loki/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")')
echo "VERSION=$LOKI_LATEST" >> ${GITHUB_ENV}
echo "version=$LOKI_LATEST" >> ${GITHUB_OUTPUT}
shell: bash
- name: check if latest loki is already a package version
id: get_versions
uses: octokit/[email protected]
with:
route: GET /user/packages/container/loki/versions
env:
GITHUB_TOKEN: ${{ secrets.PACKAGES }}
- run: |
export LOKI_AVAIL=$(echo "${{ steps.get_versions.outputs.data }}"|grep -Po "${VERSION}"|head -1)
echo "AVAIL=$LOKI_AVAIL" >> ${GITHUB_ENV}
- name: Prepare multiarch
run: sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes
if: env.VERSION != env.AVAIL
- name: Build version image
id: build-version-image
uses: redhat-actions/[email protected]
with:
image: loki
archs: ${{ matrix.arch }}
tags: ${{ env.VERSION }}-${{ matrix.arch }}
dockerfiles: |
./Dockerfile
build-args: |
VERSION=${{ env.VERSION }}
GOARCH=${{ matrix.arch }}
if: env.VERSION != env.AVAIL
- name: Push version image to ghcr
uses: redhat-actions/[email protected]
with:
image: ${{ steps.build-version-image.outputs.image }}
tags: ${{ steps.build-version-image.outputs.tags }}
registry: ghcr.io/${{ github.repository_owner }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
if: env.VERSION != env.AVAIL
create-manifest-latest:
needs: build-latest
if: ${{ github.event.pull_request.merged == true || ( github.ref == 'refs/heads/master' && github.event_name == 'push' ) }}
name: Create manifest for latest image
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: pull latest images
run: |
docker pull ghcr.io/${{ github.repository_owner }}/loki:latest-arm64
docker pull ghcr.io/${{ github.repository_owner }}/loki:latest-amd64
docker pull ghcr.io/${{ github.repository_owner }}/loki:latest-386
- name: create latest manifest list
run: |
docker manifest create ghcr.io/${{ github.repository_owner }}/loki:latest ghcr.io/${{ github.repository_owner }}/loki:latest-arm64 ghcr.io/${{ github.repository_owner }}/loki:latest-amd64 ghcr.io/${{ github.repository_owner }}/loki:latest-386
docker manifest annotate ghcr.io/${{ github.repository_owner }}/loki:latest ghcr.io/${{ github.repository_owner }}/loki:latest-arm64 --arch arm64
docker manifest annotate ghcr.io/${{ github.repository_owner }}/loki:latest ghcr.io/${{ github.repository_owner }}/loki:latest-amd64 --arch amd64
docker manifest annotate ghcr.io/${{ github.repository_owner }}/loki:latest ghcr.io/${{ github.repository_owner }}/loki:latest-386 --arch 386
- name: push latest manifest
run: |
docker manifest push ghcr.io/${{ github.repository_owner }}/loki:latest
create-manifest-version:
needs: build-version
if: ${{ github.event.pull_request.merged == true || ( github.ref == 'refs/heads/master' && github.event_name == 'push' ) }}
name: Create manifest for version image
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: pull version images
run: |
docker pull ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}}-arm64
docker pull ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}}-amd64
docker pull ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}}-386
- name: create version manifest list
run: |
docker manifest create ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}} ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}}-arm64 ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}}-amd64 ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}}-386
docker manifest annotate ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}} ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}}-arm64 --arch arm64
docker manifest annotate ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}} ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}}-amd64 --arch amd64
docker manifest annotate ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}} ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}}-386 --arch 386
- name: push version manifest
run: |
docker manifest push ghcr.io/${{ github.repository_owner }}/loki:${{needs.build-version.outputs.version}}