Skip to content

Commit d065710

Browse files
committed
Merge branch 'add-read-only-file-plugin' into allow-second-credential-watcher
2 parents b81fb37 + 5773b42 commit d065710

18 files changed

+426
-543
lines changed

.github/workflows/release-branch.yml

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ on:
2828
default: false
2929
type: boolean
3030
createPullRequest:
31-
description: 'Create pull request back into v3'
31+
description: 'Create pull request back into main'
3232
default: false
3333
type: boolean
3434
releaseBranch:
@@ -262,23 +262,6 @@ jobs:
262262
echo "$GPG_KEY" | base64 --decode > ${NFPM_SIGNING_KEY_FILE}
263263
make package
264264
265-
- name: Azure Login
266-
if: ${{ inputs.uploadAzure == true }}
267-
uses: azure/login@8c334a195cbb38e46038007b304988d888bf676a # v2.0.0
268-
with:
269-
creds: ${{ secrets.AZURE_CREDENTIALS }}
270-
271-
- name: Azure Upload Release Packages
272-
if: ${{ inputs.uploadAzure == true }}
273-
uses: azure/CLI@965c8d7571d2231a54e321ddd07f7b10317f34d9 # v2.0.0
274-
with:
275-
inlineScript: |
276-
for i in ./build/azure/packages/nginx-agent*; do
277-
echo "Uploading ${i} to nginx-agent/${GITHUB_REF##*/}/${i##*/}"
278-
az storage blob upload --auth-mode=login -f "$i" -c ${{ secrets.AZURE_CONTAINER_NAME }} \
279-
--account-name ${{ secrets.AZURE_ACCOUNT_NAME }} --overwrite -n nginx-agent/${GITHUB_REF##*/}/${i##*/}
280-
done
281-
282265
- name: Install GPG tools
283266
if: ${{ inputs.publishPackages == true }}
284267
run: |
@@ -302,34 +285,9 @@ jobs:
302285
run: |
303286
make release
304287
305-
- name: Upload Release Assets
306-
if: ${{ needs.vars.outputs.github_release == 'true' }}
307-
env:
308-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
309-
# clobber overwrites existing assets of the same name
310-
run: |
311-
gh release upload --clobber v${{ inputs.packageVersion }} \
312-
$(find ./build/github/packages -type f \( -name "*.deb" -o -name "*.rpm" -o -name "*.pkg" -o -name "*.apk" \))
313-
314-
- name: Publish Github Release
315-
if: ${{ needs.vars.outputs.github_release == 'true' }}
316-
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
317-
with:
318-
script: |
319-
const {RELEASE_ID} = process.env
320-
const release = (await github.rest.repos.updateRelease({
321-
owner: context.payload.repository.owner.login,
322-
repo: context.payload.repository.name,
323-
release_id: `${RELEASE_ID}`,
324-
draft: false,
325-
}))
326-
console.log(`Release published: ${release.data.html_url}`)
327-
env:
328-
RELEASE_ID: ${{ needs.release-draft.outputs.release_id }}
329-
330288
merge-release:
331289
if: ${{ needs.vars.outputs.create_pull_request == 'true' }}
332-
name: Merge release branch back into V3 branch
290+
name: Merge release branch back into main branch
333291
runs-on: ubuntu-22.04
334292
needs: [vars,tag-release]
335293
permissions:
@@ -346,11 +304,11 @@ jobs:
346304
script: |
347305
const { repo, owner } = context.repo;
348306
const result = await github.rest.pulls.create({
349-
title: 'Merge ${{ github.ref_name }} back into v3',
307+
title: 'Merge ${{ github.ref_name }} back into main',
350308
owner,
351309
repo,
352310
head: '${{ github.ref_name }}',
353-
base: 'v3',
311+
base: 'main',
354312
body: [
355313
'This PR is auto-generated by the release workflow.'
356314
].join('\n')
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Publish Release packages
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
pkgRepo:
7+
description: "Source repository to pull packages from"
8+
type: string
9+
default: ""
10+
pkgVersion:
11+
description: 'Agent version'
12+
type: string
13+
default: ""
14+
uploadAzure:
15+
description: 'Publish packages Azure storage'
16+
type: boolean
17+
default: false
18+
uploadGithub:
19+
description: 'Publish packages to GitHub release'
20+
type: boolean
21+
default: false
22+
23+
defaults:
24+
run:
25+
shell: bash
26+
27+
permissions:
28+
contents: read
29+
30+
jobs:
31+
vars:
32+
name: Set workflow variables
33+
runs-on: ubuntu-22.04
34+
outputs:
35+
github_release: ${{steps.vars.outputs.github_release }}
36+
upload_azure: ${{steps.vars.outputs.upload_azure }}
37+
steps:
38+
- name: Checkout Repository
39+
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
40+
with:
41+
ref: ${{ inputs.releaseBranch }}
42+
43+
- name: Set variables
44+
id: vars
45+
run: |
46+
echo "github_release=${{ inputs.uploadGithub }}" >> $GITHUB_OUTPUT
47+
echo "upload_azure=${{ inputs.uploadAzure }}" >> $GITHUB_OUTPUT
48+
cat $GITHUB_OUTPUT
49+
50+
upload-release-assets:
51+
name: Upload assets
52+
runs-on: ubuntu-22.04
53+
needs: [vars]
54+
steps:
55+
- name: Checkout Repository
56+
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
57+
with:
58+
ref: ${{ inputs.releaseBranch }}
59+
60+
- name: Azure Login
61+
if: ${{ inputs.uploadAzure == true }}
62+
uses: azure/login@8c334a195cbb38e46038007b304988d888bf676a # v2.0.0
63+
with:
64+
creds: ${{ secrets.AZURE_CREDENTIALS }}
65+
66+
- name: Download Packages
67+
run:
68+
|
69+
echo "Checking Packages in ${{inputs.pkgRepo}}/nginx-agent"
70+
PKG_REPO=${{inputs.pkgRepo}} CERT=${{secrets.PUBTEST_CERT}} KEY=${{secrets.PUBTEST_KEY}} DL=1 scripts/packages/package-check.sh ${{inputs.pkgVersion}}
71+
find ${{inputs.pkgRepo}}/nginx-agent | grep -e "nginx-agent[_-]${{inputs.pkgVersion}}"
72+
73+
- name: Azure Upload Release Packages
74+
if: ${{ inputs.uploadAzure == true }}
75+
uses: azure/CLI@965c8d7571d2231a54e321ddd07f7b10317f34d9 # v2.0.0
76+
with:
77+
inlineScript: |
78+
for i in $(find ${{inputs.pkgRepo}}/nginx-agent | grep -e "nginx-agent[_-]${{inputs.pkgVersion}}"); do
79+
dest="nginx-agent/${GITHUB_REF##*/}/${i##*/}"
80+
if [[ "$i" == *.apk ]]; then
81+
ver=$(echo "$i" | grep -o -e "v[0-9]*\.[0-9]*")
82+
arch=$(echo "$i" | grep -o -F -e "x86_64" -e "aarch64")
83+
dest="nginx-agent/${GITHUB_REF##*/}/nginx-agent-$VER-$ver-$arch.apk"
84+
fi
85+
echo "Uploading ${i} to ${dest}"
86+
az storage blob upload --auth-mode=login -f "$i" -c ${{ secrets.AZURE_CONTAINER_NAME }} \
87+
--account-name ${{ secrets.AZURE_ACCOUNT_NAME }} --overwrite -n ${dest}
88+
done
89+
90+
- name: Azure Logout
91+
run: |
92+
az logout
93+
if: always()
94+
95+
- name: GitHub Upload Release Assets
96+
if: ${{ needs.vars.outputs.github_release == 'true' }}
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
# clobber overwrites existing assets of the same name
100+
run: |
101+
gh release upload --clobber v${{ inputs.pkgVersion }} \
102+
$(find ${{inputs.pkgRepo}}/nginx-agent | grep -e "nginx-agent[_-]${{inputs.pkgVersion}}")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/nginx/agent/v3
22

33
go 1.23.7
44

5-
toolchain go1.23.8
5+
toolchain go1.23.10
66

77
require (
88
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.4-20250130201111-63bb56e20495.1

internal/command/command_plugin.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"log/slog"
1111
"sync"
1212

13+
"github.com/nginx/agent/v3/internal/model"
14+
1315
"google.golang.org/protobuf/types/known/timestamppb"
1416

1517
mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
@@ -25,17 +27,6 @@ var _ bus.Plugin = (*CommandPlugin)(nil)
2527

2628
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6@v6.8.1 -generate
2729
//counterfeiter:generate . commandService
28-
type ServerType int
29-
30-
const (
31-
Command ServerType = iota
32-
Auxiliary
33-
)
34-
35-
var serverType = map[ServerType]string{
36-
Command: "command",
37-
Auxiliary: "auxiliary",
38-
}
3930

4031
type (
4132
commandService interface {
@@ -55,13 +46,13 @@ type (
5546
conn grpc.GrpcConnectionInterface
5647
commandService commandService
5748
subscribeChannel chan *mpi.ManagementPlaneRequest
58-
commandServerType ServerType
49+
commandServerType model.ServerType
5950
subscribeMutex sync.Mutex
6051
}
6152
)
6253

6354
func NewCommandPlugin(agentConfig *config.Config, grpcConnection grpc.GrpcConnectionInterface,
64-
commandServerType ServerType,
55+
commandServerType model.ServerType,
6556
) *CommandPlugin {
6657
return &CommandPlugin{
6758
config: agentConfig,
@@ -256,7 +247,7 @@ func (cp *CommandPlugin) monitorSubscribeChannel(ctx context.Context) {
256247
slog.InfoContext(ctx, "Received management plane config upload request")
257248
cp.handleConfigUploadRequest(newCtx, message)
258249
case *mpi.ManagementPlaneRequest_ConfigApplyRequest:
259-
if cp.commandServerType != Command {
250+
if cp.commandServerType != model.Command {
260251
slog.WarnContext(newCtx, "Auxiliary command server can not perform config apply",
261252
"command_server_type", cp.commandServerType.String())
262253
cp.handleInvalidRequest(newCtx, message)
@@ -269,7 +260,7 @@ func (cp *CommandPlugin) monitorSubscribeChannel(ctx context.Context) {
269260
slog.InfoContext(ctx, "Received management plane health request")
270261
cp.handleHealthRequest(newCtx)
271262
case *mpi.ManagementPlaneRequest_ActionRequest:
272-
if cp.commandServerType != Command {
263+
if cp.commandServerType != model.Command {
273264
slog.WarnContext(newCtx, "Auxiliary command server can not perform api action",
274265
"command_server_type", cp.commandServerType.String())
275266
cp.handleInvalidRequest(newCtx, message)
@@ -395,7 +386,3 @@ func (cp *CommandPlugin) createDataPlaneResponse(correlationID string, status mp
395386
},
396387
}
397388
}
398-
399-
func (s ServerType) String() string {
400-
return serverType[s]
401-
}

internal/command/command_plugin_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"testing"
1212
"time"
1313

14+
"github.com/nginx/agent/v3/internal/model"
15+
1416
pkg "github.com/nginx/agent/v3/pkg/config"
1517
"github.com/nginx/agent/v3/pkg/id"
1618

@@ -32,14 +34,14 @@ import (
3234
)
3335

3436
func TestCommandPlugin_Info(t *testing.T) {
35-
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
37+
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
3638
info := commandPlugin.Info()
3739

3840
assert.Equal(t, "command", info.Name)
3941
}
4042

4143
func TestCommandPlugin_Subscriptions(t *testing.T) {
42-
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
44+
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
4345
subscriptions := commandPlugin.Subscriptions()
4446

4547
assert.Equal(
@@ -60,7 +62,7 @@ func TestCommandPlugin_Init(t *testing.T) {
6062
messagePipe := busfakes.NewFakeMessagePipe()
6163
fakeCommandService := &commandfakes.FakeCommandService{}
6264

63-
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
65+
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
6466
err := commandPlugin.Init(ctx, messagePipe)
6567
require.NoError(t, err)
6668

@@ -79,7 +81,7 @@ func TestCommandPlugin_createConnection(t *testing.T) {
7981
commandService.CreateConnectionReturns(&mpi.CreateConnectionResponse{}, nil)
8082
messagePipe := busfakes.NewFakeMessagePipe()
8183

82-
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
84+
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
8385
err := commandPlugin.Init(ctx, messagePipe)
8486
commandPlugin.commandService = commandService
8587
require.NoError(t, err)
@@ -111,7 +113,7 @@ func TestCommandPlugin_Process(t *testing.T) {
111113
messagePipe := busfakes.NewFakeMessagePipe()
112114
fakeCommandService := &commandfakes.FakeCommandService{}
113115

114-
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
116+
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
115117
err := commandPlugin.Init(ctx, messagePipe)
116118
require.NoError(t, err)
117119
defer commandPlugin.Close(ctx)
@@ -219,7 +221,7 @@ func TestCommandPlugin_monitorSubscribeChannel(t *testing.T) {
219221

220222
agentConfig := types.AgentConfig()
221223
agentConfig.Features = test.configFeatures
222-
commandPlugin := NewCommandPlugin(agentConfig, &grpcfakes.FakeGrpcConnectionInterface{}, Command)
224+
commandPlugin := NewCommandPlugin(agentConfig, &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
223225
err := commandPlugin.Init(ctx, messagePipe)
224226
require.NoError(tt, err)
225227
defer commandPlugin.Close(ctx)
@@ -319,7 +321,7 @@ func TestCommandPlugin_FeatureDisabled(t *testing.T) {
319321

320322
agentConfig.Features = test.configFeatures
321323

322-
commandPlugin := NewCommandPlugin(agentConfig, &grpcfakes.FakeGrpcConnectionInterface{}, Command)
324+
commandPlugin := NewCommandPlugin(agentConfig, &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
323325
err := commandPlugin.Init(ctx, messagePipe)
324326
commandPlugin.commandService = fakeCommandService
325327
require.NoError(tt, err)
@@ -344,7 +346,7 @@ func TestMonitorSubscribeChannel(t *testing.T) {
344346
logBuf := &bytes.Buffer{}
345347
stub.StubLoggerWith(logBuf)
346348

347-
cp := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
349+
cp := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
348350
cp.subscribeCancel = cncl
349351

350352
message := protos.CreateManagementPlaneRequest()
@@ -383,7 +385,7 @@ func Test_createDataPlaneResponse(t *testing.T) {
383385
Error: "",
384386
},
385387
}
386-
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
388+
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
387389
result := commandPlugin.createDataPlaneResponse(expected.GetMessageMeta().GetCorrelationId(),
388390
expected.GetCommandResponse().GetStatus(),
389391
expected.GetCommandResponse().GetMessage(), expected.GetCommandResponse().GetError())

0 commit comments

Comments
 (0)