Dockerfile 3.7 KB
Newer Older
1
FROM ubuntu:17.10
2 3 4
LABEL maintainer="Huan LI <zixia@zixia.net>"

ENV DEBIAN_FRONTEND     noninteractive
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
5 6 7
ENV LC_ALL              C.UTF-8
ENV NODE_ENV            $NODE_ENV
ENV NPM_CONFIG_LOGLEVEL warn
8 9 10 11 12 13 14

# Installing the 'apt-utils' package gets rid of the 'debconf: delaying package configuration, since apt-utils is not installed'
# error message when installing any other package with the apt-get package manager.
# https://peteris.rocks/blog/quiet-and-unattended-installation-with-apt-get/
RUN apt-get update && apt-get install -y --no-install-recommends \
    apt-utils \
    bash \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
15
    build-essential \
16 17 18 19
    ca-certificates \
    curl \
    coreutils \
    figlet \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
20
    git \
21 22 23 24 25 26
    jq \
    libav-tools \
    moreutils \
    sudo \
    ttf-freefont \
    vim \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
27
    wget \
28 29 30 31 32 33 34
  && rm -rf /tmp/* /var/lib/apt/lists/* \
  && apt-get purge --auto-remove

RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
    && apt-get update && apt-get install -y --no-install-recommends nodejs \
    && rm -rf /tmp/* /var/lib/apt/lists/* \
    && apt-get purge --auto-remove
35 36 37 38 39

# https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
# https://github.com/ebidel/try-puppeteer/blob/master/backend/Dockerfile
# Install latest chrome dev package.
# Note: this also installs the necessary libs so we don't need the previous RUN command.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
40
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
41
    && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
42 43 44
    && apt-get update && apt-get install -y --no-install-recommends \
      google-chrome-unstable \
    && rm -rf /tmp/* /var/lib/apt/lists/* \
45
    && apt-get purge --auto-remove
46 47

# Add chatie user.
48
RUN groupadd bot && useradd -g bot -d /bot -m -G audio,video,sudo bot \
49 50 51
    && mkdir -p /bot/Downloads \
    && chown -R bot:bot /bot \
    && echo "bot   ALL=NOPASSWD:ALL" >> /etc/sudoers
52

53 54 55
RUN mkdir /wechaty \
    && chown -R bot:bot /wechaty \
    && mkdir /node_modules
56

57
WORKDIR /wechaty
58 59 60 61
VOLUME [ "/bot" ]

# Run user as non privileged.
USER bot
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
62

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
63
COPY package.json .
64 65
RUN  npm install \
  && sudo rm -fr /tmp/* ~/.npm
66

67
COPY . .
68
RUN  npm run dist
69

70 71 72 73 74 75 76 77
# Loading from node_modules Folders: https://nodejs.org/api/modules.html
# If it is not found there, then it moves to the parent directory, and so on, until the root of the file system is reached.
RUN sudo npm link \
    && sudo ln -s /wechaty /node_modules/wechaty \
    && sudo ln -s /wechaty/node_modules/* /node_modules/ \
    && sudo ln -s /wechaty/tsconfig.json / \
    && echo "export * from 'wechaty'" | sudo tee /index.ts \
    && echo 'Linked wechaty to global'
78

79
ENTRYPOINT [ "/wechaty/bin/entrypoint.sh" ]
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
80
CMD [ "" ]
81

82 83 84 85
#
# https://docs.docker.com/docker-cloud/builds/advanced/
# http://label-schema.org/rc1/
#
86
LABEL org.label-schema.license="Apache-2.0" \
87 88 89 90 91
      org.label-schema.build-date="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
      org.label-schema.version="$DOCKER_TAG" \
      org.label-schema.schema-version="$(wechaty-version)" \
      org.label-schema.name="Wechaty" \
      org.label-schema.description="Wechat for Bot" \
92
      org.label-schema.usage="https://github.com/chatie/wechaty/wiki/Docker" \
93
      org.label-schema.url="https://www.chatie.io" \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
94
      org.label-schema.vendor="Chatie" \
95
      org.label-schema.vcs-ref="$SOURCE_COMMIT" \
96
      org.label-schema.vcs-url="https://github.com/chatie/wechaty" \
97 98 99 100
      org.label-schema.docker.cmd="docker run -ti --rm zixia/wechaty <code.js>" \
      org.label-schema.docker.cmd.test="docker run -ti --rm zixia/wechaty test" \
      org.label-schema.docker.cmd.help="docker run -ti --rm zixia/wechaty help" \
      org.label-schema.docker.params="WECHATY_TOKEN=token token from https://www.chatie.io"
101

102
#RUN npm test