-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
147 lines (140 loc) · 5.27 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
# syntax=docker/dockerfile:1
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# https://alpinelinux.org/
# https://hub.docker.com/_/alpine
FROM alpine:3.15 AS fresh
RUN set -o pipefail \
&& function log { echo -e "\e[7;36m$(date +%F_%T)\e[0m\e[1;96m $*\e[0m" > /dev/stderr ; } \
\
# https://wiki.alpinelinux.org/wiki/Alpine_setup_scripts#setup-apkrepos
# https://mirrors.alpinelinux.org/
# https://developer.aliyun.com/mirror/alpine
# https://mirrors.tuna.tsinghua.edu.cn/help/alpine/
&& log "updating apk repositories mirror" \
&& echo "@edgetesting https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
# && sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \
# && sed -i 's/dl-cdn.alpinelinux.org/mirrors.cloud.tencent.com/g' /etc/apk/repositories \
# && sed -i 's/dl-cdn.alpinelinux.org/repo.huaweicloud.com/g' /etc/apk/repositories \
# && sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
&& cat /etc/apk/repositories \
\
# https://docs.alpinelinux.org/user-handbook/0.1a/Working/apk.html
# https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management
# https://wiki.alpinelinux.org/wiki/Comparison_with_other_distros#Comparison_chart.2FRosetta_Stone
# https://pkgs.alpinelinux.org
&& apps="tzdata alpine-conf bash curl iputils docker-cli git openssh-client-default openjdk17 maven jq yq rclone npm py3-pip libc6-compat kubectl@edgetesting helm@edgetesting" \
&& log "installing $apps" \
&& apk add --no-cache $apps \
\
# https://wiki.alpinelinux.org/wiki/Alpine_setup_scripts#setup-timezone
&& log "setting timezone as 'Asia/Shanghai'" \
&& setup-timezone -z Asia/Shanghai \
\
# https://developer.aliyun.com/mirror/NPM
# https://npm.taobao.org/mirrors
&& log "setting npm mirror" \
&& npm config set registry https://registry.npm.taobao.org -g \
&& npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/ -g \
&& npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/ -g \
&& npm config set electron_mirror https://npm.taobao.org/mirrors/electron/ -g \
\
# https://developer.aliyun.com/mirror/pypi
&& log "setting pip mirror" \
&& echo -e '[global]\nindex-url=https://mirrors.aliyun.com/pypi/simple/\ntrusted-host=mirrors.aliyun.com' > /etc/pip.conf \
\
# https://github.com/aliyun/aliyun-cli/releases
&& log "installing latest aliyun-cli" \
&& wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz -qO- | tar xz && chown root:root aliyun && chmod 755 aliyun && mv aliyun /usr/local/bin/ \
\
&& log "cleaning all cache files" \
&& rm -rf ~/.ash_history ~/.cache/ ~/.config/ ~/.npm* ~/* /var/cache/apk/* /tmp/*
# HEALTHCHECK --timeout=1s --retries=1 CMD true || false
# https://docs.docker.com/engine/reference/builder/#shell
# https://github.com/docker/docker.github.io/blob/master/develop/develop-images/dockerfile_best-practices.md#using-pipes
# https://github.com/hadolint/hadolint/wiki/DL4006
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
WORKDIR /root
ENV \
LANG=C.UTF-8 \
# PS1='\[\e[1;7;94m\] ?=$? $(. /etc/os-release && echo $ID-$VERSION_ID) \u@$(hostname -i)@\H:\w \[\e[0m\]\n\$ ' \
PS1='\[\e]0;\u@\h: \w\a\]\[\e[0m\]\[\e[1;97;41m\]$(r=$?; [ $r -ne 0 ] && echo " \\$?=$r ")\[\e[0m\]\[\e[1;97;43m\]$([ 1 -ne $SHLVL ] && echo " \\$SHLVL=$SHLVL ")\[\e[0m\]\[\e[3;37;100m\] $(source /etc/os-release && echo $ID-$VERSION_ID) \[\e[0m\]\[\e[95;40m\] \u\[\e[0m\]\[\e[1;35;40m\]$([ "$(id -ng)" != "$(id -nu)" ] && echo ":$(id -ng)")\[\e[0m\]\[\e[2;90;40m\]@\[\e[0m\]\[\e[3;32;40m\]$(hostname -i)\[\e[0m\]\[\e[2;90;40m\]@\[\e[0m\]\[\e[4;34;40m\]\H\[\e[0m\]\[\e[2;90;40m\]:\[\e[0m\]\[\e[1;33;40m\]$PWD \[\e[0m\]\n\[\e[0m\]\[\e[1;31m\]\$\[\e[0m\] '
CMD ["/bin/bash"]
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
FROM fresh AS tester
RUN function log { echo -e "\e[7;36m$(date +%F_%T)\e[0m\e[1;96m $*\e[0m" > /dev/stderr ; } \
\
&& log "Test os-release" \
&& cat /etc/os-release \
\
&& log "Test APK repositories" \
&& cat /etc/apk/repositories \
\
&& log "Test timezone" \
&& readlink -vf /etc/localtime \
\
&& log "Test bash" \
&& bash --version \
\
&& log "Test curl" \
&& curl --version \
\
&& log "Test ping" \
&& ping -V \
\
&& log "Test docker-cli" \
&& docker --version \
\
&& log "Test git" \
&& git --version \
\
&& log "Test SSH" \
&& ssh -V \
\
&& log "Test openjdk17" \
&& javac --version \
\
&& log "Test maven" \
&& mvn --version \
\
&& log "Test jq" \
&& jq --version \
\
&& log "Test yq" \
&& yq --version \
\
&& log "Test rclone" \
&& rclone --version \
\
&& log "Test nodejs" \
&& node --version \
\
&& log "Test npm" \
&& npm --version \
\
&& log "Test npm repositories" \
&& npm config list \
\
&& log "Test python3" \
&& python3 --version \
\
&& log "Test pip" \
&& pip --version \
\
&& log "Test pip mirrors" \
&& pip config list \
\
&& log "Test kubectl" \
&& kubectl version --client \
\
&& log "Test helm" \
&& helm version \
\
&& log "Test aliyun-cli" \
&& aliyun > out && head -n1 out \
\
&& log "Passed all test cases!" \
&& touch /tested
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
FROM fresh AS output
# https://www.docker.com/blog/advanced-dockerfiles-faster-builds-and-smaller-images-using-buildkit-and-multistage-builds/
COPY --from=tester /tested /