Skip to content

Commit fd273f1

Browse files
committed
builder: Copy file to existing dir
Signed-off-by: Stefan Prodan <[email protected]>
1 parent c1a5759 commit fd273f1

File tree

5 files changed

+302
-212
lines changed

5 files changed

+302
-212
lines changed
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
---
21
apiVersion: source.extensions.fluxcd.io/v1beta1
32
kind: ArtifactGenerator
43
metadata:
54
name: app-gen
65
spec:
76
sources:
8-
- alias: oci
9-
kind: OCIRepository
10-
name: podinfo-oci
11-
- alias: repo
7+
- alias: git
128
kind: GitRepository
139
name: podinfo-repo
1410
artifacts:
15-
- name: podinfo-svc
11+
- name: podinfo-frontend
1612
copy:
17-
- from: "@repo/kustomize/service.yaml"
18-
to: "@artifact/service.yaml"
19-
- name: podinfo-deploy
13+
- from: "@git/deploy/bases/frontend/"
14+
to: "@artifact/"
15+
- name: podinfo-backend
2016
copy:
21-
- from: "@repo/kustomize/deployment.yaml"
22-
to: "@artifact/deployment.yaml"
17+
- from: "@git/deploy/bases/backend/*.yaml"
18+
to: "@artifact/"
19+
- name: podinfo-cache
20+
copy:
21+
- from: "@git/deploy/bases/cache/**"
22+
to: "@artifact/"
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
---
22
apiVersion: source.toolkit.fluxcd.io/v1
3-
kind: OCIRepository
4-
metadata:
5-
name: podinfo-oci
6-
spec:
7-
interval: 10m
8-
url: oci://ghcr.io/stefanprodan/manifests/podinfo
9-
ref:
10-
semver: ">=6.9.0"
11-
---
12-
apiVersion: source.toolkit.fluxcd.io/v1
133
kind: GitRepository
144
metadata:
155
name: podinfo-repo
166
spec:
177
interval: 10m
188
url: https://github.com/stefanprodan/podinfo
199
ref:
20-
semver: ">=6.9.0"
10+
semver: "*"

internal/builder/builder.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func applySingleSourceCopy(ctx context.Context,
225225
}
226226

227227
// applySingleFileCopy handles copying a single file using cp-like semantics:
228-
// - file -> dest (no slash) = copy to dest as filename
228+
// - file -> dest (no slash) = copy to dest as filename or dest/filename if dest is an existing directory
229229
// - file -> dest/ (with slash) = copy to dest/filename
230230
func applySingleFileCopy(ctx context.Context,
231231
srcRoot *os.Root,
@@ -240,8 +240,14 @@ func applySingleFileCopy(ctx context.Context,
240240
srcFileName := filepath.Base(srcPath)
241241
finalDestPath = filepath.Join(destPath, srcFileName)
242242
} else {
243-
// Destination is the target filename
244-
finalDestPath = destPath
243+
// Check if destination path already exists as a directory
244+
if destInfo, err := stagingRoot.Stat(destPath); err == nil && destInfo.IsDir() {
245+
srcFileName := filepath.Base(srcPath)
246+
finalDestPath = filepath.Join(destPath, srcFileName)
247+
} else {
248+
// Destination is the target filename
249+
finalDestPath = destPath
250+
}
245251
}
246252

247253
return copyFileWithRoots(ctx, srcRoot, srcPath, stagingRoot, finalDestPath)

0 commit comments

Comments
 (0)