forked from labring/sealos
-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (136 loc) · 4.84 KB
/
webhooks.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
name: Build Webhooks image
on:
workflow_dispatch:
inputs:
push_mage:
description: 'Push images'
required: false
type: boolean
push:
branches: [ "main" ]
paths:
- "webhooks/**"
- ".github/workflows/webhooks.yml"
- "!**/*.md"
- "!**/*.yaml"
pull_request:
branches: [ "*" ]
paths:
- "webhooks/**"
- ".github/workflows/webhooks.yml"
- "!**/*.md"
- "!**/*.yaml"
env:
# Common versions
GO_VERSION: "1.22"
DEFAULT_OWNER: "labring"
jobs:
resolve-modules:
runs-on: ubuntu-20.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Resolve Modules
id: set-matrix
run: bash ./scripts/resolve-modules.sh ./webhooks
golangci-lint:
needs: [ resolve-modules ]
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Install Dependencies
run: sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
- name: Run Linter
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.2
working-directory: ${{ matrix.workdir }}
args: "--out-${NO_FUTURE}format colored-line-number"
image-build:
runs-on: ubuntu-latest
strategy:
matrix:
module: [ admission ]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Install Dependencies
run: sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
- name: Build ${{ matrix.module }} amd64
working-directory: webhooks/${{ matrix.module }}
run: |
GOARCH=amd64 make build
mv bin/manager bin/webhook-${{ matrix.module }}-amd64
chmod +x bin/webhook-${{ matrix.module }}-amd64
- name: Build ${{ matrix.module }} arm64
working-directory: webhooks/${{ matrix.module }}
run: |
GOARCH=arm64 make build
mv bin/manager bin/webhook-${{ matrix.module }}-arm64
chmod +x bin/webhook-${{ matrix.module }}-arm64
- name: Prepare
id: prepare
run: |
TAG=latest
echo tag_name=${TAG} >> $GITHUB_OUTPUT
- # Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Login to Docker Hub
uses: docker/login-action@v2
if: ${{ (github.event_name == 'push') || (inputs.push_mage == true) }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_PAT }}
- name: build (and publish) ${{ matrix.module }} main image
if: ${{ (github.event_name == 'push') || (inputs.push_mage == true) }}
env:
# fork friendly ^^
DOCKER_REPO: ghcr.io/${{ github.repository_owner }}/sealos-${{ matrix.module }}-webhook
working-directory: webhooks/${{ matrix.module }}
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/sealos" \
--label "org.opencontainers.image.description=sealos-${{ matrix.module }}-webhook container image" \
--label "org.opencontainers.image.licenses=MIT" \
--push \
-t ${DOCKER_REPO}:${{ steps.prepare.outputs.tag_name }} \
-f Dockerfile \
.
- name: build ${{ matrix.module }} image
if: ${{ github.event_name == 'pull_request' }}
env:
# fork friendly ^^
DOCKER_REPO: ghcr.io/${{ github.repository_owner }}/sealos-${{ matrix.module }}-webhook
working-directory: webhooks/${{ matrix.module }}
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/sealos" \
--label "org.opencontainers.image.description=sealos-${{ matrix.module }}-webhook container image" \
--label "org.opencontainers.image.licenses=MIT" \
-t ${DOCKER_REPO}:${{ steps.prepare.outputs.tag_name }} \
-f Dockerfile \
.