-
Notifications
You must be signed in to change notification settings - Fork 1
144 lines (124 loc) · 4.38 KB
/
buildAndDeploy.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
name: Build and Deploy Images
on:
push:
paths-ignore:
- "docs/**"
- "*.md"
tags:
- 'v*.*.*'
pull_request:
branches:
- main
- release/**
workflow_dispatch:
env:
DOCKERHUB_IMAGE: solarwinds/solarwinds-otel-collector
jobs:
checks:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check licenses
run: make ci-check-licenses
build_and_test:
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.generate-tag.outputs.value }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate docker image tag
id: generate-tag
run: echo "tag=v${{ github.run_number }}-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and Test
run: docker build . --file build/docker/Dockerfile --tag ${{ steps.generate-tag.outputs.tag }}
deploy_dockerhub:
runs-on: ubuntu-latest
needs: build_and_test
name: Deploy to docker hub
if: startsWith(github.ref, 'refs/tags/')
environment:
name: production
url: https://hub.docker.com/repository/docker/solarwinds/solarwinds-otel-collector
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get image tag
id: get-tag
run: echo "tag=${GITHUB_REF#refs/tags/v*}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.OPENTELEMETRY_DOCKER_HUB_CI_USER }}
password: ${{ secrets.OPENTELEMETRY_DOCKER_HUB_CI_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: build/docker/Dockerfile
platforms: linux/amd64,linux/arm64
provenance: false
sbom: false
push: true
tags: ${{ env.DOCKERHUB_IMAGE }}:${{ steps.get-tag.outputs.tag }}
create_and_push_docker_manifest:
runs-on: ubuntu-latest
name: Create Multi-platform Docker Manifest
needs:
- deploy_dockerhub
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get image tag
id: get-tag
run: echo "tag=${GITHUB_REF#refs/tags/v*}" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.OPENTELEMETRY_DOCKER_HUB_CI_USER }}
password: ${{ secrets.OPENTELEMETRY_DOCKER_HUB_CI_PASSWORD }}
- name: Get linux manifest
run: |
docker manifest inspect ${{ env.DOCKERHUB_IMAGE }}:${{ steps.get-tag.outputs.tag }} > manifest.json
- name: Create multi-arch manifest
run: |
docker manifest create ${{ env.DOCKERHUB_IMAGE }}:${{ steps.get-tag.outputs.tag }} \
--amend ${{ env.DOCKERHUB_IMAGE }}@$(jq -r '.manifests[] | select(.platform.os == "linux" and .platform.architecture == "amd64") | .digest' manifest.json) \
--amend ${{ env.DOCKERHUB_IMAGE }}@$(jq -r '.manifests[] | select(.platform.os == "linux" and .platform.architecture == "arm64") | .digest' manifest.json)
- name: Push multi-arch manifest
run: |
docker manifest push ${{ env.DOCKERHUB_IMAGE }}:${{ steps.get-tag.outputs.tag }}
create_release:
runs-on: ubuntu-latest
name: Create GitHub Release
needs:
- create_and_push_docker_manifest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Find previous tag
run: |
CURRENT_TAG=${GITHUB_REF#refs/tags/}
PREVIOUS_TAG=$(git tag --sort=version:refname | grep -B1 "^${CURRENT_TAG}$" | head -n 1)
echo "Previous tag: $PREVIOUS_TAG"
echo "PREVIOUS_TAG=$PREVIOUS_TAG" >> $GITHUB_ENV
- name: Get current tag
id: get-tag
run: echo "tag=${GITHUB_REF#refs/tags/*}" >> $GITHUB_OUTPUT
- name: Create GitHub Release
env:
# for gh cli
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ steps.get-tag.outputs.tag }} \
--title ${{ steps.get-tag.outputs.tag }} \
--latest=false \
--generate-notes \
--notes-start-tag ${{ env.PREVIOUS_TAG }}