Commit 983cbc8e authored by Stéphane Veyret's avatar Stéphane Veyret
Browse files

Adapt docker to gitlab-ci

parent f714ad83
......@@ -19,11 +19,11 @@ vagrant/*.log
vagrant/duniter
# Releases
/work
*.deb
*.tar.gz
*.log
*.exe
/release/arch/debian/duniter-source
# vscode
.vscode
......
stages:
- github-sync
- test
before_script:
- export NVM_DIR="$HOME/.nvm"
- . "$NVM_DIR/nvm.sh"
- github-sync
- build
- test
push_to_github:
stage: github-sync
......@@ -12,8 +9,6 @@ push_to_github:
GIT_STRATEGY: none
tags:
- redshift
before_script:
- ''
script:
- rm -rf ./*
- rm -rf .git
......@@ -32,8 +27,6 @@ enforce_readme:
GIT_STRATEGY: none
tags:
- redshift
before_script:
- ''
script:
- rm -rf ./*
- rm -rf .git
......@@ -47,10 +40,42 @@ enforce_readme:
- git commit -am "Enforce github readme"
- git push origin master
build_linux:test:
stage: build
image: duniter/release-builder:v1.0.0
tags:
- nodejs
- nwjs
script:
- bash "release/arch/linux/build-lin.sh" "$(date +%Y%m%d).$(date +%H%M).$(date +%S)"
artifacts:
paths:
- work/bin/
expire_in: 8h
except:
- tags
build_linux:deploy:
stage: build
image: duniter/release-builder:v1.0.0
tags:
- nodejs
- nwjs
script:
- bash "release/arch/linux/build-lin.sh" "${CI_COMMIT_TAG#v}"
artifacts:
paths:
- work/bin/
only:
- tags
test:
stage: test
tags:
- redshift
before_script:
- export NVM_DIR="$HOME/.nvm"
- . "$NVM_DIR/nvm.sh"
script:
- yarn
- yarn test
#!/bin/bash
# NVM
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# Prepare
NODE_VERSION=8.9.1
NVER="v$NODE_VERSION"
DUNITER_TAG=$1
ADDON_VERSION=57
NW_VERSION=0.24.4
NW_RELEASE="v${NW_VERSION}"
NW="nwjs-${NW_RELEASE}-linux-x64"
NW_GZ="${NW}.tar.gz"
DUNITER_SRC=/dunidata/duniter-source
nvm install ${NVER}
nvm use ${NVER}
npm install -g node-pre-gyp
npm install -g nw-gyp
# Folders
ROOT=`pwd`
DOWNLOADS="$ROOT/downloads"
RELEASES="$ROOT/releases"
mkdir -p "$DOWNLOADS" || exit 1
# -----------
# Clean up
# -----------
rm -rf /dunidata/*.deb
rm -rf /dunidata/*.tar.gz
# -----------
# Sources and downloads
# -----------
DUNITER_DEB_VER=" $DUNITER_TAG"
DUNITER_TAG="v$DUNITER_TAG"
cd "${DUNITER_SRC}"
git checkout "${DUNITER_TAG}" || exit 1
cd "$DOWNLOADS"
curl -O https://dl.nwjs.io/${NW_RELEASE}/${NW_GZ} || exit 1
tar xzf ${NW_GZ} || exit 1
# Download Node.js and package it with the sources
curl -O http://nodejs.org/dist/${NVER}/node-${NVER}-linux-x64.tar.gz || exit 1
tar xzf node-${NVER}-linux-x64.tar.gz || exit 1
# -----------
# Releases
# -----------
mkdir -p "$RELEASES" || exit 1
cp -r "${DUNITER_SRC}" "$RELEASES/duniter" || exit 1
# Releases builds
cd ${RELEASES}/duniter
# Remove git files
rm -Rf .git
[[ $? -eq 0 ]] && echo ">> VM: building modules..."
[[ $? -eq 0 ]] && npm install
# Duniter UI
[[ $? -eq 0 ]] && npm install duniter-ui@1.6.x
[[ $? -eq 0 ]] && npm prune --production
[[ $? -eq 0 ]] || exit 1
cp -r "$RELEASES/duniter" "$RELEASES/desktop_" || exit 1
cp -r "$RELEASES/duniter" "$RELEASES/server_" || exit 1
# -------------------------------------------------
# Build Desktop version (Nw.js is embedded)
# -------------------------------------------------
nw_copy() {
[[ -z ${1} ]] && exit 1
cp lib/binding/Release/node-webkit-v${NW_VERSION}-linux-x64/${1}.node \
lib/binding/Release/node-v${ADDON_VERSION}-linux-x64/${1}.node || exit 1
}
nw_copy_node() {
[[ -z ${1} ]] && exit 1
cp lib/binding/node-webkit-v${NW_VERSION}-linux-x64/node_${1}.node \
lib/binding/node-v${ADDON_VERSION}-linux-x64/node_${1}.node || exit 1
}
nw_compile() {
[[ -z ${1} ]] && exit 1
cd ${1} || exit 1
node-pre-gyp --runtime=node-webkit --target=${NW_VERSION} configure || exit 1
node-pre-gyp --runtime=node-webkit --target=${NW_VERSION} build || exit 1
[[ -z ${2} ]] || ${2} ${1}
cd ..
}
echo "$NW_RELEASE"
# FIX: bug of nw.js, we need to patch first.
# TODO: remove this patch once a correct version of Nw.js is out (NodeJS 8 or 9 if the above modules are compliant)
cd "$RELEASES/desktop_/node_modules/wotb"
node-pre-gyp --runtime=node-webkit --target=$NW_VERSION configure \
|| echo "This failure is expected"
cp /dunidata/0.24.4_common.gypi ~/.nw-gyp/0.24.4/common.gypi || exit 1
cd "$RELEASES/desktop_/node_modules/"
nw_compile wotb nw_copy
nw_compile naclb nw_copy
nw_compile scryptb nw_copy
nw_compile sqlite3 nw_copy_node
# Unused binaries
cd "$RELEASES/desktop_/"
rm -rf node_modules/sqlite3/build
#rm -rf node_modules/naclb/build
#rm -rf node_modules/wotb/build
#rm -rf node_modules/scryptb/build
## Install Nw.js
mkdir -p "$RELEASES/desktop_release" || exit 1
# -------------------------------------------------
# Build Desktop version .tar.gz
# -------------------------------------------------
cp -r $DOWNLOADS/${NW}/* "$RELEASES/desktop_release/" || exit 1
# Embed Node.js with Nw.js to make Duniter modules installable
cp -r ${DOWNLOADS}/node-${NVER}-linux-x64/lib "$RELEASES/desktop_release/" || exit 1
cp -r ${DOWNLOADS}/node-${NVER}-linux-x64/include "$RELEASES/desktop_release/" || exit 1
cp -r ${DOWNLOADS}/node-${NVER}-linux-x64/bin "$RELEASES/desktop_release/" || exit 1
# Add some specific files for GUI
cp ${RELEASES}/desktop_/gui/* "$RELEASES/desktop_release/" || exit 1
# Add Duniter sources
cp -R $RELEASES/desktop_/* "$RELEASES/desktop_release/" || exit 1
## Insert Nw specific fields while they do not exist (1.3.3)
sed -i "s/\"main\": \"index.js\",/\"main\": \"index.html\",/" "$RELEASES/desktop_release/package.json" || exit 1
# Add links for Node.js + NPM
cd "$RELEASES/desktop_release/bin"
ln -s ../lib/node_modules/npm/bin/npm-cli.js ./npm -f || exit 1
cd ..
ln -s ./bin/node node -f || exit 1
ln -s ./bin/npm npm -f || exit 1
#sed -i "s/\"node-main\": \"\.\.\/sources\/bin\/duniter\",/\"node-main\": \".\/bin\/duniter\",/" "$RELEASES/desktop_release/package.json"
# Create a copy for TGZ binary
cp -R "$RELEASES/desktop_release" "$RELEASES/desktop_release_tgz" || exit 1
#cd "$RELEASES/desktop_release_tgz/"
#rm -rf node_modules/sqlite3/lib/binding/node-webkit-$NW_RELEASE-linux-x64
#rm -rf node_modules/wotb/lib/binding/Release/node-webkit-$NW_RELEASE-linux-x64
#rm -rf node_modules/naclb/lib/binding/Release/node-webkit-$NW_RELEASE-linux-x64
#rm -rf node_modules/scryptb/lib/binding/Release/node-webkit-$NW_RELEASE-linux-x64
cd "$RELEASES/desktop_release_tgz"
tar czf /duniter/duniter-desktop-${DUNITER_TAG}-linux-x64.tar.gz * --exclude "coverage" --exclude "test" || exit 1
# -------------------------------------------------
# Build Desktop version .deb
# -------------------------------------------------
# Create .deb tree + package it
#cp -r "$RELEASES/desktop_release/release/arch/debian/package" "$RELEASES/duniter-x64"
cp -r "/dunidata/package" "$RELEASES/duniter-x64" || exit 1
mkdir -p "$RELEASES/duniter-x64/opt/duniter/" || exit 1
chmod 755 ${RELEASES}/duniter-x64/DEBIAN/post*
chmod 755 ${RELEASES}/duniter-x64/DEBIAN/pre*
sed -i "s/Version:.*/Version:$DUNITER_DEB_VER/g" ${RELEASES}/duniter-x64/DEBIAN/control || exit 1
cd ${RELEASES}/desktop_release/
#rm -rf node_modules/sqlite3/lib/binding/node-webkit-$NW_RELEASE-linux-x64
#rm -rf node_modules/wotb/lib/binding/Release/node-webkit-$NW_RELEASE-linux-x64
#rm -rf node_modules/naclb/lib/binding/Release/node-webkit-$NW_RELEASE-linux-x64
#rm -rf node_modules/scryptb/lib/binding/Release/node-webkit-$NW_RELEASE-linux-x64
#rm -rf node_modules/sqlite3/lib/binding/node-v$ADDON_VERSION-linux-x64
#rm -rf node_modules/wotb/lib/binding/Release/node-v$ADDON_VERSION-linux-x64
#rm -rf node_modules/naclb/lib/binding/Release/node-v$ADDON_VERSION-linux-x64
#rm -rf node_modules/scryptb/lib/binding/Release/node-v$ADDON_VERSION-linux-x64
zip -qr ${RELEASES}/duniter-x64/opt/duniter/duniter-desktop.nw * || exit 1
sed -i "s/Package: .*/Package: duniter-desktop/g" ${RELEASES}/duniter-x64/DEBIAN/control || exit 1
cd ${RELEASES}/
fakeroot dpkg-deb --build duniter-x64 || exit 1
mv duniter-x64.deb /duniter/duniter-desktop-${DUNITER_TAG}-linux-x64.deb || exit 1
# -------------------------------------------------
# Build Server version (Node.js is embedded, not Nw.js)
# -------------------------------------------------
cd ${RELEASES}
rm -rf duniter-server-x64
cp -r duniter-x64 duniter-server-x64 || exit 1
# Remove Nw.js
rm -rf duniter-server-x64/opt/duniter/duniter-desktop.nw*
cd ${RELEASES}/server_
cp -r ${DOWNLOADS}/node-${NVER}-linux-x64 node || exit 1
zip -qr ${RELEASES}/duniter-server-x64/opt/duniter/duniter-desktop.nw * || exit 1
cd ${RELEASES}
sed -i "s/Package: .*/Package: duniter/g" ${RELEASES}/duniter-server-x64/DEBIAN/control || exit 1
rm -rf ${RELEASES}/duniter-server-x64/usr
fakeroot dpkg-deb --build duniter-server-x64 || exit 1
mv duniter-server-x64.deb /duniter/duniter-server-${DUNITER_TAG}-linux-x64.deb || exit 1
#!/bin/bash
if [[ -z "${1}" ]]; then
echo "Fatal: no version given to build script"
exit 1
fi
if [[ -s "$NVM_DIR/nvm.sh" ]]; then
source "$NVM_DIR/nvm.sh"
else
echo "Fatal: could not load nvm"
exit 1
fi
# -----------
# Prepare
# -----------
NODE_VERSION=8.9.1
NVER="v${NODE_VERSION}"
DUNITER_TAG="v${1}"
DUNITER_DEB_VER=" ${1}"
ADDON_VERSION=57
NW_VERSION=0.24.4
NW_RELEASE="v${NW_VERSION}"
NW="nwjs-${NW_RELEASE}-linux-x64"
NW_GZ="${NW}.tar.gz"
DUNITER_UI_VER="1.6.x"
nvm install ${NVER} || exit 1
nvm use ${NVER} || exit 1
npm install -g node-pre-gyp || exit 1
npm install -g nw-gyp || exit 1
# -----------
# Folders
# -----------
ROOT="${PWD}"
WORK_NAME=work
WORK="${ROOT}/${WORK_NAME}"
DOWNLOADS="${WORK}/downloads"
RELEASES="${WORK}/releases"
BIN="${WORK}/bin"
mkdir -p "${DOWNLOADS}" "${RELEASES}" "${BIN}" || exit 1
rm -rf "${BIN}/"*.{deb,tar.gz} # Clean up
# -----------
# Downloads
# -----------
cd "${DOWNLOADS}"
curl -O https://dl.nwjs.io/${NW_RELEASE}/${NW_GZ} || exit 1
tar xzf ${NW_GZ} || exit 1
rm ${NW_GZ}
curl -O http://nodejs.org/dist/${NVER}/node-${NVER}-linux-x64.tar.gz || exit 1
tar xzf node-${NVER}-linux-x64.tar.gz || exit 1
rm node-${NVER}-linux-x64.tar.gz
# -----------
# Releases
# -----------
# Prepare sources
mkdir -p "${RELEASES}/duniter" || exit 1
cp -r $(find "${ROOT}" -mindepth 1 -maxdepth 1 ! -name "${WORK_NAME}") "${RELEASES}/duniter" || exit 1
cd "${RELEASES}/duniter"
rm -Rf .gitignore .git || exit 1 # Remove git files
# Build
echo ">> VM: building modules..."
npm install || exit 1
# Duniter UI
npm install "duniter-ui@${DUNITER_UI_VER}" || exit 1
npm prune --production || exit 1
rm -rf release coverage test # Non production folders
cp -r "${RELEASES}/duniter" "${RELEASES}/desktop_" || exit 1
cp -r "${RELEASES}/duniter" "${RELEASES}/server_" || exit 1
# -------------------------------------
# Build Desktop version against nw.js
# -------------------------------------
nw_copy() {
[[ -z ${1} ]] && exit 1
cp lib/binding/Release/node-webkit-v${NW_VERSION}-linux-x64/${1}.node \
lib/binding/Release/node-v${ADDON_VERSION}-linux-x64/${1}.node || exit 1
}
nw_copy_node() {
[[ -z ${1} ]] && exit 1
cp lib/binding/node-webkit-v${NW_VERSION}-linux-x64/node_${1}.node \
lib/binding/node-v${ADDON_VERSION}-linux-x64/node_${1}.node || exit 1
}
nw_compile() {
[[ -z ${1} ]] && exit 1
cd ${1} || exit 1
node-pre-gyp --runtime=node-webkit --target=${NW_VERSION} configure || exit 1
node-pre-gyp --runtime=node-webkit --target=${NW_VERSION} build || exit 1
[[ -z ${2} ]] || ${2} ${1}
cd ..
}
echo "${NW_RELEASE}"
# FIX: bug of nw.js, we need to patch first.
# TODO: remove this patch once a correct version of Nw.js is out (NodeJS 8 or 9 if the above modules are compliant)
cd "${RELEASES}/desktop_/node_modules/wotb"
node-pre-gyp --runtime=node-webkit --target=$NW_VERSION configure \
|| echo "This failure is expected"
cp ${ROOT}/release/arch/linux/0.24.4_common.gypi ~/.nw-gyp/0.24.4/common.gypi || exit 1
cd "${RELEASES}/desktop_/node_modules/"
nw_compile wotb nw_copy
nw_compile naclb nw_copy
nw_compile scryptb nw_copy
nw_compile sqlite3 nw_copy_node
# Unused binaries
cd "${RELEASES}/desktop_/"
rm -rf node_modules/sqlite3/build
# --------------------------------
# Embed nw.js in desktop version
# --------------------------------
# Install Nw.js
mkdir -p "${RELEASES}/desktop_release" || exit 1
cp -r "${DOWNLOADS}/${NW}/"* "${RELEASES}/desktop_release/" || exit 1
# Embed Node.js with Nw.js to make Duniter modules installable
cp -r "${DOWNLOADS}/node-${NVER}-linux-x64/lib" "${RELEASES}/desktop_release/" || exit 1
cp -r "${DOWNLOADS}/node-${NVER}-linux-x64/include" "${RELEASES}/desktop_release/" || exit 1
cp -r "${DOWNLOADS}/node-${NVER}-linux-x64/bin" "${RELEASES}/desktop_release/" || exit 1
# Add some specific files for GUI
cp "${RELEASES}/desktop_/gui/"* "${RELEASES}/desktop_release/" || exit 1
# Add Duniter sources
cp -R "${RELEASES}/desktop_/"* "${RELEASES}/desktop_release/" || exit 1
# Insert Nw specific fields while they do not exist (1.3.3)
sed -i "s/\"main\": \"index.js\",/\"main\": \"index.html\",/" "${RELEASES}/desktop_release/package.json" || exit 1
# Add links for Node.js + NPM
cd "${RELEASES}/desktop_release/bin"
ln -s "../lib/node_modules/npm/bin/npm-cli.js" "./npm" -f || exit 1
cd ..
ln -s "./bin/node" "node" -f || exit 1
ln -s "./bin/npm" "npm" -f || exit 1
#sed -i "s/\"node-main\": \"\.\.\/sources\/bin\/duniter\",/\"node-main\": \".\/bin\/duniter\",/" "$RELEASES/desktop_release/package.json"
rm -rf "${RELEASES}/desktop_"
mv "${RELEASES}/desktop_release" "${RELEASES}/desktop_"
# ---------------------------------
# Embed node.js in server version
# ---------------------------------
cp -r "${DOWNLOADS}/node-${NVER}-linux-x64" "${RELEASES}/server_/node" || exit 1
# ---------------
# Build .tar.gz
# ---------------
cd "${RELEASES}/desktop_"
tar czf "${BIN}/duniter-desktop-${DUNITER_TAG}-linux-x64.tar.gz" * || exit 1
# -----------------------
# Build Debian packages
# -----------------------
# Parameters
# 1: either "server" or "desktop".
# 2: package name for Debian.
build_deb_pack() {
rm -rf "${RELEASES}/duniter-x64"
mkdir "${RELEASES}/duniter-x64" || exit 1
cp -r "${ROOT}/release/arch/linux/debian/package/"* "${RELEASES}/duniter-x64" || exit 1
if [[ "${1}" == "desktop" ]]; then
cp -r "${ROOT}/release/contrib/desktop/"* "${RELEASES}/duniter-x64" || exit 1
fi
mkdir -p "${RELEASES}/duniter-x64/opt/duniter/" || exit 1
chmod 755 "${RELEASES}/duniter-x64/DEBIAN/"post* || exit 1
chmod 755 "${RELEASES}/duniter-x64/DEBIAN/"pre* || exit 1
sed -i "s/Version:.*/Version:${DUNITER_DEB_VER}/g" "${RELEASES}/duniter-x64/DEBIAN/control" || exit 1
cd "${RELEASES}/${1}_/"
zip -qr "${RELEASES}/duniter-x64/opt/duniter/duniter.zip" * || exit 1
sed -i "s/Package: .*/Package: ${2}/g" "${RELEASES}/duniter-x64/DEBIAN/control" || exit 1
cd "${RELEASES}"
fakeroot dpkg-deb --build duniter-x64 || exit 1
mv duniter-x64.deb "${BIN}/duniter-${1}-${DUNITER_TAG}-linux-x64.deb" || exit 1
}
build_deb_pack desktop duniter-desktop
build_deb_pack server duniter
......@@ -5,9 +5,9 @@ DUN_SOURCES=$DUN_ROOT/
mkdir -p $DUN_SOURCES
# Duniter sources extraction
if [[ -f $DUN_ROOT/duniter-desktop.nw ]]; then
unzip -q -d $DUN_SOURCES/ $DUN_ROOT/duniter-desktop.nw
rm -rf $DUN_ROOT/duniter-desktop.nw
if [[ -f $DUN_ROOT/duniter.zip ]]; then
unzip -q -d $DUN_SOURCES/ $DUN_ROOT/duniter.zip
rm -rf $DUN_ROOT/duniter.zip
fi
# Duniter-Desktop
......
#!/bin/bash
BUILDER_TAG="v0.0.6"
BUILDER_TAG="v1.0.0"
TAG="$3"
ORIGIN="$4"
......@@ -43,31 +43,36 @@ make)
echo ">> Build success."
fi
;;
deb)
cd release/arch/debian
lin)
cd release/arch/linux
if [[ ! -f "duniter-desktop-$TAG-linux-x64.deb" ]]; then
#### PREPARE SOURCE CODE ####
rm -rf duniter-source
# Clone from remote
echo ">> VM: Cloning sources from ${ORIGIN}..."
git clone "${ORIGIN}" duniter-source
if [ ${IS_LOCAL_TAG} -eq 1 ]; then
cd duniter-source
./release/new_version.sh "$TAG"
cd ..
fi
cd duniter-source
[[ ${IS_LOCAL_TAG} -eq 1 ]] && ./release/new_version.sh "${TAG}"
git checkout "v${TAG}"
cd ..
docker pull duniter/release-builder:${BUILDER_TAG}
docker run --rm -it -v ${PWD}:/dunidata duniter/release-builder:${BUILDER_TAG} ${TAG}
cat <<EOF |
cd /builds/duniter-source
bash "release/arch/linux/build-lin.sh" "${TAG}" || exit 1
exit 0
EOF
docker run --rm -i -v ${PWD}/duniter-source:/builds/duniter-source duniter/release-builder:${BUILDER_TAG}
if [ ! $? -eq 0 ]; then
echo ">> Something went wrong. Stopping build."
else
mv duniter-source/work/bin/* .
echo ">> Build success. Shutting the VM down."
fi
rm -rf duniter-source
echo ">> VM closed."
else
echo "Debian binaries already built. Ready for upload."
echo "Linux binaries already built. Ready for upload."
fi
;;
win)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment