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

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

# 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 (李卓桓) 已提交
16
    build-essential \
17 18 19 20
    ca-certificates \
    curl \
    coreutils \
    figlet \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
21
    git \
22 23 24 25 26 27
    jq \
    libav-tools \
    moreutils \
    sudo \
    ttf-freefont \
    vim \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
28
    wget \
29 30 31 32 33 34 35
  && 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
36 37 38 39 40

# 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 (李卓桓) 已提交
41
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
42
    && 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 (李卓桓) 已提交
43 44
    && apt-get update && apt-get install -y --no-install-recommends \
      google-chrome-unstable \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
45 46 47
    && rm -rf /usr/bin/google-chrome* /opt/google/chrome-unstable \
    && apt-get purge --auto-remove \
    && rm -rf /tmp/* /var/lib/apt/lists/*
48 49

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

55 56 57
RUN mkdir /wechaty \
    && chown -R bot:bot /wechaty \
    && mkdir /node_modules
58

59
WORKDIR /wechaty
60 61 62

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

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

68
COPY . .
69
RUN npm run dist
70

71 72 73 74 75
# 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/ \
76
    && sudo ln -s /wechaty/node_modules/.bin/* /usr/local/bin/ \
77 78
    && sudo ln -s /wechaty/tsconfig.json / \
    && echo "export * from 'wechaty'" | sudo tee /index.ts \
79
    && echo 'Linked Wechaty to Global'
80

81 82
ENTRYPOINT  [ "/wechaty/bin/entrypoint.sh" ]
CMD         [ "" ]
83

84 85 86 87
#
# https://docs.docker.com/docker-cloud/builds/advanced/
# http://label-schema.org/rc1/
#
88
LABEL org.label-schema.license="Apache-2.0" \
89 90 91 92 93
      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" \
94
      org.label-schema.usage="https://github.com/chatie/wechaty/wiki/Docker" \
95
      org.label-schema.url="https://www.chatie.io" \
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
96
      org.label-schema.vendor="Chatie" \
97
      org.label-schema.vcs-ref="$SOURCE_COMMIT" \
98
      org.label-schema.vcs-url="https://github.com/chatie/wechaty" \
99 100 101 102
      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"
103

104
#RUN npm test