Skip to content

Commit 0ade78c

Browse files
ngehrsitzNorman Gehrsitz
and
Norman Gehrsitz
authored
improve docker container usage (#1704)
* Update Go build version for Docker container * Explicitly specify copy target * Set ENTRYPOINT * Move binary to /bin * Add docker usage instructions to the README * Set /code as the default WORKDIR --------- Co-authored-by: Norman Gehrsitz <git@gehrsitz.eu>
1 parent c7c63fc commit 0ade78c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Dockerfile

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Dockerfile References: https://docs.docker.com/engine/reference/builder/
22

33
# Start from the latest golang base image
4-
FROM golang:1.18.3-alpine as builder
4+
FROM golang:1.20-alpine as builder
55

66
# Set the Current Working Directory inside the container
77
WORKDIR /app
@@ -22,7 +22,9 @@ RUN CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -o swag cmd/swag/
2222
######## Start a new stage from scratch #######
2323
FROM scratch
2424

25-
WORKDIR /root/
25+
WORKDIR /code/
2626

2727
# Copy the Pre-built binary file from the previous stage
28-
COPY --from=builder /app/swag .
28+
COPY --from=builder /app/swag /bin/swag
29+
30+
ENTRYPOINT ["/bin/swag"]

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,17 @@ Swag converts Go annotations to Swagger Documentation 2.0. We've created a varie
5151

5252
1. Add comments to your API source code, See [Declarative Comments Format](#declarative-comments-format).
5353

54-
2. Download swag by using:
54+
2. Install swag by using:
5555
```sh
5656
go install github.com/swaggo/swag/cmd/swag@latest
5757
```
5858
To build from source you need [Go](https://golang.org/dl/) (1.17 or newer).
5959

60+
Alternatively you can run the docker image:
61+
```sh
62+
docker run --rm -v $(pwd):/code ghcr.io/swaggo/swag:latest
63+
```
64+
6065
Or download a pre-compiled binary from the [release page](https://github.com/swaggo/swag/releases).
6166

6267
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`).

0 commit comments

Comments
 (0)