From b8bf9de3ecc328f494cf660820a0ac2c62027948 Mon Sep 17 00:00:00 2001 From: Ada Date: Sat, 17 Feb 2024 22:02:11 +0100 Subject: [PATCH] Docker support & image --- .woodpecker/build.yaml | 17 +++++++++++++++++ docker/Dockerfile | 21 +++++++++++++++++++++ docker/docker-compose.dev.yaml | 12 ++++++++++++ docker/docker-compose.yaml | 18 ++++++++++++++++++ docker/serve.go | 9 +++++++++ 5 files changed, 77 insertions(+) create mode 100644 .woodpecker/build.yaml create mode 100644 docker/Dockerfile create mode 100644 docker/docker-compose.dev.yaml create mode 100644 docker/docker-compose.yaml create mode 100644 docker/serve.go diff --git a/.woodpecker/build.yaml b/.woodpecker/build.yaml new file mode 100644 index 0000000..ed6024f --- /dev/null +++ b/.woodpecker/build.yaml @@ -0,0 +1,17 @@ +steps: + - name: publish_image + image: woodpeckerci/plugin-docker-buildx + settings: + repo: git.gnous.eu/${CI_REPO_OWNER}/wiki + dockerfile: docker/Dockerfile + platforms: linux/amd64 + registry: https://git.gnous.eu + tag: ${CI_COMMIT} + username: + from_secret: docker_username + password: + from_secret: docker_password + when: + branch: ${CI_REPO_DEFAULT_BRANCH} + event: push + diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..e08047a --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:1.22 as build + +WORKDIR /build +COPY . . + +RUN wget https://github.com/rust-lang/mdBook/releases/download/v0.4.37/mdbook-v0.4.37-x86_64-unknown-linux-gnu.tar.gz +RUN tar xvf mdbook-v0.4.37-x86_64-unknown-linux-gnu.tar.gz +RUN ./mdbook build + +RUN CGO_ENABLED=0 go build -ldflags "-w -s" docker/serve.go + +FROM gcr.io/distroless/static-debian12:nonroot + +WORKDIR /app + +COPY --from=build /build/serve . +COPY --from=build /build/book/ static/ + +EXPOSE 3000 + +CMD ["/app/serve"] \ No newline at end of file diff --git a/docker/docker-compose.dev.yaml b/docker/docker-compose.dev.yaml new file mode 100644 index 0000000..6ef0df0 --- /dev/null +++ b/docker/docker-compose.dev.yaml @@ -0,0 +1,12 @@ +version: "3" + +services: + www: + build: + context: ../ + dockerfile: docker/Dockerfile + restart: always + container_name: www + ports: + - "3000:3000" + diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml new file mode 100644 index 0000000..bd17832 --- /dev/null +++ b/docker/docker-compose.yaml @@ -0,0 +1,18 @@ +version: "3" + +networks: + plakken: + external: false + +volumes: + redis: + driver: local + +services: + server: + image: git.gnous.eu/gnouseu/wiki:latest + restart: always + container_name: plakken + read_only: true + ports: + - "3000:3000" diff --git a/docker/serve.go b/docker/serve.go new file mode 100644 index 0000000..37c15c9 --- /dev/null +++ b/docker/serve.go @@ -0,0 +1,9 @@ +package main + +import "net/http" + +func main() { + fs := http.FileServer(http.Dir("./static")) + http.Handle("GET /", fs) + http.ListenAndServe(":3000", nil) +}