diff --git a/Makefile b/Makefile index dcb7319..9912510 100644 --- a/Makefile +++ b/Makefile @@ -35,3 +35,9 @@ out/go.oci.tgz: \ out/bash.oci.tgz \ out/musl.oci.tgz docker build -t ocirep/go --output type=oci,dest=$@ packages/go + +test: + docker build -t ocirep/go_hello examples/go_hello + @printf "\nOcirep Test Suite\n" + @printf "go_hello -> " + @docker run -i ocirep/go_hello | grep Success diff --git a/examples/go_hello/Dockerfile b/examples/go_hello/Dockerfile new file mode 100644 index 0000000..300ea24 --- /dev/null +++ b/examples/go_hello/Dockerfile @@ -0,0 +1,14 @@ +FROM ocirep/busybox as build +COPY --from=ocirep/go . / +COPY . . +RUN \ + go build main.go \ + && mkdir -p $HOME/rootfs/etc \ + && echo "nogroup:*:100:nobody" > ~/rootfs/etc/group \ + && echo "nobody:*:100:100:::" > ~/rootfs/etc/passwd \ + && cp main $HOME/rootfs/ + +FROM scratch +COPY --from=build --chown=100:100 /home/user/rootfs / +USER 100:100 +ENTRYPOINT ["/main"] diff --git a/examples/go_hello/main.go b/examples/go_hello/main.go new file mode 100644 index 0000000..5da4e06 --- /dev/null +++ b/examples/go_hello/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Success") +} diff --git a/examples/go_http_hello/Dockerfile b/examples/go_http_hello/Dockerfile deleted file mode 100644 index 2c165f1..0000000 --- a/examples/go_http_hello/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -ARG GO_IMAGE=ocirep:go -FROM ${GO_IMAGE} as build -COPY . . -RUN \ - go build main.go \ - && mkdir -p rootfs/etc \ - && echo "nogroup:*:100:nobody" > ~/rootfs/etc/group \ - && echo "nobody:*:100:100:::" > ~/rootfs/etc/passwd \ - && cp main rootfs/ - -ARG CA_IMAGE=ocirep:ca-certificates -FROM scratch -COPY --from=${CA_IMAGE} / -COPY --from=build --chown=100:100 rootfs / -USER 100:100 -EXPOSE 8080 -ENTRYPOINT main diff --git a/examples/go_http_hello/main.go b/examples/go_http_hello/main.go deleted file mode 100644 index e2f0c6d..0000000 --- a/examples/go_http_hello/main.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "fmt" - "net/http" -) - -func main() { - http.HandleFunc("/", HelloServer) - http.ListenAndServe(":8080", nil) -} - -func HelloServer(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:]) -}