forked from skwashd/alpine-docker-from-scratch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·49 lines (40 loc) · 1.33 KB
/
build.sh
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
#!/bin/sh
#
# Copyright (c) 2018-2020 Dave Hall <skwashd@gmail.com>
# MIT Licensed, see LICENSE for more information.
#
set -ex
DOCKER_USERNAME="${DOCKER_USERNAME:-skwashd}"
ALPINE_VER="${ALPINE_VER:-latest-stable}"
PACKAGES="apk-tools ca-certificates ssl_client"
MKROOTFS="/tmp/alpine-make-rootfs"
BUILD_TAR="/tmp/docker/alpine-rootfs-${ALPINE_VER}.tar.gz"
DOCKER_ROOT=$(dirname $BUILD_TAR)
POST_INSTALL="./post-install.sh"
mkdir $DOCKER_ROOT
# Download rootfs builder and verify it.
wget https://raw.githubusercontent.com/alpinelinux/alpine-make-rootfs/v0.6.0/alpine-make-rootfs -O "$MKROOTFS"
chmod +x ${MKROOTFS}
sudo ${MKROOTFS} --mirror-uri http://dl-2.alpinelinux.org/alpine \
--branch "${ALPINE_VER}" \
--packages "$PACKAGES" \
--script-chroot \
"$BUILD_TAR" \
"$POST_INSTALL"
cat <<DOCKERFILE > "${DOCKER_ROOT}/Dockerfile"
FROM scratch
USER worker
ADD $(basename $BUILD_TAR) /
CMD ["/bin/sh"]
DOCKERFILE
cd $DOCKER_ROOT
docker build --no-cache -t "${DOCKER_USERNAME}/alpine:${ALPINE_VER}" .
cd -
docker build --build-arg BASE_IMAGE="${DOCKER_USERNAME}/alpine:${ALPINE_VER}" - <<'DOCKERFILE'
ARG BASE_IMAGE
FROM $BASE_IMAGE
ARG MS_TOKEN
USER root
RUN apk update && apk add curl && rm -rf /var/cache/apk/*
RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
DOCKERFILE