From c3cd451645e50920106959720c86751d4e0372dd Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz Date: Wed, 15 Nov 2023 00:33:01 +0100 Subject: [PATCH 1/6] Update Go build version for Docker container --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 170d0c699..c36b9fa1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Dockerfile References: https://docs.docker.com/engine/reference/builder/ # Start from the latest golang base image -FROM golang:1.18.3-alpine as builder +FROM golang:1.20-alpine as builder # Set the Current Working Directory inside the container WORKDIR /app From d26ec0e743c23f584546e5fc4236c183109cd5c4 Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz Date: Wed, 15 Nov 2023 00:28:23 +0100 Subject: [PATCH 2/6] Explicitly specify copy target --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c36b9fa1e..aac218b8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,4 +25,4 @@ FROM scratch WORKDIR /root/ # Copy the Pre-built binary file from the previous stage -COPY --from=builder /app/swag . +COPY --from=builder /app/swag /root/swag From 1a9bec7162b87c82d3826d1a194defdeea27cf04 Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz Date: Wed, 15 Nov 2023 00:29:05 +0100 Subject: [PATCH 3/6] Set ENTRYPOINT --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index aac218b8c..8fffc831c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,3 +26,5 @@ WORKDIR /root/ # Copy the Pre-built binary file from the previous stage COPY --from=builder /app/swag /root/swag + +ENTRYPOINT ["/root/swag"] From 7345755cdf912fee5944687f1d1a4964c93d97d5 Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz Date: Wed, 15 Nov 2023 00:30:23 +0100 Subject: [PATCH 4/6] Move binary to /bin --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8fffc831c..17c276537 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,6 @@ FROM scratch WORKDIR /root/ # Copy the Pre-built binary file from the previous stage -COPY --from=builder /app/swag /root/swag +COPY --from=builder /app/swag /bin/swag -ENTRYPOINT ["/root/swag"] +ENTRYPOINT ["/bin/swag"] From 9f4f31ccffe848101d7ed81331e2f6ea0bcd725d Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz Date: Wed, 15 Nov 2023 00:40:58 +0100 Subject: [PATCH 5/6] Add docker usage instructions to the README --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b3c26eca5..9d8769c9e 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,17 @@ Swag converts Go annotations to Swagger Documentation 2.0. We've created a varie 1. Add comments to your API source code, See [Declarative Comments Format](#declarative-comments-format). -2. Download swag by using: +2. Install swag by using: ```sh go install github.com/swaggo/swag/cmd/swag@latest ``` To build from source you need [Go](https://golang.org/dl/) (1.17 or newer). +Alternatively you can run the docker image: +```sh +docker run --rm -v $(pwd):/code -w /code ghcr.io/swaggo/swag:latest +``` + Or download a pre-compiled binary from the [release page](https://github.com/swaggo/swag/releases). 3. Run `swag init` in the project's root folder which contains the `main.go` file. This will parse your comments and generate the required files (`docs` folder and `docs/docs.go`). From f8eee2f18de38e30673305ba9311091aae69e8c0 Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz Date: Wed, 15 Nov 2023 00:46:00 +0100 Subject: [PATCH 6/6] Set /code as the default WORKDIR --- Dockerfile | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 17c276537..410fe31ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -o swag cmd/swag/ ######## Start a new stage from scratch ####### FROM scratch -WORKDIR /root/ +WORKDIR /code/ # Copy the Pre-built binary file from the previous stage COPY --from=builder /app/swag /bin/swag diff --git a/README.md b/README.md index 9d8769c9e..05462671c 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ To build from source you need [Go](https://golang.org/dl/) (1.17 or newer). Alternatively you can run the docker image: ```sh -docker run --rm -v $(pwd):/code -w /code ghcr.io/swaggo/swag:latest +docker run --rm -v $(pwd):/code ghcr.io/swaggo/swag:latest ``` Or download a pre-compiled binary from the [release page](https://github.com/swaggo/swag/releases).