Skip to content
Permalink
Browse files

ci, feat: add dockerfiles. (#510)

  • Loading branch information...
richardo2016 authored and xicilion committed Jun 18, 2019
1 parent 965c955 commit 3c46c38fb83a3ed1d60cb302cf12c0f932fc09b0
@@ -0,0 +1,30 @@
FROM alpine:latest

LABEL AUTHOR="Richard"
LABEL AUTHOR_EMAIL="richardo2016@gmail.com"

RUN apk update && apk upgrade

RUN apk update
RUN apk add --no-cache clang clang-dev alpine-sdk xz dpkg ncurses && \
apk add --update --no-cache cmake && \
apk add --update --no-cache linux-headers

RUN ls -l /usr/bin/cc /usr/bin/c++ /usr/bin/clang /usr/bin/clang++ /usr/bin/tput

RUN ln -sf /usr/bin/clang /usr/bin/cc
RUN ln -sf /usr/bin/clang++ /usr/bin/c++

RUN update-alternatives --install /usr/bin/cc cc /usr/bin/clang 10
RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 10

RUN update-alternatives --auto cc
RUN update-alternatives --auto c++

RUN update-alternatives --display cc
RUN update-alternatives --display c++

RUN ls -l /usr/bin/cc /usr/bin/c++

RUN cc --version
RUN c++ --version
@@ -0,0 +1,90 @@
#! /bin/bash -

# set envrionment variables fisrtly
# GROUP=fibjs

usage()
{
echo ""
echo "Usage: `basename $0` [Command]"
echo "Command:"
echo " image: "
echo " get build-env-alpine by docker."
echo " fibjs: "
echo " build fibjs."
echo " -h, --help:"
echo " Print this message and exit."
echo ""
exit 0
}

if [ "$FIBJS_DIR" = "" ]; then
FIBJS_DIR=../../
fi
if [ "$GROUP" = "" ]; then
GROUP=fibjs
fi
if [ "$IMG_NAME" = "" ]; then
IMG_NAME=$GROUP/build-env-alpine
fi

image()
{
docker build --rm -t $IMG_NAME .
}

fibjs()
{
if [ "$DEBUG" != "" ]; then
MODE=debug
CI=""
else
MODE=release
CI="ci"
fi

HOST_OS=`uname`
CPU_CORE=2
case ${HOST_OS} in
Darwin)
CPU_CORE=$(sysctl hw.ncpu | awk '{print $2}')
;;
Linux)
CPU_CORE=$(cat /proc/cpuinfo | grep processor | wc -l)
;;
Windows)
CPU_CORE=$(echo $NUMBER_OF_PROCESSORS)
;;
esac

BUILD_JOBS=$(( $CPU_CORE * 4 ))

echo "------ env :start -------"
echo HOST_OS: $HOST_OS
echo CPU_CORE: $CPU_CORE
echo BUILD_JOBS: $BUILD_JOBS
echo "------ env :end -------"

echo "start compiling fibjs..."
# -m 16g \
# --memory-swap 32g \
docker run -it \
-e BUILD_JOBS=$BUILD_JOBS \
-v ${FIBJS_DIR}:/home/ci $IMG_NAME:latest \
/bin/sh -c "cd /home/ci; sh build $MODE $CI"
echo "finish compiling fibjs!"
}

for i in "$@"
do
case $i in
image) image
;;
fibjs) fibjs
;;
--help|-h) usage
;;
*) usage
;;
esac
done
@@ -0,0 +1 @@
tmp/**
@@ -0,0 +1,6 @@
FROM alpine:latest

LABEL AUTHOR="Richard"
LABEL AUTHOR_EMAIL="richardo2016@gmail.com"

COPY fibjs /usr/local/bin
@@ -0,0 +1,124 @@
#! /bin/bash -

# set envrionment variables fisrtly
#
# RELEASE=${TARGET_OS}_${TARGET_ARCH}_${BUILD_TYPE}
# GROUP=fibjs

# @sample:
# GROUP=fibjs \
# RELEASE=Linux_amd64_release \
# ./build release

usage()
{
echo ""
echo "Usage: `basename $0` [Command]"
echo "Command:"
echo " release: "
echo " release fibjs in alpine image."
echo " test: "
echo " release fibjs in alpine image and test."
echo " -h, --help:"
echo " Print this message and exit."
echo ""
exit 0
}

if [ "$FIBJS_DIR" = "" ]; then
FIBJS_DIR=../../
fi
if [ "$GROUP" = "" ]; then
GROUP=fibjs
fi
if [ "$RELEASE" = "" ]; then
RELEASE=Linux_amd64_release
fi

NOW=$(echo $(date +'%Y-%m-%d_%H-%M-%S'))

DIR=`pwd`

IMG_NAME=$(echo "$RELEASE" | tr '[:upper:]' '[:lower:]')
IMG_REPO=$GROUP/alpine-$IMG_NAME

TARGET_NAME=$IMG_REPO:building

BUILD_CTX=$DIR/tmp/$RELEASE/
TEST_DIR=$DIR/tmp/test

build()
{
clean_tmp
mkdir -p ./tmp

mkdir -p $BUILD_CTX
cp $FIBJS_DIR/bin/$RELEASE/fibjs $BUILD_CTX
cp -r $FIBJS_DIR/test $TEST_DIR

echo "would build docker $TARGET_NAME"
docker build \
-f ./Dockerfile \
--rm -t $TARGET_NAME $BUILD_CTX
echo "finish building docker $TARGET_NAME"

RESULT_V=$(docker run --rm $TARGET_NAME fibjs --version)
echo ""
echo "version: $RESULT_V"

# must run before change name
if [ "$FIBJS_BUILD_ALPINE_TEST" = "1" ]; then
do_test
fi

OLD_TARGET_NAME=$TARGET_NAME

if [ "$USE_VERSION" == "1" ]; then
IMG_TAG=$RESULT_V
elif [ "$FIBJS_BUILD_ALPINE_LATEST" = "1" ]; then
IMG_TAG=latest
else
IMG_TAG=$RESULT_V-$NOW
fi

TARGET_NAME=$IMG_REPO:$IMG_TAG
docker tag $OLD_TARGET_NAME $TARGET_NAME
docker rmi $OLD_TARGET_NAME

echo "build success!"
clean_tmp
}

clean_tmp()
{
rm -rf tmp
}

do_test()
{
docker run -it \
-v ${TEST_DIR}:/home/test $TARGET_NAME \
/bin/sh -c "cd /home/test; fibjs test"
}

for i in "$@"
do
case $i in
--help|-h)
usage
;;
release)
USE_VERSION=1
build
;;
test)
FIBJS_BUILD_ALPINE_TEST=1
build
do_test
;;
latest)
FIBJS_BUILD_ALPINE_LATEST=1
build
;;
esac
done

0 comments on commit 3c46c38

Please sign in to comment.
You can’t perform that action at this time.