Skip to content

Commit 54022da

Browse files
authored
feat: add multiarch build using matrix strategy (edgefarm#29)
* feat: add multiarch build using matrix strategy --------- Co-authored-by: zs-ko <[email protected]>
1 parent 233c964 commit 54022da

File tree

5 files changed

+67
-25
lines changed

5 files changed

+67
-25
lines changed

.github/workflows/release.yml

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,73 @@ on:
1010
- completed
1111

1212
jobs:
13-
on-success:
14-
name: Release
13+
test:
14+
name: Test
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout
1818
uses: actions/checkout@v3
1919
with:
2020
fetch-depth: 0
2121

22-
- name: Setup Node.js
23-
uses: actions/setup-node@v3
24-
with:
25-
node-version: "lts/*"
26-
27-
- name: Set up Go 1.18
28-
uses: actions/setup-go@v3
22+
- name: Set up Go 1.21.10
23+
uses: actions/setup-go@v5
2924
with:
30-
go-version: 1.18
25+
go-version: '1.21.10'
3126

3227
- name: Run Tests
3328
run: |
3429
make test
30+
build:
31+
name: Build
32+
needs: test
33+
runs-on: ubuntu-latest
34+
strategy:
35+
matrix:
36+
os: ['linux', 'windows', 'darwin']
37+
architecture: [amd64, arm64]
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v3
41+
with:
42+
fetch-depth: 0
43+
44+
- name: Set up Go 1.21.10
45+
uses: actions/setup-go@v5
46+
with:
47+
go-version: '1.21.10'
3548

3649
- name: Build the artifacts
3750
run: |
38-
make build
51+
make OS=${{ matrix.os }} GOARCH=${{ matrix.architecture }} build
52+
53+
- name: uplpoad built artifacts
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: vault-plugin-secrets-nats-${{ matrix.os }}-${{ matrix.architecture }}
57+
path: build/vault/plugins/vault-plugin-secrets-nats-*
58+
retention-days: 1
59+
overwrite: true
60+
release:
61+
name: Release
62+
runs-on: ubuntu-latest
63+
needs: build
64+
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v3
67+
with:
68+
fetch-depth: 0
69+
70+
- name: Setup Node.js
71+
uses: actions/setup-node@v3
72+
with:
73+
node-version: "lts/*"
74+
75+
- name: Download built artifacts
76+
uses: actions/download-artifact@v4
77+
with:
78+
path: build/vault/plugins/
79+
merge-multiple: true
3980

4081
- name: Release
4182
env:
@@ -45,6 +86,4 @@ jobs:
4586
#!/bin/bash
4687
set -e
4788
npm install @semantic-release/exec @eclass/semantic-release-docker @semantic-release/git -D
48-
# the ... || true is to prevent the script from failing caused by a bug in semantic-release regarding
49-
# rate limit changes on github. See https://github.com/semantic-release/github/pull/487
50-
npx -c semantic-release || true
89+
npx -c semantic-release

.releaserc.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@
5252
{
5353
"assets": [
5454
{
55-
"path": "build/vault/plugins/vault-plugin-secrets-nats",
56-
"label": "vault-plugin-secrets-nats"
57-
},
58-
{
59-
"path": "build/vault/plugins/vault-plugin-secrets-nats.sha256",
60-
"label": "vault-plugin-secrets-nats.sha256"
55+
"path": "build/vault/plugins/vault-plugin-secrets-*"
6156
}
6257
]
6358
}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ generate:
2121
all: fmt build start
2222

2323
build: generate
24-
CGO_ENABLED=0 GOOS=$(OS) GOARCH="$(GOARCH)" go build -o build/vault/plugins/vault-plugin-secrets-nats -gcflags "all=-N -l" -ldflags '-extldflags "-static"' cmd/vault-plugin-secrets-nats/main.go
24+
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(GOARCH) go build -o build/vault/plugins/vault-plugin-secrets-nats-$(OS)-$(GOARCH) -gcflags "all=-N -l" -ldflags '-extldflags "-static"' cmd/vault-plugin-secrets-nats/main.go
2525

2626
docker: build
2727
docker build -t $(DOCKER_REGISTRY)/vault-with-nats-secrets:$(VERSION) -f build/vault/Dockerfile .
@@ -36,7 +36,7 @@ enable:
3636
VAULT_ADDR='http://127.0.0.1:8200' vault secrets enable -path=nats-secrets vault-plugin-secrets-nats
3737

3838
clean:
39-
rm -f ./build/vault/plugins/vault-plugin-secrets-nats
39+
rm -f ./build/vault/plugins/vault-plugin-secrets-nats-*
4040

4141
fmt:
4242
go fmt $$(go list ./...)

build/vault/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM vault:1.12.5
22
RUN mkdir -p /etc/vault/vault_plugins
33
RUN mkdir -p /etc/vault/vault_plugins_checksums
4-
COPY build/vault/plugins/vault-plugin-secrets-nats /etc/vault/vault_plugins
4+
COPY build/vault/plugins/vault-plugin-secrets-nats-linux-amd64 /etc/vault/vault_plugins/vault-plugin-secrets-nats
55
RUN sha256sum /etc/vault/vault_plugins/vault-plugin-secrets-nats > /etc/vault/vault_plugins_checksums/vault-plugin-secrets-nats.sha256
66
RUN cat /etc/vault/vault_plugins_checksums/*
77

ci/semantic-release-patch-files.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
#!/bin/sh
22
set -e
33
NEXTVERSION=$1
4-
sha256sum build/vault/plugins/vault-plugin-secrets-nats > build/vault/plugins/vault-plugin-secrets-nats.sha256
4+
for file in build/vault/plugins/vault-plugin-secrets-nats-*; do
5+
sha256sum $file > $file.sha256
6+
# this is to retain backward compatibility with the old naming convention
7+
if echo "$file" | grep -q "amd64"; then
8+
cp $file ./build/vault/plugins/vault-plugin-secrets-nats
9+
cp $file.sha256 build/vault/plugins/vault-plugin-secrets-nats.sha256
10+
fi
11+
done
12+
# only use x86 for the README.md and dev/manifests/vault/vault.yaml
513
export SHA256SUM=$(cat build/vault/plugins/vault-plugin-secrets-nats.sha256 | cut -d ' ' -f1)
614
sed -i "s#sha256: .*#sha256: ${SHA256SUM}#g" README.md
715
sed -i "s#image: ghcr.io/edgefarm/vault-plugin-secrets-nats/vault-with-nats-secrets:.*#image: ghcr.io/edgefarm/vault-plugin-secrets-nats/vault-with-nats-secrets:${NEXTVERSION}#g" README.md
816
sed -i "s#sha256: .*#sha256: ${SHA256SUM}#g" dev/manifests/vault/vault.yaml
9-
sed -i "s#image: ghcr.io/edgefarm/vault-plugin-secrets-nats/vault-with-nats-secrets:.*#image: ghcr.io/edgefarm/vault-plugin-secrets-nats/vault-with-nats-secrets:${NEXTVERSION}#g" dev/manifests/vault/vault.yaml
17+
sed -i "s#image: ghcr.io/edgefarm/vault-plugin-secrets-nats/vault-with-nats-secrets:.*#image: ghcr.io/edgefarm/vault-plugin-secrets-nats/vault-with-nats-secrets:${NEXTVERSION}#g" dev/manifests/vault/vault.yaml

0 commit comments

Comments
 (0)