From ca919744292ef8ab5cbfd09b3dadbccbe2a0fc83 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Tue, 8 Aug 2023 14:44:47 -0700 Subject: [PATCH] Build webserver using ko-build --- README.md | 4 +++- webserver/Dockerfile | 4 ---- webserver/README.md | 4 +++- webserver/build.sh | 15 +++++---------- webserver/cmd/go.mod | 3 +++ webserver/manifest.sh | 11 ----------- 6 files changed, 14 insertions(+), 27 deletions(-) delete mode 100644 webserver/Dockerfile create mode 100644 webserver/cmd/go.mod delete mode 100755 webserver/manifest.sh diff --git a/README.md b/README.md index c23b608..881f95f 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,9 @@ The containers are stored on my gitea instance, so you can pull them like this: docker pull gitea.elara.ws/elara6331/golang:latest ``` +Some of the images use [ko.build](https://github.com/ko-build/ko) + ### Images - `golang`: An alpine-based image with Go installed -- `webserver`: A very simple webserver \ No newline at end of file +- `webserver`: A very simple webserver diff --git a/webserver/Dockerfile b/webserver/Dockerfile deleted file mode 100644 index c6472ad..0000000 --- a/webserver/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM busybox:latest -COPY webserver /usr/bin/webserver -RUN mkdir /html -ENTRYPOINT webserver \ No newline at end of file diff --git a/webserver/README.md b/webserver/README.md index 94cc1fc..2feb384 100644 --- a/webserver/README.md +++ b/webserver/README.md @@ -2,4 +2,6 @@ The [webserver image](https://gitea.elara.ws/Elara6331/-/packages/container/webserver/latest) is a very simple webserver that serves its `/html` directory and logs requests. It doesn't have any TLS capabilities or anything like that, it just serves some static files and does nothing else. -You can change the address it listens on using the `WEBSERVER_ADDR` environment variable. \ No newline at end of file +You can change the address it listens on using the `WEBSERVER_ADDR` environment variable. + +This image uses [ko.build](https://ko.build) diff --git a/webserver/build.sh b/webserver/build.sh index 6e33f8f..95a6c9f 100755 --- a/webserver/build.sh +++ b/webserver/build.sh @@ -1,12 +1,7 @@ #!/bin/bash -if [[ $# == 0 ]]; then - echo "Usage: $0 " - exit 1 -fi - -GOOS=linux GOARCH=$1 go build -o webserver ./cmd/main.go - -docker login gitea.elara.ws -docker build . -t "gitea.elara.ws/elara6331/webserver:$1" -docker push "gitea.elara.ws/elara6331/webserver:$1" +pushd cmd +KO_DOCKER_REPO=gitea.elara.ws/elara6331 ko build -B \ + --platform=linux/amd64,linux/arm64,linux/riscv64 \ + --sbom=none +popd diff --git a/webserver/cmd/go.mod b/webserver/cmd/go.mod new file mode 100644 index 0000000..293f5a3 --- /dev/null +++ b/webserver/cmd/go.mod @@ -0,0 +1,3 @@ +module webserver + +go 1.21.0 diff --git a/webserver/manifest.sh b/webserver/manifest.sh deleted file mode 100755 index 11456c1..0000000 --- a/webserver/manifest.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -tag="$1" -tag="${tag:=latest}" - -docker login gitea.elara.ws -docker manifest create "gitea.elara.ws/elara6331/webserver:$tag" \ - --amend gitea.elara.ws/elara6331/webserver:amd64 \ - --amend gitea.elara.ws/elara6331/webserver:arm64 \ - --amend gitea.elara.ws/elara6331/webserver:riscv64 -docker manifest push "gitea.elara.ws/elara6331/webserver:$tag"