Skip to content

Commit

Permalink
Merge pull request #162 from blackpiglet/replace_busybox_v0.5
Browse files Browse the repository at this point in the history
[cherry-pick][release-0.5]Replace busybox with internal copy binary.
  • Loading branch information
blackpiglet authored Apr 18, 2023
2 parents 0f44f66 + a304b12 commit b50251e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM busybox@sha256:91540637a8c1bd8374832a77bb11ec286c9599ff8b528d69794f5dea6e257fd9 AS busybox

FROM scratch
ADD cp-plugin /bin/cp-plugin
ADD velero-plugin-for-csi /plugins/
COPY --from=busybox /bin/cp /bin/cp
USER 65532:65532
ENTRYPOINT ["cp", "/plugins/velero-plugin-for-csi", "/target/."]
ENTRYPOINT ["/bin/cp-plugin", "/plugins/velero-plugin-for-csi", "/target/velero-plugin-for-csi"]
1 change: 1 addition & 0 deletions changelogs/CHANGELOG-0.5.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### All Changes

* Replace busybox with internal copy binary. (#162, @blackpiglet)
* When restorePVs is false, CSI should restore the PVC. (#154, @blackpiglet)
* Bump the Golang version to v1.19 for the GCP plugin's main branch. (#153, @blackpiglet)
* Update golang.org/x/net to fix CVE. (#149, @blackpiglet)
Expand Down
3 changes: 3 additions & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export CGO_ENABLED=0
if [[ -z "${OUTPUT_DIR:-}" ]]; then
OUTPUT_DIR=.
fi

OUTPUT=${OUTPUT_DIR}/${BIN}
if [[ "${GOOS}" = "windows" ]]; then
OUTPUT="${OUTPUT}.exe"
Expand All @@ -46,3 +47,5 @@ go build \
-installsuffix "static" \
-mod=readonly \
./

CGO_ENABLED=0 go build -v -o ${OUTPUT_DIR}/cp-plugin ./hack/cp-plugin
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 b50251e

Please sign in to comment.