Skip to content

Commit

Permalink
improve docker container usage (#1704)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ngehrsitz and Norman Gehrsitz committed Nov 16, 2023
1 parent c7c63fc commit 0ade78c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +22,9 @@ 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 .
COPY --from=builder /app/swag /bin/swag

ENTRYPOINT ["/bin/swag"]
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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`).
Expand Down

0 comments on commit 0ade78c

Please sign in to comment.