-
Notifications
You must be signed in to change notification settings - Fork 22
/
Dockerfile
122 lines (95 loc) · 4.04 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Those vars are used broadly outside this Dockerfile
# Github Action CI and release script (./utility.sh) is consuming these variables.
ARG VERSION="1.51.0"
ARG RELEASE="1.51.0-r1"
ARG APP_NAME="rclone"
ARG GITHUB_USER="firepress-org"
#
ARG ALPINE_VERSION="3.11"
#
ARG DOCKERHUB_USER="devmtl"
ARG GITHUB_ORG="firepress-org"
ARG GITHUB_REGISTRY="registry"
#
ARG GIT_REPO_DOCKERFILE="https://github.com/firepress-org/rclone-in-docker"
ARG GIT_REPO_SOURCE="https://github.com/rclone/rclone"
# ----------------------------------------------
# BASE IMAGE VERSIONNING LAYER
# ----------------------------------------------
FROM alpine:${ALPINE_VERSION} AS myalpine
FROM golang:alpine${ALPINE_VERSION} AS mygolang
# Credit to Tõnis Tiigi / https://bit.ly/2RoCmvG
# ----------------------------------------------
# ALPINEBASE LAYER
# ----------------------------------------------
FROM myalpine AS alpinebase
ARG APP_NAME
ARG VERSION
ARG ALPINE_VERSION
ARG GIT_REPO_DOCKERFILE
ARG GIT_REPO_SOURCE
ENV APP_NAME="${APP_NAME}"
ENV VERSION="${VERSION}"
ENV GIT_REPO_DOCKERFILE="${GIT_REPO_DOCKERFILE}"
ENV GIT_REPO_SOURCE="${GIT_REPO_SOURCE}"
ENV ALPINE_VERSION="${ALPINE_VERSION}"
ENV CREATED_DATE="$(date "+%Y-%m-%d_%HH%Ms%S")"
ENV SOURCE_COMMIT="$(git rev-parse --short HEAD)"
# Install basics
RUN set -eux && apk --update --no-cache add \
ca-certificates tini
# Best practice credit: https://github.com/opencontainers/image-spec/blob/master/annotations.md
LABEL org.opencontainers.image.title="${APP_NAME}" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.description="See README.md" \
org.opencontainers.image.authors="Pascal Andy https://firepress.org/en/contact/" \
org.opencontainers.image.created="${CREATED_DATE}" \
org.opencontainers.image.revision="${SOURCE_COMMIT}" \
org.opencontainers.image.source="${GIT_REPO_DOCKERFILE}" \
org.opencontainers.image.licenses="GNUv3. See README.md" \
org.firepress.image.alpineversion="{ALPINE_VERSION}" \
org.firepress.image.field1="not_set" \
org.firepress.image.field2="not_set" \
org.firepress.image.schemaversion="1.0"
# ----------------------------------------------
# UPGRADE LAYER
# The point is to keep trace of logs our CI
# ----------------------------------------------
FROM alpinebase AS what-to-upgrade
RUN set -eux && apk update && apk upgrade
# ----------------------------------------------
# BUILDER LAYER
# ----------------------------------------------
FROM mygolang AS gobuilder
ARG APP_NAME
ARG VERSION
ARG GIT_REPO_SOURCE
ENV APP_NAME="${APP_NAME}"
ENV VERSION="${VERSION}"
ENV GIT_REPO_SOURCE="${GIT_REPO_SOURCE}"
# Install common utilities
RUN set -eux && apk --update --no-cache add \
bash wget curl git openssl ca-certificates upx
# Install common Go dependencies
RUN set -eux && apk --update --no-cache add \
-t build-deps libc-dev gcc libgcc
# Compile Go app
WORKDIR /go/src/github.com/rclone/rclone
RUN git clone "${GIT_REPO_SOURCE}" --single-branch --depth 1 -b "v${VERSION}" . && \
git checkout -b "v${VERSION}" && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /usr/local/bin/"${APP_NAME}"
# Compress binary
RUN upx /usr/local/bin/"${APP_NAME}" && \
upx -t /usr/local/bin/"${APP_NAME}" && \
rclone --version
# ----------------------------------------------
# FINAL LAYER
# ----------------------------------------------
FROM alpinebase AS final
ARG APP_NAME
ENV APP_NAME="${APP_NAME}"
COPY --from=gobuilder /usr/local/bin/"${APP_NAME}" /usr/local/bin/"${APP_NAME}"
WORKDIR /usr/local/bin
VOLUME [ "/root/.config/rclone", "/data" ]
ENTRYPOINT [ "/sbin/tini", "--" ]
CMD [ "rclone", "--version" ]