From e7b34d4d232483d10920e715d8f459eae9f740af Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Fri, 26 Mar 2021 10:15:40 +0700 Subject: [PATCH] Add makefile and scripts and updated build script --- Makefile | 9 +++++++++ README.md | 4 ++++ src/build.sh | 22 +++++++++++++++------- src/post-install.sh | 2 +- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index e69de29..3640e17 100644 --- a/Makefile +++ b/Makefile @@ -0,0 +1,9 @@ +DOCKER_IMAGE_NAME = calpine-os-linux +DOCKER_IMAGE_VERSION = 3.13.3 +DOCKER_IMAGE_SIZE = $(shell docker images --format "{{.Repository}} {{.Size}}" | grep $(DOCKER_IMAGE_NAME) | cut -d\ -f2) + +build: + $(shell ./src/build.sh) + @echo "Size of the image: ${DOCKER_IMAGE_SIZE}" + +.PHONY: build \ No newline at end of file diff --git a/README.md b/README.md index 376c821..ef7052a 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,9 @@ - Minimal container image - Easy and fast runtime for serverless +# Build +```shell +make build +``` # Contributors - Sambo Chea \ No newline at end of file diff --git a/src/build.sh b/src/build.sh index 585eb69..28cd5d2 100644 --- a/src/build.sh +++ b/src/build.sh @@ -4,7 +4,11 @@ # MIT # +# Catch errors set -ex + +# Default args +DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME:-calpine-os-linux} DOCKER_USERNAME="${DOCKER_USERNAME:-cubetiq}" ALPINE_VERSION="${ALPINE_VERSION:-3.13.3}" PACKAGES="apk-tools ca-certificates ssl_client" @@ -19,6 +23,9 @@ mkdir $DOCKER_ROOT MS_ROOT="${DOCKER_ROOT}/../microscanner" mkdir $MS_ROOT +# Load pre-install +$PRE_INSTALL + # Build from alpine rootfs # Download rootfs builder and verify it. wget https://raw.githubusercontent.com/alpinelinux/alpine-make-rootfs/v0.5.1/alpine-make-rootfs -O "$MKROOTFS" @@ -35,21 +42,22 @@ sudo ${MKROOTFS} --mirror-uri http://dl-2.alpinelinux.org/alpine \ # Create Dockerfile cat < "${DOCKER_ROOT}/Dockerfile" FROM scratch -USER worker +USER cubetiq ADD $(basename $BUILD_TAR) / CMD ["/bin/sh"] DOCKERFILE cd $DOCKER_ROOT -docker build --no-cache -t "${DOCKER_USERNAME}/alpine:${ALPINE_VERSION}" . +docker build --no-cache -t "${DOCKER_USERNAME}/${DOCKER_IMAGE_NAME}:${ALPINE_VERSION}" . cd - -docker build --build-arg BASE_IMAGE="${DOCKER_USERNAME}/alpine:${ALPINE_VERSION}" --build-arg MS_TOKEN="${MS_TOKEN}" - <<'DOCKERFILE' +# Scanner for docker build docker for security for os container +docker build --build-arg BASE_IMAGE="${DOCKER_USERNAME}/${DOCKER_IMAGE_NAME}:${ALPINE_VERSION}" --build-arg MS_TOKEN="${MS_TOKEN}" - <<'DOCKERFILE' ARG BASE_IMAGE FROM $BASE_IMAGE ARG MS_TOKEN -RUN wget https://get.aquasec.com/microscanner -O /home/worker/microscanner \ - && echo "8e01415d364a4173c9917832c2e64485d93ac712a18611ed5099b75b6f44e3a5 /home/worker/microscanner" | sha256sum -c - \ - && chmod +x /home/worker/microscanner \ - && /home/worker/microscanner $MS_TOKEN +RUN wget https://get.aquasec.com/microscanner -O /home/cubetiq/microscanner \ + && echo "8e01415d364a4173c9917832c2e64485d93ac712a18611ed5099b75b6f44e3a5 /home/cubetiq/microscanner" | sha256sum -c - \ + && chmod +x /home/cubetiq/microscanner \ + && /home/cubetiq/microscanner $MS_TOKEN DOCKERFILE \ No newline at end of file diff --git a/src/post-install.sh b/src/post-install.sh index 3d2a0ad..e687533 100644 --- a/src/post-install.sh +++ b/src/post-install.sh @@ -17,4 +17,4 @@ update-ca-certificates /sbin/apk upgrade # Add a standard user. -adduser -D -u1000 worker \ No newline at end of file +adduser -D -u1000 cubetiq \ No newline at end of file