59 lines
1.8 KiB
Bash
Executable File
59 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Catch build Error
|
|
function error {
|
|
|
|
echo "Docker build Failed."
|
|
exit 1;
|
|
}
|
|
|
|
set -e
|
|
trap error ERR
|
|
|
|
echo "Build Docker Image."
|
|
|
|
stagingPath=$1
|
|
projectPath=$2
|
|
projectName=$3
|
|
version=$4
|
|
|
|
echo "Staging: $stagingPath"
|
|
echo "projectPath: $projectPath"
|
|
echo "projectName: $projectName"
|
|
echo "version: $version"
|
|
|
|
HAS_IMAGE=`docker image ls ${projectName}:v${version} | wc -l`
|
|
if [ $HAS_IMAGE -eq "2" ]; then
|
|
echo "The image existe we remove it first"
|
|
docker image rm -f ${projectName}:v${version}
|
|
fi
|
|
|
|
rm -rf $stagingPath/docker-build
|
|
mkdir -p $stagingPath/docker-build/rootfs/
|
|
mkdir -p $stagingPath/docker-build/rootfs/dev
|
|
mkdir -p $stagingPath/docker-build/rootfs/media
|
|
mkdir -p $stagingPath/docker-build/rootfs/mnt
|
|
mkdir -p $stagingPath/docker-build/rootfs/proc
|
|
mkdir -p $stagingPath/docker-build/rootfs/run
|
|
mkdir -p $stagingPath/docker-build/rootfs/srv
|
|
mkdir -p $stagingPath/docker-build/rootfs/sys
|
|
mkdir -p $stagingPath/docker-build/rootfs/tmp
|
|
|
|
mkdir -p $stagingPath/docker-build/rootfs/usr/local/
|
|
|
|
cp $projectPath/configs/Dockerfile $stagingPath/docker-build
|
|
|
|
cp -a $stagingPath/buildroot/target/bin $stagingPath/docker-build/rootfs/
|
|
cp -a $stagingPath/buildroot/target/etc $stagingPath/docker-build/rootfs/
|
|
cp -a $stagingPath/buildroot/target/lib $stagingPath/docker-build/rootfs/
|
|
cp -a $stagingPath/buildroot/target/sbin $stagingPath/docker-build/rootfs/
|
|
|
|
touch $stagingPath/docker-build/rootfs/etc/resolv.conf
|
|
|
|
cp /lib/x86_64-linux-gnu/libpthread.so.0 $stagingPath/docker-build/rootfs/lib
|
|
cp /usr/lib/x86_64-linux-gnu/libltdl.so.7 $stagingPath/docker-build/rootfs/lib
|
|
cp /lib/x86_64-linux-gnu/libc.so.6 $stagingPath/docker-build/rootfs/lib
|
|
cp /lib64/ld-linux-x86-64.so.2 $stagingPath/docker-build/rootfs/lib64
|
|
|
|
docker build -t ${projectName}:v${version} $stagingPath/docker-build
|