SebastiaanKlippert / go-wkhtmltopdf

Golang commandline wrapper for wkhtmltopdf
MIT License
1.06k stars 146 forks source link

Can't create Docker build #105

Closed HiperJava closed 1 year ago

HiperJava commented 1 year ago

I was implemented my code. I was put go-wlhtmltopdf to Dockerfile. But i can't build this

make[1]: Leaving directory '/app'
# github.com/SebastiaanKlippert/go-wkhtmltopdf
/go/pkg/mod/github.com/!sebastiaan!klippert/go-wkhtmltopdf@v1.8.2/wkhtmltopdf.go:274:25: undefined: exec.ErrDot
/go/pkg/mod/github.com/!sebastiaan!klippert/go-wkhtmltopdf@v1.8.2/wkhtmltopdf.go:287:25: undefined: exec.ErrDot
############################
# STEP 1 build executable binary
############################
FROM golang:1.17-alpine AS builder

ENV GOLANG_MIGRATE_VERSION v4.2.5
ENV APPLICATION_SWAGGER_API_DOCS_DIR /etc/api-docs
ENV APPLICATION_SWAGGER_FILE swagger.json
ARG GITLAB_USER
ARG GITLAB_TOKEN

# Install git.
# Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git ca-certificates tzdata curl && update-ca-certificates \
    ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-ubuntu-font-family go-wkhtmltopdf

# Create appuser.
RUN adduser -D -g '' appuser

RUN git config \
      --global \
      url."https://${GITLAB_USER}:${GITLAB_TOKEN}@gitlab.com".insteadOf \
      "https://gitlab.com"

# Download golang migrate
RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@$GOLANG_MIGRATE_VERSION \
    && go get -v -u github.com/lib/pq \
    && go get -v -u github.com/hashicorp/go-multierror

RUN mkdir -p /go/src/github.com
WORKDIR /go/src/github.com
RUN git clone https://github.com/go-swagger/go-swagger
WORKDIR /go/src/github.com/go-swagger
RUN git checkout v0.25.0
RUN go install -ldflags "-X github.com/go-swagger/go-swagger/cmd/swagger/commands.Version=$(git describe --tags) -X github.com/go-swagger/go-swagger/cmd/swagger/commands.Commit=$(git rev-parse HEAD)" ./cmd/swagger

# Select base application folder
WORKDIR /go/src/gitlab.com/********/******/wallet

# Copy files
COPY ./ /go/src/gitlab.com/*******/*********/wallet
COPY ./resources/changelogs /etc/changelogs
COPY ./resources/permissions /etc/permissions
COPY ./resources/config /etc/config
COPY ./resources/fonts /etc/fonts
COPY ./resources/template /etc/template

# Fetch dependencies.
# TODO  - [swagger-go-mod] - swagger does not support go modules yet, use go mod download when its get available
# Using go get.
RUN go mod tidy

# TODO - [swagger-go-mod] - remove GO111MODULE=off
RUN mkdir -p ${APPLICATION_SWAGGER_API_DOCS_DIR} && \
    GIT_TERMINAL_PROMPT=1 GO111MODULE=on GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go mod vendor && \
    GIT_TERMINAL_PROMPT=1 GO111MODULE=off GOOS=linux CGO_ENABLED=0 GOARCH=amd64 /go/bin/swagger generate spec \
        -o ${APPLICATION_SWAGGER_API_DOCS_DIR}/${APPLICATION_SWAGGER_FILE} -m --compact && \
    cat ${APPLICATION_SWAGGER_API_DOCS_DIR}/${APPLICATION_SWAGGER_FILE}

# Build the binary.
RUN GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -tags=timetzdata -ldflags="-w -s" -o /go/bin/wallet

############################
# STEP 2 build a small image
############################
FROM bash:5

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

RUN apk add --update --no-cache ca-certificates \
    ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-freefont go-wkhtmltopdf

RUN adduser -D -g '' appuser

# Import the user and group files from the builder.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/template /etc/template

# Copy our static executable.
COPY --from=builder /go/bin/wallet /go/bin/wallet

# Copy configs from builder.
COPY --from=builder /etc /etc

# Use an unprivileged user.
USER appuser

COPY --from=builder /go/bin/migrate /go/bin/migrate
COPY --from=builder /go/src/gitlab.com/*******/*********/wallet/docker-entrypoint.sh /docker-entrypoint.sh
COPY --from=stemxcli /go/bin/****-cli /go/bin/****-cli
COPY --from=envoy-preflight /go/bin/envoy-preflight /go/bin/envoy-preflight

# Run the hello binary.
ENTRYPOINT ["./docker-entrypoint.sh"]

Any idea?

SebastiaanKlippert commented 1 year ago

I see this is closed, but for anyone else getting this error: You are using Go 1.17 FROM golang:1.17-alpine AS builder You will need Go 1.19 or later to build this version of my package, or use an older version of this repository. Version 1.7.1 should work.