Skip to content

Commit

Permalink
Merge pull request #181 from reasonerjt/replace-busybox-cp-1.7
Browse files Browse the repository at this point in the history
Replace the cp from busybox - 1.7.x
  • Loading branch information
ywk253100 authored Apr 14, 2023
2 parents 88f64da + 50a0b2f commit 0ea7f33
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ ENV GOOS=${TARGETOS} \
COPY . /go/src/velero-plugin-for-microsoft-azure
WORKDIR /go/src/velero-plugin-for-microsoft-azure
RUN export GOARM=$( echo "${GOARM}" | cut -c2-) && \
CGO_ENABLED=0 go build -v -o /go/bin/velero-plugin-for-microsoft-azure ./velero-plugin-for-microsoft-azure

FROM busybox@sha256:91540637a8c1bd8374832a77bb11ec286c9599ff8b528d69794f5dea6e257fd9 AS busybox
CGO_ENABLED=0 go build -v -o /go/bin/velero-plugin-for-microsoft-azure ./velero-plugin-for-microsoft-azure && \
CGO_ENABLED=0 go build -v -o /go/bin/cp-plugin ./hack/cp-plugin

FROM scratch
COPY --from=build /go/bin/velero-plugin-for-microsoft-azure /plugins/
COPY --from=busybox /bin/cp /bin/cp
COPY --from=build /go/bin/cp-plugin /bin/cp-plugin
USER 65532:65532
ENTRYPOINT ["cp", "/plugins/velero-plugin-for-microsoft-azure", "/target/."]
ENTRYPOINT ["cp", "/plugins/velero-plugin-for-microsoft-azure", "/target/velero-plugin-for-microsoft-azure"]
42 changes: 42 additions & 0 deletions hack/cp-plugin/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"errors"
"fmt"
"io"
"os"
)

func main() {
if len(os.Args) != 3 {
fmt.Println(
`Error: This command requires two arguments.
Usage: cp-plugin src dst`)
os.Exit(1)
}
src, dst := os.Args[1], os.Args[2]
fmt.Printf("Copying %s to %s ... ", src, dst)
srcFile, err := os.Open(src)
if err != nil {
panic(err)
}
defer srcFile.Close()
if _, err := os.Stat(dst); errors.Is(err, os.ErrNotExist) {
_, err = os.Create(dst)
if err != nil {
panic(err)
}
}
dstFile, err := os.OpenFile(dst, os.O_WRONLY, 0755)
if err != nil {
panic(err)
}
defer dstFile.Close()
buf := make([]byte, 1024*128)
_, err = io.CopyBuffer(dstFile, srcFile, buf)
if err != nil {
panic(err)
}
os.Chmod(dst, 0755)
fmt.Println("done.")
}

0 comments on commit 0ea7f33

Please sign in to comment.