-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
173 lines (147 loc) · 3.97 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
##################################################
# Notes for GitHub Actions
# * Dockerfile instructions: https://git.io/JfGwP
# * Environment variables: https://git.io/JfGw5
##################################################
#########################
# STAGE: GLOBAL
# Description: Global args for reuse
#########################
ARG PROJECT="pipeprogress"
ARG PROJECT_BIN="pp"
ARG PROJECT_DESC="A command line utility to show progress during pipe operations"
ARG PROJECT_REPO="https://github.com/salt-labs/pipeprogress"
ARG VERSION="0"
ARG TOOLCHAIN="stable"
ARG TARGET="x86_64-unknown-linux-musl"
#########################
# STAGE: BUILD
# Description: Build the app
#########################
FROM docker.io/debian:buster as BUILD
ARG PROJECT
ARG PROJECT_BIN
ARG PROJECT_DESC
ARG PROJECT_REPO
ARG VERSION
ARG TOOLCHAIN
ARG TARGET
ENV DEBIAN_FRONTEND=noninteractive \
RUST_BACKTRACE=1 \
PKG_CONFIG_ALLOW_CROSS=1 \
PKG_CONFIG_ALL_STATIC=1 \
RUSTFLAGS='-C link-arg=-s' \
RUST_LOG="info" \
PATH="/root/.cargo/bin:$PATH"
WORKDIR /
RUN apt update -y \
&& apt upgrade -y \
&& apt install -y \
--no-install-recommends \
autoconf \
automake \
binutils \
build-essential \
ca-certificates \
clang \
cmake \
curl \
file \
g++ \
gcc \
git \
gnupg2 \
jq \
libasound2 \
libasound2-dev \
libgcc-8-dev \
libgmp-dev \
libmpc-dev \
libmpfr-dev \
libpq-dev \
libssl-dev \
libtool \
make \
musl-dev \
musl-tools \
openssh-client \
pkgconf \
tzdata \
unzip \
wget \
xutils-dev \
zlib1g-dev \
&& apt autoremove -y \
&& apt clean -y \
&& rm -rf /var/lib/apt/lists/*
RUN echo "##### Rustup Init #####" \
&& curl \
--proto '=https' \
--tlsv1.2 \
--output rustup-init \
https://sh.rustup.rs \
&& chmod +x rustup-init \
&& ./rustup-init \
-y \
--profile default \
--no-modify-path \
--default-toolchain ${TOOLCHAIN} \
&& rm rustup-init \
&& . ${HOME}/.cargo/env
RUN echo "##### Rustup #####" \
&& rustup target add ${TARGET} \
--toolchain ${TOOLCHAIN} \
&& rustup show
# Hacky trick to stop the crates being built every
# run when they haven't even been changed by putting the
# crates into a seperate layer.
COPY Cargo.lock .
COPY Cargo.toml .
RUN echo "##### Cargo Cache #####" \
&& mkdir src \
&& echo "fn main() {print!(\"Dummy main\");} // dummy file" > src/main.rs \
&& cargo build \
--release \
--target ${TARGET} \
&& rm -f "target/${TARGET}/release/deps/${PROJECT_BIN}"*
ADD . /
RUN echo "##### Cargo Build #####" \
&& cargo build \
--release \
--target ${TARGET} \
--bin ${PROJECT_BIN}
RUN echo "##### Target #####" \
&& ls -lah "/target/${TARGET}/release/" \
&& strip "/target/${TARGET}/release/${PROJECT_BIN}" \
&& ldd "/target/${TARGET}/release/${PROJECT_BIN}" || echo "" \
&& "/target/${TARGET}/release/${PROJECT_BIN}" --help
#########################
# STAGE: RUN
# Description: Run the app
#########################
# Minimal base
FROM gcr.io/distroless/static-debian10 as RUN
# Adds glibc, libssl, openssl
#FROM gcr.io/distroless/base-debian10 as RUN
# Adds libgcc1
#FROM gcr.io/distroless/cc-debian10 as RUN
ARG PROJECT
ARG PROJECT_BIN
ARG PROJECT_DESC
ARG PROJECT_REPO
ARG VERSION
ARG TOOLCHAIN
ARG TARGET
LABEL name="${PROJECT}" \
maintainer="MAHDTech <[email protected]>" \
vendor="Salt Labs" \
version="${VERSION}" \
summary="${PROJECT_DESC}" \
url="${PROJECT_REPO}"
ENV APP=${PROJECT_BIN}
WORKDIR /
COPY --from=BUILD /target/${TARGET}/release/${PROJECT_BIN} /
COPY "LICENSE" "README.md" /
# No shell, no shell expansion
ENTRYPOINT [ "/pp" ]
CMD [ "--help" ]