Dockerfile 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. FROM debian:buster-slim
  2. MAINTAINER wekan
  3. # Declare Arguments
  4. ARG NODE_VERSION
  5. ARG METEOR_RELEASE
  6. ARG METEOR_EDGE
  7. ARG USE_EDGE
  8. ARG NPM_VERSION
  9. ARG FIBERS_VERSION
  10. ARG ARCHITECTURE
  11. ARG SRC_PATH
  12. # Set the environment variables (defaults where required)
  13. # DOES NOT WORK: paxctl fix for alpine linux: https://github.com/wekan/wekan/issues/1303
  14. # ENV BUILD_DEPS="paxctl"
  15. ENV BUILD_DEPS="apt-utils gnupg gosu wget curl bzip2 build-essential python git ca-certificates gcc-7"
  16. ENV NODE_VERSION ${NODE_VERSION:-v8.11.1}
  17. ENV METEOR_RELEASE ${METEOR_RELEASE:-1.6.0.1}
  18. ENV USE_EDGE ${USE_EDGE:-false}
  19. ENV METEOR_EDGE ${METEOR_EDGE:-1.5-beta.17}
  20. ENV NPM_VERSION ${NPM_VERSION:-latest}
  21. ENV FIBERS_VERSION ${FIBERS_VERSION:-2.0.0}
  22. ENV ARCHITECTURE ${ARCHITECTURE:-linux-x64}
  23. ENV SRC_PATH ${SRC_PATH:-./}
  24. # Copy the app to the image
  25. COPY ${SRC_PATH} /home/wekan/app
  26. RUN \
  27. echo "=== Add non-root user wekan" && \
  28. useradd --user-group --system --home-dir /home/wekan wekan && \
  29. \
  30. echo "=== OS dependencies" && \
  31. apt-get update -y && apt-get install -y --no-install-recommends ${BUILD_DEPS} && \
  32. \
  33. # Download nodejs
  34. #wget https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-${ARCHITECTURE}.tar.gz && \
  35. #wget https://nodejs.org/dist/${NODE_VERSION}/SHASUMS256.txt.asc && \
  36. #---------------------------------------------------------------------------------------------
  37. # Node Fibers 100% CPU usage issue:
  38. # https://github.com/wekan/wekan-mongodb/issues/2#issuecomment-381453161
  39. # https://github.com/meteor/meteor/issues/9796#issuecomment-381676326
  40. # https://github.com/sandstorm-io/sandstorm/blob/0f1fec013fe7208ed0fd97eb88b31b77e3c61f42/shell/server/00-startup.js#L99-L129
  41. # Also see beginning of wekan/server/authentication.js
  42. # import Fiber from "fibers";
  43. # Fiber.poolSize = 1e9;
  44. echo "=== Getting newest Node from Sandstorm fork of Node" && \
  45. echo "=== Source: https://github.com/sandstorm-io/node ===" && \
  46. \
  47. # From https://github.com/sandstorm-io/sandstorm/blob/master/branch.conf
  48. SANDSTORM_BRANCH_NUMBER=0 && \
  49. \
  50. # From https://github.com/sandstorm-io/sandstorm/blob/master/release.sh
  51. SANDSTORM_CHANNEL=dev && \
  52. SANDSTORM_LAST_BUILD=$(curl -fs https://install.sandstorm.io/$SANDSTORM_CHANNEL) && \
  53. \
  54. echo "=== Latest Sandstorm Release: ${SANDSTORM_LAST_BUILD}===" && \
  55. if (( SANDSTORM_LAST_BUILD / 1000 > SANDSTORM_BRANCH_NUMBER )); && \
  56. then && \
  57. echo "SANDSTORM BRANCH ERROR: $CHANNEL has already moved past this branch!" >&2 && \
  58. echo " I refuse to replace it with an older branch." >&2 && \
  59. exit 1 && \
  60. fi && \
  61. BASE_BUILD=$(( BRANCH_NUMBER * 1000 )) && \
  62. BUILD=$(( BASE_BUILD > LAST_BUILD ? BASE_BUILD : LAST_BUILD + 1 )) && \
  63. BUILD_MINOR="$(( $BUILD % 1000 ))" && \
  64. DISPLAY_VERSION="${BRANCH_NUMBER}.${BUILD_MINOR}" && \
  65. TAG_NAME="v${DISPLAY_VERSION}" && \
  66. SIGNING_KEY_ID=160D2D577518B58D94C9800B63F227499DA8CCBD && \
  67. TARBALL=sandstorm-$SANDSTORM_LAST_BUILD.tar.xz && \
  68. NODE_EXE=sandstorm-$SANDSTORM_LAST_BUILD/bin/node && \
  69. echo "=== Downloading Sandstorm GPG keys to verify Sandstorm release" && \
  70. # Do verification in custom GPG workspace
  71. # https://docs.sandstorm.io/en/latest/install/#option-3-pgp-verified-install
  72. export GNUPGHOME=$(mktemp -d) && \
  73. curl https://raw.githubusercontent.com/sandstorm-io/sandstorm/master/keys/release-keyring.gpg | gpg --import && \
  74. wget https://raw.githubusercontent.com/sandstorm-io/sandstorm/master/keys/release-certificate.kentonv.sig && \
  75. gpg --decrypt release-certificate.kentonv.sig && \
  76. echo "=== Downloading Sandstorm release from https://dl.sandstorm.io/${TARBALL} ===" && \
  77. wget https://dl.sandstorm.io/$TARBALL && \
  78. echo "=== Downloading signature for Sandstorm release from https://dl.sandstorm.io/${TARBALL}.sig ===" && \
  79. wget https://dl.sandstorm.io/$TARBALL.sig && \
  80. echo "=== Verifying signature of Sandstorm release" && \
  81. gpg --verify $TARBALL.sig $TARBALL && \
  82. \
  83. if [ $? -eq 0 ] && \
  84. then && \
  85. echo "=== All is well. Good signature in Sandstorm." && \
  86. else && \
  87. echo "=== PROBLEM WITH SANDSTORM SIGNATURE." && \
  88. exit 1 && \
  89. fi && \
  90. echo "=== Extracting Node from Sandstorm release tarball" && \
  91. # --strip 2 removes path of 2 subdirectories
  92. tar -xf $TARBALL $NODE_EXE --strip=2 && \
  93. echo "=== Deleting Sandstorm release tarball and signature" && \
  94. rm $TARBALL $TARBALL.sig release-certificate.kentonv.si* && \
  95. # == OLD ==
  96. # Download node version 8.11.1 that has fix included, node binary copied from Sandstorm
  97. # Description at https://releases.wekan.team/node.txt
  98. ##wget https://releases.wekan.team/node-${NODE_VERSION}-${ARCHITECTURE}.tar.gz && \
  99. ##echo "308d0caaef0a1da3e98d1a1615016aad9659b3caf31d0f09ced20cabedb8acbf node-v8.11.1-linux-x64.tar.gz" >> SHASUMS256.txt.asc && \
  100. ##\
  101. # Verify nodejs authenticity
  102. ##grep ${NODE_VERSION}-${ARCHITECTURE}.tar.gz SHASUMS256.txt.asc | shasum -a 256 -c - && \
  103. #export GNUPGHOME="$(mktemp -d)" && \
  104. #\
  105. # Try other key servers if ha.pool.sks-keyservers.net is unreachable
  106. # Code from https://github.com/chorrell/docker-node/commit/2b673e17547c34f17f24553db02beefbac98d23c
  107. # gpg keys listed at https://github.com/nodejs/node#release-team
  108. # and keys listed here from previous version of this Dockerfile
  109. #for key in \
  110. #9554F04D7259F04124DE6B476D5A82AC7E37093B \
  111. #94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
  112. #FD3A5288F042B6850C66B31F09FE44734EB7990E \
  113. #71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
  114. #DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
  115. #C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
  116. #B9AE9905FFD7803F25714661B63B535A4C206CA9 \
  117. #; do \
  118. #gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" || \
  119. #gpg --keyserver pgp.mit.edu --recv-keys "$key" || \
  120. #gpg --keyserver keyserver.pgp.com --recv-keys "$key" ; \
  121. #done && \
  122. #gpg --verify SHASUMS256.txt.asc && \
  123. # Ignore socket files then delete files then delete directories
  124. #find "$GNUPGHOME" -type f | xargs rm -f && \
  125. #find "$GNUPGHOME" -type d | xargs rm -fR && \
  126. ##rm -f SHASUMS256.txt.asc && \
  127. \
  128. # Install Node
  129. #tar xvzf node-${NODE_VERSION}-${ARCHITECTURE}.tar.gz && \
  130. #rm node-${NODE_VERSION}-${ARCHITECTURE}.tar.gz && \
  131. #mv node-${NODE_VERSION}-${ARCHITECTURE} /opt/nodejs && \
  132. mv node /opt/nodejs && \
  133. ln -s /opt/nodejs/bin/node /usr/bin/node && \
  134. ln -s /opt/nodejs/bin/npm /usr/bin/npm && \
  135. \
  136. #DOES NOT WORK: paxctl fix for alpine linux: https://github.com/wekan/wekan/issues/1303
  137. #paxctl -mC `which node` && \
  138. \
  139. echo "=== Install Node dependencies" && \
  140. npm install -g npm@${NPM_VERSION} && \
  141. npm install -g node-gyp && \
  142. npm install -g fibers@${FIBERS_VERSION} && \
  143. \
  144. echo "=== Change user to wekan and install meteor" && \
  145. cd /home/wekan/ && \
  146. chown wekan:wekan --recursive /home/wekan && \
  147. curl https://install.meteor.com -o /home/wekan/install_meteor.sh && \
  148. sed -i "s|RELEASE=.*|RELEASE=${METEOR_RELEASE}\"\"|g" ./install_meteor.sh && \
  149. echo "Starting meteor ${METEOR_RELEASE} installation... \n" && \
  150. chown wekan:wekan /home/wekan/install_meteor.sh && \
  151. \
  152. # Check if opting for a release candidate instead of major release
  153. if [ "$USE_EDGE" = false ]; then \
  154. gosu wekan:wekan sh /home/wekan/install_meteor.sh; \
  155. else \
  156. gosu wekan:wekan git clone --recursive --depth 1 -b release/METEOR@${METEOR_EDGE} git://github.com/meteor/meteor.git /home/wekan/.meteor; \
  157. fi; \
  158. \
  159. echo "=== Get additional packages" && \
  160. mkdir -p /home/wekan/app/packages && \
  161. chown wekan:wekan --recursive /home/wekan && \
  162. cd /home/wekan/app/packages && \
  163. gosu wekan:wekan git clone --depth 1 -b master git://github.com/wekan/flow-router.git kadira-flow-router && \
  164. gosu wekan:wekan git clone --depth 1 -b master git://github.com/meteor-useraccounts/core.git meteor-useraccounts-core && \
  165. sed -i 's/api\.versionsFrom/\/\/api.versionsFrom/' /home/wekan/app/packages/meteor-useraccounts-core/package.js && \
  166. cd /home/wekan/.meteor && \
  167. gosu wekan:wekan /home/wekan/.meteor/meteor -- help; \
  168. \
  169. echo "=== Build app" && \
  170. cd /home/wekan/app && \
  171. gosu wekan:wekan /home/wekan/.meteor/meteor add standard-minifier-js && \
  172. gosu wekan:wekan /home/wekan/.meteor/meteor npm install && \
  173. gosu wekan:wekan /home/wekan/.meteor/meteor build --directory /home/wekan/app_build && \
  174. cp /home/wekan/app/fix-download-unicode/cfs_access-point.txt /home/wekan/app_build/bundle/programs/server/packages/cfs_access-point.js && \
  175. chown wekan:wekan /home/wekan/app_build/bundle/programs/server/packages/cfs_access-point.js && \
  176. #Removed binary version of bcrypt because of security vulnerability that is not fixed yet.
  177. #https://github.com/wekan/wekan/commit/4b2010213907c61b0e0482ab55abb06f6a668eac
  178. #https://github.com/wekan/wekan/commit/7eeabf14be3c63fae2226e561ef8a0c1390c8d3c
  179. #cd /home/wekan/app_build/bundle/programs/server/npm/node_modules/meteor/npm-bcrypt && \
  180. #gosu wekan:wekan rm -rf node_modules/bcrypt && \
  181. #gosu wekan:wekan npm install bcrypt && \
  182. cd /home/wekan/app_build/bundle/programs/server/ && \
  183. gosu wekan:wekan npm install && \
  184. #gosu wekan:wekan npm install bcrypt && \
  185. mv /home/wekan/app_build/bundle /build && \
  186. \
  187. echo "=== Cleanup" && \
  188. apt-get remove --purge -y ${BUILD_DEPS} && \
  189. apt-get autoremove -y && \
  190. rm -R /var/lib/apt/lists/* && \
  191. rm -R /home/wekan/.meteor && \
  192. rm -R /home/wekan/app && \
  193. rm -R /home/wekan/app_build && \
  194. rm /home/wekan/install_meteor.sh
  195. ENV PORT=80
  196. EXPOSE $PORT
  197. CMD ["node", "/build/main.js"]