Skip to content

Commit f958507

Browse files
committed
Merge branch 'main' into add-auxiliary-command-server-proto
2 parents c42a042 + 4c52f40 commit f958507

File tree

8 files changed

+325
-72
lines changed

8 files changed

+325
-72
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/file/file_manager_service.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,19 @@ type (
6868

6969
fileManagerServiceInterface interface {
7070
UpdateOverview(ctx context.Context, instanceID string, filesToUpdate []*mpi.File, iteration int) error
71-
ConfigApply(ctx context.Context, configApplyRequest *mpi.ConfigApplyRequest) (writeStatus model.WriteStatus,
72-
err error)
71+
ConfigApply(
72+
ctx context.Context,
73+
configApplyRequest *mpi.ConfigApplyRequest,
74+
) (writeStatus model.WriteStatus, err error)
7375
Rollback(ctx context.Context, instanceID string) error
7476
UpdateFile(ctx context.Context, instanceID string, fileToUpdate *mpi.File) error
7577
ClearCache()
7678
UpdateCurrentFilesOnDisk(ctx context.Context, updateFiles map[string]*mpi.File, referenced bool) error
77-
DetermineFileActions(currentFiles map[string]*mpi.File, modifiedFiles map[string]*model.FileCache) (
78-
map[string]*model.FileCache, map[string][]byte, error)
79+
DetermineFileActions(
80+
ctx context.Context,
81+
currentFiles map[string]*mpi.File,
82+
modifiedFiles map[string]*model.FileCache,
83+
) (map[string]*model.FileCache, map[string][]byte, error)
7984
IsConnected() bool
8085
SetIsConnected(isConnected bool)
8186
}
@@ -505,8 +510,11 @@ func (fms *FileManagerService) ConfigApply(ctx context.Context,
505510
return model.Error, allowedErr
506511
}
507512

508-
diffFiles, fileContent, compareErr := fms.DetermineFileActions(fms.currentFilesOnDisk,
509-
ConvertToMapOfFileCache(fileOverview.GetFiles()))
513+
diffFiles, fileContent, compareErr := fms.DetermineFileActions(
514+
ctx,
515+
fms.currentFilesOnDisk,
516+
ConvertToMapOfFileCache(fileOverview.GetFiles()),
517+
)
510518

511519
if compareErr != nil {
512520
return model.Error, compareErr
@@ -541,7 +549,7 @@ func (fms *FileManagerService) ClearCache() {
541549

542550
// nolint:revive,cyclop
543551
func (fms *FileManagerService) Rollback(ctx context.Context, instanceID string) error {
544-
slog.InfoContext(ctx, "Rolling back config for instance", "instanceid", instanceID)
552+
slog.InfoContext(ctx, "Rolling back config for instance", "instance_id", instanceID)
545553

546554
fms.filesMutex.Lock()
547555
defer fms.filesMutex.Unlock()
@@ -710,6 +718,7 @@ func (fms *FileManagerService) checkAllowedDirectory(checkFiles []*mpi.File) err
710718
// that have changed and a map of the contents for each updated and deleted file. Key to both maps is file path
711719
// nolint: revive,cyclop,gocognit
712720
func (fms *FileManagerService) DetermineFileActions(
721+
ctx context.Context,
713722
currentFiles map[string]*mpi.File,
714723
modifiedFiles map[string]*model.FileCache,
715724
) (
@@ -732,6 +741,7 @@ func (fms *FileManagerService) DetermineFileActions(
732741
return nil, nil, manifestFileErr
733742
}
734743
}
744+
735745
// if file is in manifestFiles but not in modified files, file has been deleted
736746
// copy contents, set file action
737747
for fileName, manifestFile := range filesMap {
@@ -741,7 +751,12 @@ func (fms *FileManagerService) DetermineFileActions(
741751
// Read file contents before marking it deleted
742752
fileContent, readErr := os.ReadFile(fileName)
743753
if readErr != nil {
744-
return nil, nil, fmt.Errorf("error reading file %s: %w", fileName, readErr)
754+
if errors.Is(readErr, os.ErrNotExist) {
755+
slog.DebugContext(ctx, "Unable to backup file contents since file does not exist", "file", fileName)
756+
continue
757+
} else {
758+
return nil, nil, fmt.Errorf("error reading file %s: %w", fileName, readErr)
759+
}
745760
}
746761
fileContents[fileName] = fileContent
747762

internal/file/file_manager_service_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ func TestFileManagerService_Rollback(t *testing.T) {
559559
}
560560

561561
func TestFileManagerService_DetermineFileActions(t *testing.T) {
562+
ctx := context.Background()
562563
tempDir := os.TempDir()
563564

564565
deleteTestFile := helpers.CreateFileWithErrorCheck(t, tempDir, "nginx_delete.conf")
@@ -584,7 +585,6 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
584585

585586
addTestFile := helpers.CreateFileWithErrorCheck(t, tempDir, "nginx_add.conf")
586587
defer helpers.RemoveFileWithErrorCheck(t, addTestFile.Name())
587-
t.Logf("Adding file: %s", addTestFile.Name())
588588
addFileContent := []byte("test add file")
589589
addErr := os.WriteFile(addTestFile.Name(), addFileContent, 0o600)
590590
require.NoError(t, addErr)
@@ -694,6 +694,18 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
694694
expectedContent: make(map[string][]byte),
695695
expectedError: nil,
696696
},
697+
{
698+
name: "Test 3: File being deleted already doesn't exist",
699+
modifiedFiles: make(map[string]*model.FileCache),
700+
currentFiles: map[string]*mpi.File{
701+
"/unknown/file.conf": {
702+
FileMeta: protos.FileMeta("/unknown/file.conf", files.GenerateHash(fileContent)),
703+
},
704+
},
705+
expectedCache: make(map[string]*model.FileCache),
706+
expectedContent: make(map[string][]byte),
707+
expectedError: nil,
708+
},
697709
}
698710

699711
for _, test := range tests {
@@ -711,8 +723,11 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
711723

712724
require.NoError(tt, err)
713725

714-
diff, contents, fileActionErr := fileManagerService.DetermineFileActions(test.currentFiles,
715-
test.modifiedFiles)
726+
diff, contents, fileActionErr := fileManagerService.DetermineFileActions(
727+
ctx,
728+
test.currentFiles,
729+
test.modifiedFiles,
730+
)
716731
require.NoError(tt, fileActionErr)
717732
assert.Equal(tt, test.expectedContent, contents)
718733
assert.Equal(tt, test.expectedCache, diff)

internal/file/filefakes/fake_file_manager_service_interface.go

Lines changed: 14 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)