2022-07-18 07:58:46 +00:00
|
|
|
FROM golang:1.18.4-alpine AS builder
|
2021-10-19 16:17:21 +00:00
|
|
|
WORKDIR /go/src/github.com/tus/tusd
|
2017-05-29 21:21:53 +00:00
|
|
|
|
2021-10-19 16:17:21 +00:00
|
|
|
# Add gcc and libc-dev early so it is cached
|
|
|
|
RUN set -xe \
|
|
|
|
&& apk add --no-cache gcc libc-dev
|
2017-05-29 21:21:53 +00:00
|
|
|
|
2021-10-19 16:17:21 +00:00
|
|
|
# Install dependencies earlier so they are cached between builds
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
RUN set -xe \
|
|
|
|
&& go mod download
|
2017-05-29 21:21:53 +00:00
|
|
|
|
2021-10-19 16:17:21 +00:00
|
|
|
# Copy the source code, because directories are special, there are separate layers
|
|
|
|
COPY cmd/ ./cmd/
|
|
|
|
COPY internal/ ./internal/
|
|
|
|
COPY pkg/ ./pkg/
|
2017-05-29 21:21:53 +00:00
|
|
|
|
2021-10-19 16:17:21 +00:00
|
|
|
# Get the version name and git commit as a build argument
|
|
|
|
ARG GIT_VERSION
|
|
|
|
ARG GIT_COMMIT
|
2019-01-04 21:40:22 +00:00
|
|
|
|
2021-10-19 16:17:21 +00:00
|
|
|
RUN set -xe \
|
|
|
|
&& GOOS=linux GOARCH=amd64 go build \
|
|
|
|
-ldflags="-X github.com/tus/tusd/cmd/tusd/cli.VersionName=${GIT_VERSION} -X github.com/tus/tusd/cmd/tusd/cli.GitCommit=${GIT_COMMIT} -X 'github.com/tus/tusd/cmd/tusd/cli.BuildDate=$(date --utc)'" \
|
|
|
|
-o /go/bin/tusd ./cmd/tusd/main.go
|
|
|
|
|
|
|
|
# start a new stage that copies in the binary built in the previous stage
|
2022-05-30 12:23:26 +00:00
|
|
|
FROM alpine:3.16.0
|
2021-10-19 16:17:21 +00:00
|
|
|
WORKDIR /srv/tusd-data
|
2019-01-04 21:40:22 +00:00
|
|
|
|
2021-10-19 16:17:21 +00:00
|
|
|
RUN apk add --no-cache ca-certificates jq \
|
2019-01-13 23:08:03 +00:00
|
|
|
&& addgroup -g 1000 tusd \
|
2019-01-04 21:40:22 +00:00
|
|
|
&& adduser -u 1000 -G tusd -s /bin/sh -D tusd \
|
|
|
|
&& mkdir -p /srv/tusd-hooks \
|
|
|
|
&& chown tusd:tusd /srv/tusd-data
|
|
|
|
|
2021-10-19 16:17:21 +00:00
|
|
|
COPY --from=builder /go/bin/tusd /usr/local/bin/tusd
|
2019-06-13 09:58:16 +00:00
|
|
|
|
2021-10-19 16:17:21 +00:00
|
|
|
EXPOSE 1080
|
2019-06-13 09:58:16 +00:00
|
|
|
USER tusd
|
2021-10-19 16:17:21 +00:00
|
|
|
|
|
|
|
ENTRYPOINT ["tusd"]
|
|
|
|
CMD [ "--hooks-dir", "/srv/tusd-hooks" ]
|