diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 414a64e1a..5a53d485d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -107,3 +107,21 @@ jobs: - name: Run tests run: cd examples && go test ./... + + ensure-docker: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Build image + run: | + docker build . \ + --tag ghcr.io/$GITHUB_REPOSITORY:$GITHUB_SHA + + - name: Check image + run: | + docker run \ + -v ./_testdata/examples/petstore.yml:/petstore.yml \ + --rm \ + ghcr.io/$GITHUB_REPOSITORY:$GITHUB_SHA /petstore.yml diff --git a/Dockerfile b/Dockerfile index d5fba04a8..ab6017195 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,16 @@ ARG GO_VERSION=latest -FROM golang:$GO_VERSION as builder - +FROM golang:$GO_VERSION AS builder WORKDIR /go/src/app - COPY . . - RUN go mod download - RUN CGO_ENABLED=0 go build -o /go/bin/ogen ./cmd/ogen/main.go FROM scratch - +# We need go in resulting image to run goimports. +COPY --from=builder /usr/local/go/ /usr/local/go/ +ENV PATH="/usr/local/go/bin:${PATH}" +# Copy built binary. WORKDIR / - COPY --from=builder /go/bin/ogen ./ogen - ENTRYPOINT ["./ogen"]