2022-10-10 06:21:34 +00:00
|
|
|
FROM golang:1.19.2-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/
|
2023-01-15 20:35:08 +00:00
|
|
|
COPY examples/ ./examples/
|
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
|
|
|
|
|
2023-01-15 20:35:08 +00:00
|
|
|
RUN set -xe \
|
|
|
|
&& GOOS=linux GOARCH=amd64 go build \
|
|
|
|
-o /go/bin/hooks_handler ./examples/hooks/plugin/hook_handler.go
|
|
|
|
|
2021-10-19 16:17:21 +00:00
|
|
|
# start a new stage that copies in the binary built in the previous stage
|
2022-08-16 09:00:06 +00:00
|
|
|
FROM alpine:3.16.2
|
2021-10-19 16:17:21 +00:00
|
|
|
WORKDIR /srv/tusd-data
|
2019-01-04 21:40:22 +00:00
|
|
|
|
2022-09-19 07:34:37 +00:00
|
|
|
COPY ./docker/entrypoint.sh /usr/local/share/docker-entrypoint.sh
|
|
|
|
COPY ./docker/load-env.sh /usr/local/share/load-env.sh
|
|
|
|
|
|
|
|
RUN apk add --no-cache ca-certificates jq bash \
|
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 \
|
2022-09-19 07:34:37 +00:00
|
|
|
&& chown tusd:tusd /srv/tusd-data \
|
|
|
|
&& chmod +x /usr/local/share/docker-entrypoint.sh /usr/local/share/load-env.sh
|
2019-01-04 21:40:22 +00:00
|
|
|
|
2021-10-19 16:17:21 +00:00
|
|
|
COPY --from=builder /go/bin/tusd /usr/local/bin/tusd
|
2023-01-15 20:35:08 +00:00
|
|
|
COPY --from=builder /go/bin/hooks_handler /usr/local/bin/hooks_handler
|
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
|
|
|
|
2022-09-19 07:34:37 +00:00
|
|
|
ENTRYPOINT ["/usr/local/share/docker-entrypoint.sh"]
|
2021-10-19 16:17:21 +00:00
|
|
|
CMD [ "--hooks-dir", "/srv/tusd-hooks" ]
|